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.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map.Entry;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; 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. * 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 Entity _followEntity;
private HologramManager _hologramManager; private HologramManager _hologramManager;
private String[] _hologramText = new String[0]; private String[] _hologramText = new String[0];
@ -53,6 +50,7 @@ public class Hologram
private int _viewDistance = 70; private int _viewDistance = 70;
protected Vector relativeToEntity; protected Vector relativeToEntity;
private boolean _hideBoundingBox; private boolean _hideBoundingBox;
private HologramInteraction _interaction;
public Hologram(HologramManager hologramManager, Location location, String... text) public Hologram(HologramManager hologramManager, Location location, String... text)
{ {
@ -61,6 +59,18 @@ public class Hologram
setText(text); 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 * Adds the player to the Hologram to be effected by Whitelist or Blacklist
*/ */
@ -151,6 +161,7 @@ public class Hologram
nearbyPlayers.add(player); nearbyPlayers.add(player);
} }
} }
return nearbyPlayers; return nearbyPlayers;
} }
@ -229,9 +240,7 @@ public class Hologram
for (int i = 0; i < _entityIds.size(); i++) for (int i = 0; i < _entityIds.size(); i++)
{ {
Entry<Integer, Integer> entry = _entityIds.get(i); entityIds1_8[i] = _entityIds.get(i);
entityIds1_8[i] = entry.getKey();
} }
_destroy1_8 = new PacketPlayOutEntityDestroy(entityIds1_8); _destroy1_8 = new PacketPlayOutEntityDestroy(entityIds1_8);
@ -247,7 +256,7 @@ public class Hologram
for (int i = _entityIds.size(); i < _hologramText.length; i++) for (int i = _entityIds.size(); i < _hologramText.length; i++)
{ {
_entityIds.add(new HashMap.SimpleEntry(UtilEnt.getNewEntityId(), UtilEnt.getNewEntityId())); _entityIds.add(UtilEnt.getNewEntityId());
} }
} }
else else
@ -261,9 +270,7 @@ public class Hologram
} }
for (int textRow = 0; textRow < _hologramText.length; textRow++) for (int textRow = 0; textRow < _hologramText.length; textRow++)
{ {
Entry<Integer, Integer> entityIds = this._entityIds.get(textRow); Packet[] packets1_8 = makeSpawnPackets1_8(textRow, _entityIds.get(textRow), _hologramText[textRow]);
Packet[] packets1_8 = makeSpawnPackets1_8(textRow, entityIds.getKey(), _hologramText[textRow]);
for (int i = 0; i < packets1_8.length; i++) for (int i = 0; i < packets1_8.length; i++)
{ {
@ -326,8 +333,7 @@ public class Hologram
public Hologram setFollowEntity(Entity entityToFollow) public Hologram setFollowEntity(Entity entityToFollow)
{ {
_followEntity = entityToFollow; _followEntity = entityToFollow;
relativeToEntity = entityToFollow == null ? null : this._location.clone().subtract(entityToFollow.getLocation()) relativeToEntity = entityToFollow == null ? null : _location.clone().subtract(entityToFollow.getLocation()).toVector();
.toVector();
return this; return this;
} }
@ -340,7 +346,7 @@ public class Hologram
*/ */
public Hologram setHologramTarget(HologramTarget newTarget) public Hologram setHologramTarget(HologramTarget newTarget)
{ {
this._target = newTarget; _target = newTarget;
return this; return this;
} }
@ -405,11 +411,11 @@ public class Hologram
if (x >= -128 && x <= 127 && y >= -128 && y <= 127 && z >= -128 && z <= 127) if (x >= -128 && x <= 127 && y >= -128 && y <= 127 && z >= -128 && z <= 127)
{ {
_lastMovement.subtract(new Vector(x / 32D, y / 32D, z / 32D)); _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(); PacketPlayOutEntity.PacketPlayOutRelEntityMove relMove = new PacketPlayOutEntity.PacketPlayOutRelEntityMove();
relMove.a = entityId.getKey(); relMove.a = entityId;
relMove.b = (byte) x; relMove.b = (byte) x;
relMove.c = (byte) y; relMove.c = (byte) y;
relMove.d = (byte) z; relMove.d = (byte) z;
@ -425,13 +431,12 @@ public class Hologram
_lastMovement = new Vector(newLocation.getX() - (x / 32D), 0, newLocation.getZ() - (z / 32D)); _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(); PacketPlayOutEntityTeleport teleportPacket = new PacketPlayOutEntityTeleport();
teleportPacket.a = entityId.getKey(); teleportPacket.a = entityId;
teleportPacket.b = x; teleportPacket.b = x;
teleportPacket.c = (int) Math teleportPacket.c = (int) Math.floor((oldLocation.getY() + (-2.1) + ((double) i * 0.285)) * 32);
.floor((oldLocation.getY() + (-2.1) + ((double) i * 0.285)) * 32);
teleportPacket.d = z; teleportPacket.d = z;
packets1_8[i] = teleportPacket; packets1_8[i] = teleportPacket;
@ -458,6 +463,11 @@ public class Hologram
return this; return this;
} }
public boolean isEntityId(int entityId)
{
return _entityIds.contains(entityId);
}
/** /**
* Set the hologram text * Set the hologram text
*/ */
@ -491,28 +501,28 @@ public class Hologram
{ {
// Add entity id and send spawn packets // Add entity id and send spawn packets
// You add a entity id because the new hologram needs // You add a entity id because the new hologram needs
Entry<Integer, Integer> entry = new HashMap.SimpleEntry(UtilEnt.getNewEntityId(), UtilEnt.getNewEntityId()); int entityId = UtilEnt.getNewEntityId();
_entityIds.add(entry); _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 // If less lines than previously
else if (i >= newText.length) else if (i >= newText.length)
{ {
// Remove entity id and send destroy packets // 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 = 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])) else if (!newText[i].equals(_hologramText[i]))
{ {
// Send update metadata packets // Send update metadata packets
Entry<Integer, Integer> entry = _entityIds.get(i); Integer entityId = _entityIds.get(i);
PacketPlayOutEntityMetadata metadata1_8 = new PacketPlayOutEntityMetadata(); PacketPlayOutEntityMetadata metadata1_8 = new PacketPlayOutEntityMetadata();
metadata1_8.a = entry.getKey(); metadata1_8.a = entityId;
DataWatcher watcher1_8 = new DataWatcher(null); DataWatcher watcher1_8 = new DataWatcher(null);
@ -552,7 +562,7 @@ public class Hologram
*/ */
public Hologram setViewDistance(int newDistance) public Hologram setViewDistance(int newDistance)
{ {
this._viewDistance = newDistance; _viewDistance = newDistance;
return setLocation(getLocation()); return setLocation(getLocation());
} }
@ -593,6 +603,7 @@ public class Hologram
_playersTracking.clear(); _playersTracking.clear();
_lastMovement = null; _lastMovement = null;
} }
return this; 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,90 +5,106 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import mineplex.core.common.util.UtilPlayer; 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.UpdateType;
import mineplex.core.updater.event.UpdateEvent; 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.Bukkit;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
public class HologramManager implements Listener public class HologramManager implements Listener, IPacketHandler
{ {
private ArrayList<Hologram> _activeHolograms = new ArrayList<Hologram>(); private ArrayList<Hologram> _activeHolograms = new ArrayList<Hologram>();
public HologramManager(JavaPlugin arcadeManager) public HologramManager(JavaPlugin arcadeManager, PacketHandler packetHandler)
{ {
Bukkit.getPluginManager().registerEvents(this, arcadeManager); Bukkit.getPluginManager().registerEvents(this, arcadeManager);
} packetHandler.addPacketHandler(this, true, PacketPlayInUseEntity.class);
}
void addHologram(Hologram hologram) void addHologram(Hologram hologram)
{ {
_activeHolograms.add(hologram); _activeHolograms.add(hologram);
} }
void removeHologram(Hologram hologram) void removeHologram(Hologram hologram)
{ {
_activeHolograms.remove(hologram); _activeHolograms.remove(hologram);
} }
@EventHandler(priority = EventPriority.LOWEST) @EventHandler(priority = EventPriority.LOWEST)
public void onTick(UpdateEvent event) public void onTick(UpdateEvent event)
{ {
if (event.getType() != UpdateType.TICK || _activeHolograms.isEmpty()) if (event.getType() != UpdateType.TICK || _activeHolograms.isEmpty())
return; return;
List<World> worlds = Bukkit.getWorlds();
Iterator<Hologram> itel = _activeHolograms.iterator(); List<World> worlds = Bukkit.getWorlds();
while (itel.hasNext())
{ Iterator<Hologram> itel = _activeHolograms.iterator();
Hologram hologram = itel.next();
if (!worlds.contains(hologram.getLocation().getWorld())) while (itel.hasNext())
{ {
itel.remove(); Hologram hologram = itel.next();
hologram.stop();
} if (!worlds.contains(hologram.getLocation().getWorld()))
else {
{ itel.remove();
if (hologram.getEntityFollowing() != null) hologram.stop();
{ }
Entity following = hologram.getEntityFollowing(); else
if (hologram.isRemoveOnEntityDeath() && !following.isValid()) {
{ if (hologram.getEntityFollowing() != null)
itel.remove(); {
hologram.stop(); Entity following = hologram.getEntityFollowing();
continue;
} if (hologram.isRemoveOnEntityDeath() && !following.isValid())
if (!hologram.relativeToEntity.equals(following.getLocation().subtract(hologram.getLocation()).toVector())) {
{ itel.remove();
// And we do this so in the rare offchance it changes by a decimal. It doesn't start turning wonky. hologram.stop();
Vector vec = hologram.relativeToEntity.clone(); continue;
hologram.setLocation(following.getLocation().add(hologram.relativeToEntity)); }
hologram.relativeToEntity = vec; if (!hologram.relativeToEntity.equals(following.getLocation().subtract(hologram.getLocation()).toVector()))
continue; // No need to do the rest of the code as setLocation does it. {
} // And we do this so in the rare offchance it changes by a decimal. It doesn't start turning wonky.
} Vector vec = hologram.relativeToEntity.clone();
ArrayList<Player> canSee = hologram.getNearbyPlayers(); hologram.setLocation(following.getLocation().add(hologram.relativeToEntity));
Iterator<Player> itel2 = hologram.getPlayersTracking().iterator(); hologram.relativeToEntity = vec;
while (itel2.hasNext())
{ continue; // No need to do the rest of the code as setLocation does it.
Player player = itel2.next(); }
if (!canSee.contains(player)) }
{
itel2.remove(); ArrayList<Player> canSee = hologram.getNearbyPlayers();
if (player.getWorld() == hologram.getLocation().getWorld())
{ Iterator<Player> itel2 = hologram.getPlayersTracking().iterator();
UtilPlayer.sendPacket(player, hologram.getDestroyPacket());
} while (itel2.hasNext())
} {
} Player player = itel2.next();
for (Player player : canSee)
if (!canSee.contains(player))
{
itel2.remove();
if (player.getWorld() == hologram.getLocation().getWorld())
{
UtilPlayer.sendPacket(player, hologram.getDestroyPacket());
}
}
}
for (Player player : canSee)
{ {
if (!hologram.getPlayersTracking().contains(player)) if (!hologram.getPlayersTracking().contains(player))
{ {
@ -96,8 +112,28 @@ public class HologramManager implements Listener
UtilPlayer.sendPacket(player, hologram.getSpawnPackets()); UtilPlayer.sendPacket(player, hologram.getSpawnPackets());
} }
} }
} }
} }
} }
@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.donation.DonationManager;
import mineplex.core.gadget.event.GadgetBlockEvent; import mineplex.core.gadget.event.GadgetBlockEvent;
import mineplex.core.hologram.Hologram; import mineplex.core.hologram.Hologram;
import mineplex.core.hologram.HologramInteraction;
import mineplex.core.hologram.HologramManager; import mineplex.core.hologram.HologramManager;
import mineplex.core.inventory.InventoryManager; import mineplex.core.inventory.InventoryManager;
import mineplex.core.reward.Reward; import mineplex.core.reward.Reward;
@ -32,6 +33,7 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.Action; import org.bukkit.event.block.Action;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.event.inventory.InventoryOpenEvent; import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerMoveEvent;
@ -63,7 +65,20 @@ public class TreasureLocation implements Listener
_hologramManager = hologramManager; _hologramManager = hologramManager;
_statusManager = statusManager; _statusManager = statusManager;
_currentTreasure = null; _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); setHoloChestVisible(true);
_shop = new TreasureShop(treasureManager, _inventoryManager, clientManager, donationManager, this); _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); SkillConditionManager conditionManager = new SkillConditionManager(this);
PersonalServerManager personalServerManager = new PersonalServerManager(this, clientManager); 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); 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); BlockRestore blockRestore = new BlockRestore(this);
ProjectileManager projectileManager = new ProjectileManager(this); ProjectileManager projectileManager = new ProjectileManager(this);
HologramManager hologramManager = new HologramManager(this); HologramManager hologramManager = new HologramManager(this, packetHandler);
//Inventory //Inventory
InventoryManager inventoryManager = new InventoryManager(this, _clientManager); InventoryManager inventoryManager = new InventoryManager(this, _clientManager);