Merge branch 'master' of ssh://184.154.0.242:7999/min/Mineplex

This commit is contained in:
Cheese 2015-11-26 14:47:24 +11:00
commit 83a7b398bc
6 changed files with 172 additions and 101 deletions

View File

@ -2,11 +2,8 @@ package mineplex.core.hologram;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map.Entry;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
@ -34,7 +31,7 @@ public class Hologram
/**
* 1.7 packets uses both EntityIDs while 1.8 uses only the first.
*/
private ArrayList<Entry<Integer, Integer>> _entityIds = new ArrayList<Entry<Integer, Integer>>();
private ArrayList<Integer> _entityIds = new ArrayList<Integer>();
private Entity _followEntity;
private HologramManager _hologramManager;
private String[] _hologramText = new String[0];
@ -53,6 +50,7 @@ public class Hologram
private int _viewDistance = 70;
protected Vector relativeToEntity;
private boolean _hideBoundingBox;
private HologramInteraction _interaction;
public Hologram(HologramManager hologramManager, Location location, String... text)
{
@ -61,6 +59,18 @@ public class Hologram
setText(text);
}
public Hologram setInteraction(HologramInteraction interact)
{
_interaction = interact;
return this;
}
public HologramInteraction getInteraction()
{
return _interaction;
}
/**
* Adds the player to the Hologram to be effected by Whitelist or Blacklist
*/
@ -151,6 +161,7 @@ public class Hologram
nearbyPlayers.add(player);
}
}
return nearbyPlayers;
}
@ -229,9 +240,7 @@ public class Hologram
for (int i = 0; i < _entityIds.size(); i++)
{
Entry<Integer, Integer> entry = _entityIds.get(i);
entityIds1_8[i] = entry.getKey();
entityIds1_8[i] = _entityIds.get(i);
}
_destroy1_8 = new PacketPlayOutEntityDestroy(entityIds1_8);
@ -247,7 +256,7 @@ public class Hologram
for (int i = _entityIds.size(); i < _hologramText.length; i++)
{
_entityIds.add(new HashMap.SimpleEntry(UtilEnt.getNewEntityId(), UtilEnt.getNewEntityId()));
_entityIds.add(UtilEnt.getNewEntityId());
}
}
else
@ -261,9 +270,7 @@ public class Hologram
}
for (int textRow = 0; textRow < _hologramText.length; textRow++)
{
Entry<Integer, Integer> entityIds = this._entityIds.get(textRow);
Packet[] packets1_8 = makeSpawnPackets1_8(textRow, entityIds.getKey(), _hologramText[textRow]);
Packet[] packets1_8 = makeSpawnPackets1_8(textRow, _entityIds.get(textRow), _hologramText[textRow]);
for (int i = 0; i < packets1_8.length; i++)
{
@ -326,8 +333,7 @@ public class Hologram
public Hologram setFollowEntity(Entity entityToFollow)
{
_followEntity = entityToFollow;
relativeToEntity = entityToFollow == null ? null : this._location.clone().subtract(entityToFollow.getLocation())
.toVector();
relativeToEntity = entityToFollow == null ? null : _location.clone().subtract(entityToFollow.getLocation()).toVector();
return this;
}
@ -340,7 +346,7 @@ public class Hologram
*/
public Hologram setHologramTarget(HologramTarget newTarget)
{
this._target = newTarget;
_target = newTarget;
return this;
}
@ -405,11 +411,11 @@ public class Hologram
if (x >= -128 && x <= 127 && y >= -128 && y <= 127 && z >= -128 && z <= 127)
{
_lastMovement.subtract(new Vector(x / 32D, y / 32D, z / 32D));
for (Entry<Integer, Integer> entityId : this._entityIds)
for (Integer entityId : _entityIds)
{
PacketPlayOutEntity.PacketPlayOutRelEntityMove relMove = new PacketPlayOutEntity.PacketPlayOutRelEntityMove();
relMove.a = entityId.getKey();
relMove.a = entityId;
relMove.b = (byte) x;
relMove.c = (byte) y;
relMove.d = (byte) z;
@ -425,13 +431,12 @@ public class Hologram
_lastMovement = new Vector(newLocation.getX() - (x / 32D), 0, newLocation.getZ() - (z / 32D));
for (Entry<Integer, Integer> entityId : this._entityIds)
for (Integer entityId : _entityIds)
{
PacketPlayOutEntityTeleport teleportPacket = new PacketPlayOutEntityTeleport();
teleportPacket.a = entityId.getKey();
teleportPacket.a = entityId;
teleportPacket.b = x;
teleportPacket.c = (int) Math
.floor((oldLocation.getY() + (-2.1) + ((double) i * 0.285)) * 32);
teleportPacket.c = (int) Math.floor((oldLocation.getY() + (-2.1) + ((double) i * 0.285)) * 32);
teleportPacket.d = z;
packets1_8[i] = teleportPacket;
@ -458,6 +463,11 @@ public class Hologram
return this;
}
public boolean isEntityId(int entityId)
{
return _entityIds.contains(entityId);
}
/**
* Set the hologram text
*/
@ -491,28 +501,28 @@ public class Hologram
{
// Add entity id and send spawn packets
// You add a entity id because the new hologram needs
Entry<Integer, Integer> entry = new HashMap.SimpleEntry(UtilEnt.getNewEntityId(), UtilEnt.getNewEntityId());
_entityIds.add(entry);
int entityId = UtilEnt.getNewEntityId();
_entityIds.add(entityId);
packets1_8.addAll(Arrays.asList(makeSpawnPackets1_8(i, entry.getKey(), newText[i])));
packets1_8.addAll(Arrays.asList(makeSpawnPackets1_8(i, entityId, newText[i])));
}
// If less lines than previously
else if (i >= newText.length)
{
// Remove entity id and send destroy packets
Entry<Integer, Integer> entry = _entityIds.remove(newText.length);
Integer entityId = _entityIds.remove(newText.length);
destroy1_8 = Arrays.copyOf(destroy1_8, destroy1_8.length + 1);
destroy1_8[destroy1_8.length - 1] = entry.getKey();
destroy1_8[destroy1_8.length - 1] = entityId;
}
else if (!newText[i].equals(_hologramText[i]))
{
// Send update metadata packets
Entry<Integer, Integer> entry = _entityIds.get(i);
Integer entityId = _entityIds.get(i);
PacketPlayOutEntityMetadata metadata1_8 = new PacketPlayOutEntityMetadata();
metadata1_8.a = entry.getKey();
metadata1_8.a = entityId;
DataWatcher watcher1_8 = new DataWatcher(null);
@ -552,7 +562,7 @@ public class Hologram
*/
public Hologram setViewDistance(int newDistance)
{
this._viewDistance = newDistance;
_viewDistance = newDistance;
return setLocation(getLocation());
}
@ -593,6 +603,7 @@ public class Hologram
_playersTracking.clear();
_lastMovement = null;
}
return this;
}

View File

@ -0,0 +1,9 @@
package mineplex.core.hologram;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
public interface HologramInteraction
{
public void onClick(Player player, ClickType clickType);
}

View File

@ -5,28 +5,33 @@ import java.util.Iterator;
import java.util.List;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.packethandler.IPacketHandler;
import mineplex.core.packethandler.PacketHandler;
import mineplex.core.packethandler.PacketInfo;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import net.minecraft.server.v1_8_R3.Packet;
import net.minecraft.server.v1_8_R3.PacketPlayInUseEntity;
import net.minecraft.server.v1_8_R3.PacketPlayInUseEntity.EnumEntityUseAction;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.Vector;
public class HologramManager implements Listener
public class HologramManager implements Listener, IPacketHandler
{
private ArrayList<Hologram> _activeHolograms = new ArrayList<Hologram>();
public HologramManager(JavaPlugin arcadeManager)
public HologramManager(JavaPlugin arcadeManager, PacketHandler packetHandler)
{
Bukkit.getPluginManager().registerEvents(this, arcadeManager);
packetHandler.addPacketHandler(this, true, PacketPlayInUseEntity.class);
}
void addHologram(Hologram hologram)
@ -44,11 +49,15 @@ public class HologramManager implements Listener
{
if (event.getType() != UpdateType.TICK || _activeHolograms.isEmpty())
return;
List<World> worlds = Bukkit.getWorlds();
Iterator<Hologram> itel = _activeHolograms.iterator();
while (itel.hasNext())
{
Hologram hologram = itel.next();
if (!worlds.contains(hologram.getLocation().getWorld()))
{
itel.remove();
@ -59,6 +68,7 @@ public class HologramManager implements Listener
if (hologram.getEntityFollowing() != null)
{
Entity following = hologram.getEntityFollowing();
if (hologram.isRemoveOnEntityDeath() && !following.isValid())
{
itel.remove();
@ -71,14 +81,19 @@ public class HologramManager implements Listener
Vector vec = hologram.relativeToEntity.clone();
hologram.setLocation(following.getLocation().add(hologram.relativeToEntity));
hologram.relativeToEntity = vec;
continue; // No need to do the rest of the code as setLocation does it.
}
}
ArrayList<Player> canSee = hologram.getNearbyPlayers();
Iterator<Player> itel2 = hologram.getPlayersTracking().iterator();
while (itel2.hasNext())
{
Player player = itel2.next();
if (!canSee.contains(player))
{
itel2.remove();
@ -88,6 +103,7 @@ public class HologramManager implements Listener
}
}
}
for (Player player : canSee)
{
if (!hologram.getPlayersTracking().contains(player))
@ -100,4 +116,24 @@ public class HologramManager implements Listener
}
}
}
@Override
public void handle(PacketInfo packetInfo)
{
PacketPlayInUseEntity packetPlayIn = (PacketPlayInUseEntity) packetInfo.getPacket();
for (Hologram hologram : _activeHolograms)
{
if (!hologram.isEntityId(packetPlayIn.a))
continue;
if (hologram.getInteraction() != null)
{
hologram.getInteraction().onClick(packetInfo.getPlayer(),
packetPlayIn.action == EnumEntityUseAction.ATTACK ? ClickType.LEFT : ClickType.RIGHT);
}
break;
}
}
}

View File

@ -12,6 +12,7 @@ import mineplex.core.common.util.UtilTextMiddle;
import mineplex.core.donation.DonationManager;
import mineplex.core.gadget.event.GadgetBlockEvent;
import mineplex.core.hologram.Hologram;
import mineplex.core.hologram.HologramInteraction;
import mineplex.core.hologram.HologramManager;
import mineplex.core.inventory.InventoryManager;
import mineplex.core.reward.Reward;
@ -32,6 +33,7 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerMoveEvent;
@ -63,7 +65,20 @@ public class TreasureLocation implements Listener
_hologramManager = hologramManager;
_statusManager = statusManager;
_currentTreasure = null;
_hologram = new Hologram(_hologramManager, chestBlock.getLocation().add(0.5, 2.5, 0.5), C.cGreen + C.Bold + "Open Treasure");
_hologram = new Hologram(_hologramManager, chestBlock.getLocation().add(0.5, 2.5, 0.5), C.cGreen + C.Bold
+ "Open Treasure");
_hologram.setInteraction(new HologramInteraction()
{
@Override
public void onClick(Player player, ClickType clickType)
{
if (clickType == ClickType.LEFT)
return;
openShop(player);
}
});
setHoloChestVisible(true);
_shop = new TreasureShop(treasureManager, _inventoryManager, clientManager, donationManager, this);
}

View File

@ -133,7 +133,7 @@ public class Hub extends JavaPlugin implements IRelation
SkillConditionManager conditionManager = new SkillConditionManager(this);
PersonalServerManager personalServerManager = new PersonalServerManager(this, clientManager);
HubManager hubManager = new HubManager(this, blockRestore, clientManager, donationManager, inventoryManager, conditionManager, disguiseManager, new TaskManager(this, clientManager, webServerAddress), portal, partyManager, preferenceManager, petManager, pollManager, statsManager, achievementManager, new HologramManager(this), npcManager, personalServerManager, packetHandler, punish, serverStatusManager, giveawayManager);
HubManager hubManager = new HubManager(this, blockRestore, clientManager, donationManager, inventoryManager, conditionManager, disguiseManager, new TaskManager(this, clientManager, webServerAddress), portal, partyManager, preferenceManager, petManager, pollManager, statsManager, achievementManager, new HologramManager(this, packetHandler), npcManager, personalServerManager, packetHandler, punish, serverStatusManager, giveawayManager);
QueueManager queueManager = new QueueManager(this, clientManager, donationManager, new EloManager(this, clientManager), partyManager);

View File

@ -136,7 +136,7 @@ public class Arcade extends JavaPlugin
BlockRestore blockRestore = new BlockRestore(this);
ProjectileManager projectileManager = new ProjectileManager(this);
HologramManager hologramManager = new HologramManager(this);
HologramManager hologramManager = new HologramManager(this, packetHandler);
//Inventory
InventoryManager inventoryManager = new InventoryManager(this, _clientManager);