From 141c08ceb89081967eebabd4dabd71b50ef5d7c0 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Wed, 26 Nov 2014 09:18:36 +1300 Subject: [PATCH 01/29] Remove old holograms and add new holograms --- .../core/hologram/ArmorStandHologram.java | 89 --- .../src/mineplex/core/hologram/Hologram.java | 690 ++++++++++++++++-- .../mineplex/core/hologram/HorseHologram.java | 132 ---- .../animation/ChestOpenAnimation.java | 94 +-- 4 files changed, 692 insertions(+), 313 deletions(-) delete mode 100644 Plugins/Mineplex.Core/src/mineplex/core/hologram/ArmorStandHologram.java delete mode 100644 Plugins/Mineplex.Core/src/mineplex/core/hologram/HorseHologram.java diff --git a/Plugins/Mineplex.Core/src/mineplex/core/hologram/ArmorStandHologram.java b/Plugins/Mineplex.Core/src/mineplex/core/hologram/ArmorStandHologram.java deleted file mode 100644 index e0f66b2e1..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/hologram/ArmorStandHologram.java +++ /dev/null @@ -1,89 +0,0 @@ -package mineplex.core.hologram; - -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_7_R4.CraftWorld; -import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer; -import org.bukkit.entity.Player; -import net.minecraft.server.v1_7_R4.DataWatcher; -import net.minecraft.server.v1_7_R4.EnumEntitySize; -import net.minecraft.server.v1_7_R4.MathHelper; -import net.minecraft.server.v1_7_R4.Packet; -import net.minecraft.server.v1_7_R4.PacketPlayOutEntityDestroy; -import net.minecraft.server.v1_7_R4.PacketPlayOutSpawnEntityLiving; -import net.minecraft.server.v1_7_R4.PlayerConnection; - -import mineplex.core.common.DummyEntity; -import mineplex.core.common.util.UtilEnt; - -/** - * Created by Shaun on 9/5/2014. - */ -public class ArmorStandHologram -{ - private String _text; - private Packet _packet; - private int _entityId; - - public ArmorStandHologram(Location location, String text) - { - _text = text; - - _entityId = UtilEnt.getNewEntityId(); - _packet = createArmorStandPacket(location); - } - - public void sendToPlayer(Player player) - { - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(_packet); - } - - public void removeForPlayer(Player player) - { - PacketPlayOutEntityDestroy entityDestroyPacket = new PacketPlayOutEntityDestroy(_entityId); - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(entityDestroyPacket); - } - - private PacketPlayOutSpawnEntityLiving createArmorStandPacket(Location location) - { - final PacketPlayOutSpawnEntityLiving packet = new PacketPlayOutSpawnEntityLiving(); - packet.a = _entityId; - packet.b = (byte) 30; - packet.c = MathHelper.floor(location.getX() * 32D);//(int) EnumEntitySize.SIZE_2.a(100); - packet.d = MathHelper.floor((location.getY() - 0.8) * 32D);//(int) MathHelper.floor(64 * 32.0D); - packet.e = MathHelper.floor(location.getZ() * 32D);//(int)EnumEntitySize.SIZE_2.a(100); - packet.f = 0; // Velocity X - packet.g = 0; // Velocity Y - packet.h = 0; // Velocity Z - packet.i = (byte) 0; // Yaw - packet.j = (byte) 0; // Pitch - packet.k = (byte) 0; // Head Pitch - - final DataWatcher watcher = new DataWatcher(new DummyEntity(((CraftWorld)location.getWorld()).getHandle())); - - watcher.a(0, Byte.valueOf((byte)0)); - watcher.a(1, Short.valueOf((short)300)); - watcher.a(2, _text); - watcher.a(3, Byte.valueOf((byte) 1)); - watcher.a(4, Byte.valueOf((byte)0)); - watcher.a(7, Integer.valueOf(0)); - watcher.a(8, Byte.valueOf((byte)0)); - watcher.a(9, Byte.valueOf((byte)0)); - watcher.a(6, Float.valueOf(1.0F)); - watcher.a(10, Byte.valueOf((byte)0)); - - // Set invisible - int i1 = watcher.getInt(0); - watcher.watch(0, Byte.valueOf((byte)(i1 | 1 << 5))); - - // Set small and No Gravity - byte b1 = watcher.getByte(10); - b1 = (byte)(b1 | 0x1); - b1 = (byte)(b1 | 0x2); - watcher.watch(10, Byte.valueOf(b1)); - - packet.l = watcher; - - return packet; - } - -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/hologram/Hologram.java b/Plugins/Mineplex.Core/src/mineplex/core/hologram/Hologram.java index 7244427fa..584b6d461 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/hologram/Hologram.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/hologram/Hologram.java @@ -1,8 +1,30 @@ package mineplex.core.hologram; -import org.bukkit.Location; -import org.bukkit.entity.Player; +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 net.minecraft.server.v1_7_R4.DataWatcher; +import net.minecraft.server.v1_7_R4.Packet; +import net.minecraft.server.v1_7_R4.PacketPlayOutAttachEntity; +import net.minecraft.server.v1_7_R4.PacketPlayOutEntityDestroy; +import net.minecraft.server.v1_7_R4.PacketPlayOutEntityMetadata; +import net.minecraft.server.v1_7_R4.PacketPlayOutEntityTeleport; +import net.minecraft.server.v1_7_R4.PacketPlayOutRelEntityMove; +import net.minecraft.server.v1_7_R4.PacketPlayOutSpawnEntity; +import net.minecraft.server.v1_7_R4.PacketPlayOutSpawnEntityLiving; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer; +import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.util.Vector; + +import mineplex.core.common.util.UtilEnt; import mineplex.core.common.util.UtilPlayer; /** @@ -10,59 +32,629 @@ import mineplex.core.common.util.UtilPlayer; */ public class Hologram { - private HorseHologram _horseHologram; - private ArmorStandHologram _armorStandHologram; - private Location _location; - private String _text; + public enum HologramTarget + { + BLACKLIST, WHITELIST; + } - public Hologram(Location location, String text) - { - _location = location; - _text = text; + private Packet _destroy1_7; + private Packet _destroy1_8; + private boolean _destroyPackets = true; + /** + * 1.7 packets uses both EntityIDs while 1.8 uses only the first. + */ + private ArrayList> _entityIds = new ArrayList>(); + private boolean _isWitherSkull; + /** + * Keeps track of the holograms movements. This fixes offset that occasionally happens when moving a hologram around. + */ + private Vector _lastMovement; + private Location _location; + private boolean _makePackets = true; + private Packet[] _packets1_7; + private Packet[] _packets1_8; + private HashSet _playersInList = new HashSet(); + private ArrayList _playersTracking = new ArrayList(); + private BukkitRunnable _runnable; + private HologramTarget _target = HologramTarget.BLACKLIST; + private String[] _text = new String[0]; + private int _viewDistance = 70; - _horseHologram = new HorseHologram(location, text); - _armorStandHologram = new ArmorStandHologram(location, text); - } + public Hologram(Location location, String... text) + { + _location = location.clone(); + setText(text); + } - public void sendToPlayer(Player player) - { - if (UtilPlayer.is1_8(player)) - { - _armorStandHologram.sendToPlayer(player); - } - else - { - _horseHologram.sendToPlayer(player); - } - } + /** + * Adds the player to the Hologram to be effected by Whitelist or Blacklist + */ + public Hologram addPlayer(Player player) + { + return addPlayer(player.getName()); + } - public void sendToPlayers(Player... players) - { - for (Player player : players) - { - sendToPlayer(player); - } - } + /** + * Adds the player to the Hologram to be effected by Whitelist or Blacklist + */ + public Hologram addPlayer(String player) + { + _playersInList.add(player); + return this; + } - public void removeForPlayer(Player player) - { - if (UtilPlayer.is1_8(player)) - { - _armorStandHologram.removeForPlayer(player); - } - else - { - _horseHologram.removeForPlayer(player); - } - } + /** + * Is there a player entry in the hologram for Whitelist and Blacklist + */ + public boolean containsPlayer(Player player) + { + return _playersInList.contains(player.getName()); + } - public void removeForPlayers(Player... players) - { - for (Player player : players) - { - removeForPlayer(player); - } - } + /** + * Is there a player entry in the hologram for Whitelist and Blacklist + */ + public boolean containsPlayer(String player) + { + return _playersInList.contains(player); + } + + private Packet getDestroyPacket(Player player) + { + if (_destroyPackets) + { + makeDestroyPacket(); + _destroyPackets = false; + } + return UtilPlayer.is1_8(player) ? _destroy1_8 : _destroy1_7; + } + + /** + * Get who can see the hologram + * + * @Whitelist = Only people added can see the hologram + * @Blacklist = Anyone but people added can see the hologram + */ + public HologramTarget getHologramTarget() + { + return _target; + } + + /** + * Get the hologram location + */ + public Location getLocation() + { + return _location.clone(); + } + + private ArrayList getNearbyPlayers() + { + ArrayList nearbyPlayers = new ArrayList(); + for (Player player : getLocation().getWorld().getPlayers()) + { + if (isVisible(player)) + { + nearbyPlayers.add(player); + } + } + return nearbyPlayers; + } + + private Packet[] getSpawnPackets(Player player) + { + if (_makePackets) + { + makeSpawnPackets(); + _makePackets = false; + } + return UtilPlayer.is1_8(player) ? _packets1_8 : _packets1_7; + } + + /** + * Get the text in the hologram + */ + public String[] getText() + { + // We reverse it again as the hologram would otherwise display the text from the bottom row to the top row + String[] reversed = new String[_text.length]; + for (int i = 0; i < reversed.length; i++) + { + reversed[i] = _text[reversed.length - (i + 1)]; + } + return reversed; + } + + /** + * Get the view distance the hologram is viewable from. Default is 70 + */ + public int getViewDistance() + { + return _viewDistance; + } + + /** + * Is the hologram holograming? + */ + public boolean isInUse() + { + return _runnable != null; + } + + /** + * Does the hologram use the wither skull for 1.8 clients? + */ + public boolean isUsingWitherSkull() + { + return _isWitherSkull; + } + + public boolean isVisible(Player player) + { + if (getLocation().getWorld() == player.getWorld()) + { + if ((getHologramTarget() == HologramTarget.WHITELIST) == containsPlayer(player)) + { + if (getLocation().distance(player.getLocation()) < getViewDistance()) + { + return true; + } + } + } + return false; + } + + private void makeDestroyPacket() + { + int[] entityIds1_7 = new int[_entityIds.size() * 2]; + int[] entityIds1_8 = new int[_entityIds.size()]; + for (int i = 0; i < _entityIds.size(); i++) + { + Entry entry = _entityIds.get(i); + entityIds1_7[i * 2] = entry.getKey(); + entityIds1_7[(i * 2) + 1] = entry.getValue(); + entityIds1_8[i] = entry.getKey(); + } + _destroy1_7 = new PacketPlayOutEntityDestroy(entityIds1_7); + _destroy1_8 = new PacketPlayOutEntityDestroy(entityIds1_8); + } + + private void makeSpawnPackets() + { + _packets1_7 = new Packet[_text.length * 3]; + _packets1_8 = new Packet[_text.length * (isUsingWitherSkull() ? 2 : 1)]; + if (_entityIds.size() < _text.length) + { + _destroyPackets = true; + for (int i = _entityIds.size(); i < _text.length; i++) + { + _entityIds.add(new HashMap.SimpleEntry(UtilEnt.getNewEntityId(), UtilEnt.getNewEntityId())); + } + } + else + { + _destroyPackets = true; + while (_entityIds.size() > _text.length) + { + _entityIds.remove(_text.length); + } + } + for (int textRow = 0; textRow < _text.length; textRow++) + { + Entry entityIds = this._entityIds.get(textRow); + Packet[] packets1_7 = makeSpawnPackets1_7(textRow, entityIds.getKey(), entityIds.getValue(), _text[textRow]); + for (int i = 0; i < packets1_7.length; i++) + { + _packets1_7[(textRow * 3) + i] = packets1_7[i]; + } + + Packet[] packets1_8 = makeSpawnPackets1_8(textRow, entityIds.getKey(), _text[textRow]); + for (int i = 0; i < packets1_8.length; i++) + { + _packets1_8[(textRow * (isUsingWitherSkull() ? 2 : 1)) + i] = packets1_8[i]; + } + } + } + + private Packet[] makeSpawnPackets1_7(int height, int witherId, int horseId, String horseName) + { + // Spawn wither skull + PacketPlayOutSpawnEntity spawnWitherSkull = new PacketPlayOutSpawnEntity(); + spawnWitherSkull.a = witherId; + spawnWitherSkull.b = (int) (getLocation().getX() * 32); + spawnWitherSkull.c = (int) ((getLocation().getY() + 54.6 + ((double) height * 0.285D)) * 32); + spawnWitherSkull.d = (int) (getLocation().getZ() * 32); + spawnWitherSkull.j = 66; + // Spawn horse + PacketPlayOutSpawnEntityLiving spawnHorse = new PacketPlayOutSpawnEntityLiving(); + spawnHorse.a = horseId; + spawnHorse.b = 100; + spawnHorse.c = (int) (getLocation().getX() * 32); + spawnHorse.d = (int) ((getLocation().getY() + 54.83 + ((double) height * 0.285D) + 0.23D) * 32); + spawnHorse.e = (int) (getLocation().getZ() * 32); + // Setup datawatcher + DataWatcher watcher = new DataWatcher(null); + watcher.a(0, (byte) 0); + watcher.a(1, (short) 300); + watcher.a(10, horseName); + watcher.a(11, (byte) 1); + watcher.a(12, -1700000); + spawnHorse.l = watcher; + // Make horse ride wither + PacketPlayOutAttachEntity attachEntity = new PacketPlayOutAttachEntity(); + attachEntity.b = horseId; + attachEntity.c = witherId; + return new Packet[] + { + spawnWitherSkull, spawnHorse, attachEntity + }; + } + + private Packet[] makeSpawnPackets1_8(int textRow, int entityId, String lineOfText) + { + if (this.isUsingWitherSkull()) + { + PacketPlayOutSpawnEntity spawnPacket = new PacketPlayOutSpawnEntity(); + spawnPacket.a = entityId; + spawnPacket.b = (int) (getLocation().getX() * 32); + spawnPacket.c = (int) ((getLocation().getY() + -0.55 + ((double) textRow * 0.285)) * 32); + spawnPacket.d = (int) (getLocation().getZ() * 32); + spawnPacket.j = 66; + // Setup datawatcher for wither skull + PacketPlayOutEntityMetadata metadataPacket = new PacketPlayOutEntityMetadata(); + metadataPacket.a = entityId; + DataWatcher watcher = new DataWatcher(null); + watcher.a(0, (byte) 0); + watcher.a(2, lineOfText); + watcher.a(3, (byte) 1); + metadataPacket.b = watcher.c(); + return new Packet[] + { + spawnPacket, metadataPacket + }; + } + else + { + PacketPlayOutSpawnEntityLiving packet = new PacketPlayOutSpawnEntityLiving(); + packet.a = entityId; + packet.b = 30; + packet.c = (int) (getLocation().getX() * 32); + packet.d = (int) ((getLocation().getY() + -2.1 + ((double) textRow * 0.285)) * 32); + packet.e = (int) (getLocation().getZ() * 32); + // Setup datawatcher for armor stand + DataWatcher watcher = new DataWatcher(null); + watcher.a(0, (byte) 32); + watcher.a(2, lineOfText); + watcher.a(3, (byte) 1); + packet.l = watcher; + return new Packet[] + { + packet + }; + } + } + + /** + * Removes the player from the Hologram so they are no longer effected by Whitelist or Blacklist + */ + public Hologram removePlayer(Player player) + { + return addPlayer(player.getName()); + } + + /** + * Removes the player from the Hologram so they are no longer effected by Whitelist or Blacklist + */ + public Hologram removePlayer(String player) + { + _playersInList.remove(player); + return this; + } + + /** + * Set who can see the hologram + * + * @Whitelist = Only people added can see the hologram + * @Blacklist = Anyone but people added can see the hologram + */ + public Hologram setHologramTarget(HologramTarget newTarget) + { + this._target = newTarget; + return this; + } + + /** + * Sets the hologram to appear at this location + */ + public Hologram setLocation(Location newLocation) + { + _makePackets = true; + Location oldLocation = getLocation(); + _location = newLocation.clone(); + if (isInUse()) + { + ArrayList canSee = getNearbyPlayers(); + Iterator itel = _playersTracking.iterator(); + while (itel.hasNext()) + { + Player player = itel.next(); + if (!canSee.contains(player)) + { + itel.remove(); + if (player.getWorld() == getLocation().getWorld()) + { + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(getDestroyPacket(player)); + } + } + } + itel = canSee.iterator(); + while (itel.hasNext()) + { + Player player = itel.next(); + if (!_playersTracking.contains(player)) + { + _playersTracking.add(player); + itel.remove(); + for (Packet packet : getSpawnPackets(player)) + { + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); + } + } + } + if (!canSee.isEmpty()) + { + _lastMovement.add(new Vector(newLocation.getX() - oldLocation.getX(), newLocation.getY() - oldLocation.getY(), + newLocation.getZ() - oldLocation.getZ())); + int x = (int) Math.floor(32 * _lastMovement.getX()); + int y = (int) Math.floor(32 * _lastMovement.getY()); + int z = (int) Math.floor(32 * _lastMovement.getZ()); + Packet[] packets1_7 = new Packet[_text.length]; + Packet[] packets1_8 = new Packet[_text.length]; + int i = 0; + 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 entityId : this._entityIds) + { + PacketPlayOutRelEntityMove relMove = new PacketPlayOutRelEntityMove(); + relMove.a = entityId.getKey(); + relMove.b = (byte) x; + relMove.c = (byte) y; + relMove.d = (byte) z; + packets1_7[i] = relMove; + packets1_8[i] = relMove; + i++; + } + } + else + { + x = (int) Math.floor(32 * newLocation.getX()); + z = (int) Math.floor(32 * newLocation.getZ()); + _lastMovement = new Vector(newLocation.getX() - (x / 32D), 0, newLocation.getZ() - (z / 32D)); + for (Entry entityId : this._entityIds) + { + for (int b = 0; b < 2; b++) + { + PacketPlayOutEntityTeleport teleportPacket = new PacketPlayOutEntityTeleport(); + teleportPacket.a = entityId.getKey(); + teleportPacket.b = x; + teleportPacket.c = (int) Math.floor((oldLocation.getY() + + (b == 0 ? 54.6 : isUsingWitherSkull() ? -0.55 : -2.1) + ((double) i * 0.285)) * 32); + teleportPacket.d = z; + if (b == 0) + { + packets1_7[i] = teleportPacket; + } + else + { + packets1_8[i] = teleportPacket; + } + } + i++; + } + } + for (Player player : canSee) + { + for (Packet packet : UtilPlayer.is1_8(player) ? packets1_8 : packets1_7) + { + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); + } + } + } + } + return this; + } + + /** + * Set the hologram text + */ + public Hologram setText(String... newText) + { + String[] reversed = new String[newText.length]; + for (int i = 0; i < reversed.length; i++) + { + reversed[i] = newText[reversed.length - (i + 1)]; + } + if (reversed.equals(_text)) + return this; + _makePackets = true; + if (isInUse()) + { + ArrayList packets1_7 = new ArrayList(); + int[] destroy1_7 = new int[0]; + int[] destroy1_8 = new int[0]; + ArrayList packets1_8 = new ArrayList(); + if (_text.length != reversed.length) + { + _destroyPackets = true; + } + for (int textRow = 0; textRow < Math.max(_text.length, reversed.length); textRow++) + { + // You can safely assume that _entityIds here is containing _text.length amount as this code is inside isInUse + if (textRow >= _text.length) + { + // Add entity id and send spawn packets + // You add a entity id because the new hologram needs + Entry entry = new HashMap.SimpleEntry(UtilEnt.getNewEntityId(), UtilEnt.getNewEntityId()); + _entityIds.add(entry); + packets1_7.addAll(Arrays.asList(makeSpawnPackets1_7(textRow, entry.getKey(), entry.getValue(), + reversed[textRow]))); + packets1_8.addAll(Arrays.asList(makeSpawnPackets1_8(textRow, entry.getKey(), reversed[textRow]))); + } + else if (textRow >= reversed.length) + { + // Remove entity id and send destroy packets + Entry entry = _entityIds.remove(reversed.length); + destroy1_7 = Arrays.copyOf(destroy1_7, destroy1_7.length + 2); + destroy1_7[destroy1_7.length - 2] = entry.getKey(); + destroy1_7[destroy1_7.length - 1] = entry.getValue(); + destroy1_8 = Arrays.copyOf(destroy1_8, destroy1_8.length + 1); + destroy1_8[destroy1_8.length - 1] = entry.getKey(); + } + else if (!reversed[textRow].equals(_text[textRow])) + { + // Send update metadata packets + Entry entry = _entityIds.get(textRow); + PacketPlayOutEntityMetadata metadata1_7 = new PacketPlayOutEntityMetadata(); + metadata1_7.a = entry.getValue(); + DataWatcher watcher1_7 = new DataWatcher(null); + watcher1_7.a(0, (byte) 0); + watcher1_7.a(1, (short) 300); + watcher1_7.a(10, reversed[textRow]); + watcher1_7.a(11, (byte) 1); + watcher1_7.a(12, -1700000); + metadata1_7.b = watcher1_7.c(); + packets1_7.add(metadata1_7); + + PacketPlayOutEntityMetadata metadata1_8 = new PacketPlayOutEntityMetadata(); + metadata1_8.a = entry.getKey(); + DataWatcher watcher1_8 = new DataWatcher(null); + watcher1_8.a(0, (byte) 0); + watcher1_8.a(2, reversed[textRow]); + watcher1_8.a(3, (byte) 1); + metadata1_8.b = watcher1_8.c(); + packets1_8.add(metadata1_8); + } + } + if (destroy1_7.length > 0) + { + packets1_7.add(new PacketPlayOutEntityDestroy(destroy1_7)); + } + if (destroy1_8.length > 0) + { + packets1_8.add(new PacketPlayOutEntityDestroy(destroy1_8)); + } + for (Player player : _playersTracking) + { + for (Packet packet : UtilPlayer.is1_8(player) ? packets1_8 : packets1_7) + { + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); + } + } + } + _text = reversed; + return this; + } + + /** + * Tells the hologram to use the wither skull instead of armorstand for 1.8 clients + */ + public Hologram setUsesWitherSkull() + { + _isWitherSkull = true; + return this; + } + + /** + * Set the distance the hologram is viewable from. Default is 70 + */ + public Hologram setViewDistance(int newDistance) + { + this._viewDistance = newDistance; + return setLocation(getLocation()); + } + + /** + * Start the hologram + */ + public Hologram start() + { + if (!isInUse()) + { + _playersTracking.addAll(getNearbyPlayers()); + for (Player player : _playersTracking) + { + for (Packet packet : getSpawnPackets(player)) + { + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); + } + } + _lastMovement = new Vector(); + _runnable = new BukkitRunnable() + { + + @Override + public void run() + { + if (!Bukkit.getWorlds().contains(getLocation().getWorld())) + { + stop(); + } + else + { + ArrayList canSee = getNearbyPlayers(); + Iterator itel = _playersTracking.iterator(); + while (itel.hasNext()) + { + Player player = itel.next(); + if (!canSee.contains(player)) + { + itel.remove(); + if (player.getWorld() == getLocation().getWorld()) + { + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(getDestroyPacket(player)); + } + } + } + for (Player player : canSee) + { + if (!_playersTracking.contains(player)) + { + _playersTracking.add(player); + for (Packet packet : getSpawnPackets(player)) + { + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); + } + } + } + } + } + + }; + _runnable.runTaskTimer(Bukkit.getPluginManager().getPlugin("Arcade"), 0, 0); + // TODO Remove that plugin call + } + return this; + } + + /** + * Stop the hologram + */ + public Hologram stop() + { + if (isInUse()) + { + _runnable.cancel(); + _runnable = null; + for (Player player : _playersTracking) + { + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(getDestroyPacket(player)); + } + _playersTracking.clear(); + _lastMovement = null; + } + return this; + } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/hologram/HorseHologram.java b/Plugins/Mineplex.Core/src/mineplex/core/hologram/HorseHologram.java deleted file mode 100644 index 3f268e531..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/hologram/HorseHologram.java +++ /dev/null @@ -1,132 +0,0 @@ -package mineplex.core.hologram; - -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_7_R4.CraftWorld; -import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer; -import org.bukkit.entity.Player; -import net.minecraft.server.v1_7_R4.EntityFireball; -import net.minecraft.server.v1_7_R4.EntityHorse; -import net.minecraft.server.v1_7_R4.EntitySmallFireball; -import net.minecraft.server.v1_7_R4.Packet; -import net.minecraft.server.v1_7_R4.PacketPlayOutAttachEntity; -import net.minecraft.server.v1_7_R4.PacketPlayOutEntityDestroy; -import net.minecraft.server.v1_7_R4.PacketPlayOutSpawnEntity; -import net.minecraft.server.v1_7_R4.PacketPlayOutSpawnEntityLiving; -import net.minecraft.server.v1_7_R4.World; - -import mineplex.core.common.util.UtilServer; - -/** - * Created by Shaun on 8/29/2014. - */ -public class HorseHologram -{ - /** - * HorseHologram creates the required entities to spawn in a hologram. It is possible to send the packets for the entities to a player, - * but it is also possible to add the entities to the nmsWorld to keep them loaded into the server. - */ - - private Location _location; - private String _text; - - private World _nmsWorld; - private EntityFireball _fireball; - private EntityHorse _horse; - - public HorseHologram(Location location, String text) - { - _location = location; - _text = text; - - _nmsWorld = ((CraftWorld) location.getWorld()).getHandle(); - - // Create Entities - _fireball = new EntitySmallFireball(_nmsWorld); - _horse = new EntityHorse(_nmsWorld); - - // Location Data - _fireball.setLocation(_location.getX(), _location.getY() + 55.25, _location.getZ(), 0, 0); - _horse.setLocation(_location.getX(), _location.getY() + 55.25, _location.getZ(), 0, 0); - _horse.setAge(-1700000); - _horse.setCustomName(_text); - _horse.setCustomNameVisible(true); - } - - public void sendToPlayer(Player player) - { - Packet fireballSpawn = getFireballSpawnPacket(); - Packet horseSpawn = getHorseSpawnPacket(); - Packet attachPacket = getAttachEntityPacket(); - - sendPacket(player, fireballSpawn); - sendPacket(player, horseSpawn); - sendPacket(player, attachPacket); - } - - public void removeForPlayer(Player player) - { - Packet horseDestroy = getHorseDestroyPacket(); - Packet fireballDestroy = getFireballDestroyPacket(); - - sendPacket(player, horseDestroy); - sendPacket(player, fireballDestroy); - } - - public void spawnWithPackets() - { - for (Player player : UtilServer.getPlayers()) - { - sendToPlayer(player); - } - } - - public void removeWithPackets() - { - for (Player player : UtilServer.getPlayers()) - { - removeForPlayer(player); - } - } - - public void setText(String text) - { - _text = text; - _horse.setCustomName(_text); - } - - public String getText() - { - return _text; - } - - private Packet getHorseSpawnPacket() - { - return new PacketPlayOutSpawnEntityLiving(_horse); - } - - private Packet getFireballSpawnPacket() - { - return new PacketPlayOutSpawnEntity(_fireball, 64); - } - - private Packet getAttachEntityPacket() - { - return new PacketPlayOutAttachEntity(0, _horse, _fireball); - } - - private Packet getHorseDestroyPacket() - { - return new PacketPlayOutEntityDestroy(_horse.getId()); - } - - private Packet getFireballDestroyPacket() - { - return new PacketPlayOutEntityDestroy(_fireball.getId()); - } - - private void sendPacket(Player player, Packet packet) - { - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); - } - -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/ChestOpenAnimation.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/ChestOpenAnimation.java index c8bb075c0..79687f732 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/ChestOpenAnimation.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/ChestOpenAnimation.java @@ -1,5 +1,7 @@ package mineplex.core.treasure.animation; +import java.util.ArrayList; + import org.bukkit.Location; import org.bukkit.Sound; import org.bukkit.block.Block; @@ -8,8 +10,8 @@ import org.bukkit.craftbukkit.v1_7_R4.util.CraftMagicNumbers; import org.bukkit.entity.Item; import org.bukkit.entity.Player; import org.bukkit.util.Vector; -import net.minecraft.server.v1_7_R4.PacketPlayOutBlockAction; +import net.minecraft.server.v1_7_R4.PacketPlayOutBlockAction; import mineplex.core.common.util.UtilServer; import mineplex.core.hologram.Hologram; import mineplex.core.reward.RewardData; @@ -21,51 +23,57 @@ import mineplex.core.treasure.Treasure; */ public class ChestOpenAnimation extends Animation { - private ChestData _chestData; - private RewardData _rewardData; + private ChestData _chestData; + private RewardData _rewardData; - private Item _itemEntity; - private Hologram _hologram; + private Item _itemEntity; + private ArrayList _holograms = new ArrayList(); - public ChestOpenAnimation(Treasure treasure, ChestData chestData, RewardData rewardData) - { - super(treasure); - _chestData = chestData; - _rewardData = rewardData; + public ChestOpenAnimation(Treasure treasure, ChestData chestData, RewardData rewardData) + { + super(treasure); + _chestData = chestData; + _rewardData = rewardData; - // Send chest open packet - Block block = chestData.getBlock(); - PacketPlayOutBlockAction packet = new PacketPlayOutBlockAction(block.getX(), block.getY(), block.getZ(), CraftMagicNumbers.getBlock(block), 1, 1); - for (Player other : UtilServer.getPlayers()) - { - ((CraftPlayer) other).getHandle().playerConnection.sendPacket(packet); - other.playSound(block.getLocation(), Sound.CHEST_OPEN, 1, 1); - } - } + // Send chest open packet + Block block = chestData.getBlock(); + PacketPlayOutBlockAction packet = new PacketPlayOutBlockAction(block.getX(), block.getY(), block.getZ(), + CraftMagicNumbers.getBlock(block), 1, 1); + for (Player other : UtilServer.getPlayers()) + { + ((CraftPlayer) other).getHandle().playerConnection.sendPacket(packet); + other.playSound(block.getLocation(), Sound.CHEST_OPEN, 1, 1); + } + } - @Override - protected void tick() - { - if (getTicks() == 5) - { - Location location = _chestData.getBlock().getLocation().add(0.5, 0.8, 0.5); - _itemEntity = location.getWorld().dropItem(location, _rewardData.getDisplayItem()); - _itemEntity.setVelocity(new Vector(0, 0, 0)); - _itemEntity.setPickupDelay(Integer.MAX_VALUE); - } - else if (getTicks() == 15) - { - _hologram = new Hologram(_chestData.getBlock().getLocation().add(0.5, 1.1, 0.5), _rewardData.getFriendlyName()); - _hologram.sendToPlayers(_chestData.getBlock().getLocation().getWorld().getPlayers().toArray(new Player[0])); - } - } + @Override + protected void tick() + { + if (getTicks() == 5) + { + Location location = _chestData.getBlock().getLocation().add(0.5, 0.8, 0.5); + _itemEntity = location.getWorld().dropItem(location, _rewardData.getDisplayItem()); + _itemEntity.setVelocity(new Vector(0, 0, 0)); + _itemEntity.setPickupDelay(Integer.MAX_VALUE); + } + else if (getTicks() == 15) + { + Hologram hologram = new Hologram(_chestData.getBlock().getLocation().add(0.5, 1.1, 0.5), + _rewardData.getFriendlyName()); + hologram.start(); + _holograms.add(hologram); + } + } - public void onFinish() - { - if (_hologram != null) - { - _hologram.removeForPlayers(_chestData.getBlock().getLocation().getWorld().getPlayers().toArray(new Player[0])); - _itemEntity.remove(); - } - } + public void onFinish() + { + if (!_holograms.isEmpty()) + { + for (Hologram hologram : _holograms) + { + hologram.stop(); + } + _itemEntity.remove(); + } + } } From 3c76fde190f6ded160365250ce5ed5629b8597f4 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Wed, 26 Nov 2014 09:51:08 +1300 Subject: [PATCH 02/29] Ignore wither skulls for CustomTagFix --- .../src/mineplex/core/CustomTagFix.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/CustomTagFix.java b/Plugins/Mineplex.Core/src/mineplex/core/CustomTagFix.java index 3dd26bc38..db9db0530 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/CustomTagFix.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/CustomTagFix.java @@ -1,6 +1,7 @@ package mineplex.core; import java.lang.reflect.Field; +import java.util.HashSet; import java.util.Iterator; import java.util.List; @@ -22,6 +23,7 @@ import net.minecraft.server.v1_7_R4.Packet; import net.minecraft.server.v1_7_R4.PacketPlayOutAttachEntity; import net.minecraft.server.v1_7_R4.PacketPlayOutEntityDestroy; import net.minecraft.server.v1_7_R4.PacketPlayOutEntityMetadata; +import net.minecraft.server.v1_7_R4.PacketPlayOutSpawnEntity; import net.minecraft.server.v1_7_R4.PacketPlayOutSpawnEntityLiving; import net.minecraft.server.v1_7_R4.WatchableObject; @@ -38,6 +40,7 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler private NautHashMap> _entityNameMap = new NautHashMap>(); private NautHashMap> _entityVehicleMap = new NautHashMap>(); private NautHashMap _loggedIn = new NautHashMap(); + private HashSet _ignoreSkulls = new HashSet(); private Field _destroyId; @@ -149,7 +152,7 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler { PacketPlayOutEntityMetadata metaPacket = (PacketPlayOutEntityMetadata)packet; - if (!_entityMap.get(owner).containsKey(metaPacket.a) && metaPacket.a != 777777) + if (!_entityMap.get(owner).containsKey(metaPacket.a) && metaPacket.a != 777777 && !_ignoreSkulls.contains(metaPacket.a)) { String entityName = ""; boolean nameShowing = false; @@ -198,6 +201,14 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler { exception.printStackTrace(); } + } + else if (packet instanceof PacketPlayOutSpawnEntity) + { + PacketPlayOutSpawnEntity spawnPacket = (PacketPlayOutSpawnEntity) packet; + if (spawnPacket.j == 66 && spawnPacket.a != 777777) + { + _ignoreSkulls.add(spawnPacket.a); + } } /* else if (packet instanceof PacketPlayOutAttachEntity) From 03075fecae4b5412dfc28a75350ffe8705f91c08 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Wed, 26 Nov 2014 10:28:37 +1300 Subject: [PATCH 03/29] You have your HologramManager presented in a light most fair. Should be worth noting I didn't test it thoroughly --- .../src/mineplex/core/hologram/Hologram.java | 67 ++++----------- .../core/hologram/HologramManager.java | 84 +++++++++++++++++++ .../src/mineplex/core/treasure/Treasure.java | 13 +-- .../core/treasure/TreasureManager.java | 7 +- .../animation/ChestOpenAnimation.java | 32 ++++--- .../Mineplex.Hub/src/mineplex/hub/Hub.java | 3 +- .../src/mineplex/hub/HubManager.java | 5 +- .../src/nautilus/game/arcade/Arcade.java | 4 +- .../nautilus/game/arcade/ArcadeManager.java | 11 ++- 9 files changed, 142 insertions(+), 84 deletions(-) create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/hologram/HologramManager.java diff --git a/Plugins/Mineplex.Core/src/mineplex/core/hologram/Hologram.java b/Plugins/Mineplex.Core/src/mineplex/core/hologram/Hologram.java index 584b6d461..2931bccb3 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/hologram/Hologram.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/hologram/Hologram.java @@ -17,11 +17,9 @@ import net.minecraft.server.v1_7_R4.PacketPlayOutRelEntityMove; import net.minecraft.server.v1_7_R4.PacketPlayOutSpawnEntity; import net.minecraft.server.v1_7_R4.PacketPlayOutSpawnEntityLiving; -import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer; import org.bukkit.entity.Player; -import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.util.Vector; import mineplex.core.common.util.UtilEnt; @@ -56,13 +54,14 @@ public class Hologram private Packet[] _packets1_8; private HashSet _playersInList = new HashSet(); private ArrayList _playersTracking = new ArrayList(); - private BukkitRunnable _runnable; private HologramTarget _target = HologramTarget.BLACKLIST; private String[] _text = new String[0]; private int _viewDistance = 70; + private HologramManager _hologramManager; - public Hologram(Location location, String... text) + public Hologram(HologramManager hologramManager, Location location, String... text) { + _hologramManager = hologramManager; _location = location.clone(); setText(text); } @@ -100,7 +99,7 @@ public class Hologram return _playersInList.contains(player); } - private Packet getDestroyPacket(Player player) + protected Packet getDestroyPacket(Player player) { if (_destroyPackets) { @@ -129,7 +128,7 @@ public class Hologram return _location.clone(); } - private ArrayList getNearbyPlayers() + protected ArrayList getNearbyPlayers() { ArrayList nearbyPlayers = new ArrayList(); for (Player player : getLocation().getWorld().getPlayers()) @@ -142,7 +141,7 @@ public class Hologram return nearbyPlayers; } - private Packet[] getSpawnPackets(Player player) + protected Packet[] getSpawnPackets(Player player) { if (_makePackets) { @@ -179,7 +178,7 @@ public class Hologram */ public boolean isInUse() { - return _runnable != null; + return _lastMovement != null; } /** @@ -575,6 +574,11 @@ public class Hologram return setLocation(getLocation()); } + protected ArrayList getPlayersTracking() + { + return _playersTracking; + } + /** * Start the hologram */ @@ -582,6 +586,7 @@ public class Hologram { if (!isInUse()) { + _hologramManager.addHologram(this); _playersTracking.addAll(getNearbyPlayers()); for (Player player : _playersTracking) { @@ -591,49 +596,6 @@ public class Hologram } } _lastMovement = new Vector(); - _runnable = new BukkitRunnable() - { - - @Override - public void run() - { - if (!Bukkit.getWorlds().contains(getLocation().getWorld())) - { - stop(); - } - else - { - ArrayList canSee = getNearbyPlayers(); - Iterator itel = _playersTracking.iterator(); - while (itel.hasNext()) - { - Player player = itel.next(); - if (!canSee.contains(player)) - { - itel.remove(); - if (player.getWorld() == getLocation().getWorld()) - { - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(getDestroyPacket(player)); - } - } - } - for (Player player : canSee) - { - if (!_playersTracking.contains(player)) - { - _playersTracking.add(player); - for (Packet packet : getSpawnPackets(player)) - { - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); - } - } - } - } - } - - }; - _runnable.runTaskTimer(Bukkit.getPluginManager().getPlugin("Arcade"), 0, 0); - // TODO Remove that plugin call } return this; } @@ -645,8 +607,7 @@ public class Hologram { if (isInUse()) { - _runnable.cancel(); - _runnable = null; + _hologramManager.removeHologram(this); for (Player player : _playersTracking) { ((CraftPlayer) player).getHandle().playerConnection.sendPacket(getDestroyPacket(player)); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/hologram/HologramManager.java b/Plugins/Mineplex.Core/src/mineplex/core/hologram/HologramManager.java new file mode 100644 index 000000000..a24869c17 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/hologram/HologramManager.java @@ -0,0 +1,84 @@ +package mineplex.core.hologram; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; +import net.minecraft.server.v1_7_R4.Packet; + +import org.bukkit.Bukkit; +import org.bukkit.World; +import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.plugin.java.JavaPlugin; + +public class HologramManager implements Listener +{ + private ArrayList _activeHolograms = new ArrayList(); + + public HologramManager(JavaPlugin arcadeManager) + { + Bukkit.getPluginManager().registerEvents(this, arcadeManager); + } + + void addHologram(Hologram hologram) + { + _activeHolograms.add(hologram); + } + + void removeHologram(Hologram hologram) + { + _activeHolograms.remove(hologram); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void onTick(UpdateEvent event) + { + if (event.getType() != UpdateType.TICK || _activeHolograms.isEmpty()) + return; + List worlds = Bukkit.getWorlds(); + Iterator itel = _activeHolograms.iterator(); + while (itel.hasNext()) + { + Hologram hologram = itel.next(); + if (!worlds.contains(hologram.getLocation().getWorld())) + { + itel.remove(); + hologram.stop(); + } + else + { + ArrayList canSee = hologram.getNearbyPlayers(); + Iterator itel2 = hologram.getPlayersTracking().iterator(); + while (itel.hasNext()) + { + Player player = itel2.next(); + if (!canSee.contains(player)) + { + itel2.remove(); + if (player.getWorld() == hologram.getLocation().getWorld()) + { + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(hologram.getDestroyPacket(player)); + } + } + } + for (Player player : canSee) + { + if (!hologram.getPlayersTracking().contains(player)) + { + hologram.getPlayersTracking().add(player); + for (Packet packet : hologram.getSpawnPackets(player)) + { + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); + } + } + } + } + } + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/Treasure.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/Treasure.java index 4dc18489f..46099fb23 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/treasure/Treasure.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/Treasure.java @@ -14,12 +14,13 @@ import org.bukkit.block.BlockFace; import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_7_R4.util.CraftMagicNumbers; import org.bukkit.entity.Player; -import net.minecraft.server.v1_7_R4.PacketPlayOutBlockAction; +import net.minecraft.server.v1_7_R4.PacketPlayOutBlockAction; import mineplex.core.blockrestore.BlockRestore; import mineplex.core.common.util.C; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilParticle; +import mineplex.core.hologram.HologramManager; import mineplex.core.reward.Reward; import mineplex.core.reward.RewardData; import mineplex.core.reward.RewardRarity; @@ -56,15 +57,16 @@ public class Treasure private LinkedList _animations; private TreasureStyle _style; + private HologramManager _hologramManager; - public Treasure(Player player, Reward[] rewards, BlockRestore blockRestore) + public Treasure(Player player, Reward[] rewards, BlockRestore blockRestore, HologramManager hologramManager) { - this(player, new Random(), rewards); + this(player, new Random(), rewards, hologramManager); _blockRestore = blockRestore; } - public Treasure(Player player, Random seed, Reward[] rewards) + public Treasure(Player player, Random seed, Reward[] rewards, HologramManager hologramManager) { _player = player; _random = seed; @@ -73,6 +75,7 @@ public class Treasure _centerBlock = player.getLocation().getBlock().getRelative(BlockFace.DOWN); _animations = new LinkedList(); + _hologramManager = hologramManager; // _animations.add(new ParticleAnimation(this)); @@ -288,7 +291,7 @@ public class Treasure RewardData rewardData = data.getReward().giveReward("Treasure", _player); data.setOpened(true); - ChestOpenAnimation chestOpenTask = new ChestOpenAnimation(this, data, rewardData); + ChestOpenAnimation chestOpenTask = new ChestOpenAnimation(this, data, rewardData, _hologramManager); _animations.add(chestOpenTask); // Extra effects based off the rarity of the treasure diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/TreasureManager.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/TreasureManager.java index dc6e8fe24..958deba89 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/treasure/TreasureManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/TreasureManager.java @@ -36,6 +36,7 @@ import mineplex.core.common.util.UtilPlayer; import mineplex.core.donation.DonationManager; import mineplex.core.event.StackerEvent; import mineplex.core.gadget.event.GadgetBlockEvent; +import mineplex.core.hologram.HologramManager; import mineplex.core.inventory.InventoryManager; import mineplex.core.pet.PetManager; import mineplex.core.reward.Reward; @@ -55,14 +56,16 @@ public class TreasureManager extends MiniPlugin private RewardManager _rewardManager; private InventoryManager _inventoryManager; private BlockRestore _blockRestore; + private HologramManager _hologramManager; - public TreasureManager(JavaPlugin plugin, DonationManager donationManager, InventoryManager inventoryManager, PetManager petManager, BlockRestore blockRestore) + public TreasureManager(JavaPlugin plugin, DonationManager donationManager, InventoryManager inventoryManager, PetManager petManager, BlockRestore blockRestore, HologramManager hologramManager) { super("Treasure", plugin); _playerTreasureMap = new NautHashMap(); _inventoryManager = inventoryManager; _blockRestore = blockRestore; + _hologramManager = hologramManager; _rewardManager = new RewardManager(donationManager, inventoryManager, petManager, 250, 500, 750, 1500, @@ -108,7 +111,7 @@ public class TreasureManager extends MiniPlugin Bukkit.broadcastMessage(F.main("Treasure", F.name(player.getName()) + " is opening a " + C.cGreen + "Treasure Chest")); Reward[] rewards = _rewardManager.getRewards(player, true); - Treasure treasure = new Treasure(player, rewards, _blockRestore); + Treasure treasure = new Treasure(player, rewards, _blockRestore, _hologramManager); _playerTreasureMap.put(player, treasure); Location teleportLocation = treasure.getPlayerBlock().getLocation().add(0.5, 0, 0.5); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/ChestOpenAnimation.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/ChestOpenAnimation.java index 79687f732..cdc2e0b10 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/ChestOpenAnimation.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/ChestOpenAnimation.java @@ -1,6 +1,12 @@ package mineplex.core.treasure.animation; -import java.util.ArrayList; +import mineplex.core.common.util.UtilServer; +import mineplex.core.hologram.Hologram; +import mineplex.core.hologram.HologramManager; +import mineplex.core.reward.RewardData; +import mineplex.core.treasure.ChestData; +import mineplex.core.treasure.Treasure; +import net.minecraft.server.v1_7_R4.PacketPlayOutBlockAction; import org.bukkit.Location; import org.bukkit.Sound; @@ -11,13 +17,6 @@ import org.bukkit.entity.Item; import org.bukkit.entity.Player; import org.bukkit.util.Vector; -import net.minecraft.server.v1_7_R4.PacketPlayOutBlockAction; -import mineplex.core.common.util.UtilServer; -import mineplex.core.hologram.Hologram; -import mineplex.core.reward.RewardData; -import mineplex.core.treasure.ChestData; -import mineplex.core.treasure.Treasure; - /** * Created by Shaun on 8/29/2014. */ @@ -25,11 +24,12 @@ public class ChestOpenAnimation extends Animation { private ChestData _chestData; private RewardData _rewardData; + private HologramManager _hologramManager; private Item _itemEntity; - private ArrayList _holograms = new ArrayList(); + private Hologram _hologram; - public ChestOpenAnimation(Treasure treasure, ChestData chestData, RewardData rewardData) + public ChestOpenAnimation(Treasure treasure, ChestData chestData, RewardData rewardData, HologramManager hologramManager) { super(treasure); _chestData = chestData; @@ -58,21 +58,17 @@ public class ChestOpenAnimation extends Animation } else if (getTicks() == 15) { - Hologram hologram = new Hologram(_chestData.getBlock().getLocation().add(0.5, 1.1, 0.5), + _hologram = new Hologram(_hologramManager, _chestData.getBlock().getLocation().add(0.5, 1.1, 0.5), _rewardData.getFriendlyName()); - hologram.start(); - _holograms.add(hologram); + _hologram.start(); } } public void onFinish() { - if (!_holograms.isEmpty()) + if (_hologram != null) { - for (Hologram hologram : _holograms) - { - hologram.stop(); - } + _hologram.stop(); _itemEntity.remove(); } } diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java b/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java index 0bac44d21..11586d5e9 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java @@ -17,6 +17,7 @@ import mineplex.core.donation.DonationManager; import mineplex.core.elo.EloManager; import mineplex.core.energy.Energy; import mineplex.core.friend.FriendManager; +import mineplex.core.hologram.HologramManager; import mineplex.core.itemstack.ItemStackFactory; import mineplex.core.logger.Logger; import mineplex.core.memory.MemoryFix; @@ -103,7 +104,7 @@ public class Hub extends JavaPlugin implements IRelation DisguiseManager disguiseManager = new DisguiseManager(this, packetHandler); StatsManager statsManager = new StatsManager(this); AchievementManager achievementManager = new AchievementManager(statsManager, clientManager, donationManager); - HubManager hubManager = new HubManager(this, new BlockRestore(this), clientManager, donationManager, new ConditionManager(this), disguiseManager, new TaskManager(this, webServerAddress), portal, partyManager, preferenceManager, petManager, pollManager, statsManager, achievementManager); + HubManager hubManager = new HubManager(this, new BlockRestore(this), clientManager, donationManager, new ConditionManager(this), disguiseManager, new TaskManager(this, webServerAddress), portal, partyManager, preferenceManager, petManager, pollManager, statsManager, achievementManager, new HologramManager(this)); QueueManager queueManager = new QueueManager(this, clientManager, donationManager, new EloManager(this), partyManager); diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java index ce6b1c604..5d2fc3925 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java @@ -65,6 +65,7 @@ import mineplex.core.donation.DonationManager; import mineplex.core.gadget.GadgetManager; import mineplex.core.gadget.event.GadgetActivateEvent; import mineplex.core.gadget.event.GadgetCollideEntityEvent; +import mineplex.core.hologram.HologramManager; import mineplex.core.inventory.InventoryManager; import mineplex.core.itemstack.ItemStackFactory; import mineplex.core.mount.MountManager; @@ -144,7 +145,7 @@ public class HubManager extends MiniClientPlugin //Admin private boolean _gadgetsEnabled = true; - public HubManager(JavaPlugin plugin, BlockRestore blockRestore, CoreClientManager clientManager, DonationManager donationManager, ConditionManager conditionManager, DisguiseManager disguiseManager, TaskManager taskManager, Portal portal, PartyManager partyManager, PreferencesManager preferences, PetManager petManager, PollManager pollManager, StatsManager statsManager, AchievementManager achievementManager) + public HubManager(JavaPlugin plugin, BlockRestore blockRestore, CoreClientManager clientManager, DonationManager donationManager, ConditionManager conditionManager, DisguiseManager disguiseManager, TaskManager taskManager, Portal portal, PartyManager partyManager, PreferencesManager preferences, PetManager petManager, PollManager pollManager, StatsManager statsManager, AchievementManager achievementManager, HologramManager hologramManager) { super("Hub Manager", plugin); @@ -173,7 +174,7 @@ public class HubManager extends MiniClientPlugin _inventoryManager = new InventoryManager(plugin); new RankBenefitsGiver9000(plugin, clientManager, _inventoryManager); _gadgetManager = new GadgetManager(_plugin, clientManager, donationManager, _inventoryManager, _mountManager, petManager, preferences, disguiseManager, blockRestore, new ProjectileManager(plugin)); - _treasureManager = new TreasureManager(_plugin, donationManager, _inventoryManager, petManager, _blockRestore); + _treasureManager = new TreasureManager(_plugin, donationManager, _inventoryManager, petManager, _blockRestore, hologramManager); new CosmeticManager(_plugin, clientManager, donationManager, _inventoryManager, _gadgetManager, _mountManager, petManager, false, _treasureManager); _partyManager = partyManager; diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java index 38b42644c..92a5c5e06 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java @@ -21,6 +21,7 @@ import mineplex.core.disguise.DisguiseManager; import mineplex.core.donation.DonationManager; import mineplex.core.friend.FriendManager; import mineplex.core.gadget.GadgetManager; +import mineplex.core.hologram.HologramManager; import mineplex.core.inventory.InventoryManager; import mineplex.core.itemstack.ItemStackFactory; import mineplex.core.logger.Logger; @@ -109,6 +110,7 @@ public class Arcade extends JavaPlugin BlockRestore blockRestore = new BlockRestore(this); ProjectileManager projectileManager = new ProjectileManager(this); + HologramManager hologramManager = new HologramManager(this); //Inventory InventoryManager inventoryManager = new InventoryManager(this); @@ -119,7 +121,7 @@ public class Arcade extends JavaPlugin cosmeticManager.setInterfaceSlot(7); //Arcade Manager - _gameManager = new ArcadeManager(this, serverStatusManager, ReadServerConfig(), _clientManager, _donationManager, _damageManager, disguiseManager, creature, teleport, new Blood(this), antistack, portal, preferenceManager, inventoryManager, packetHandler, cosmeticManager, projectileManager, petManager, webServerAddress); + _gameManager = new ArcadeManager(this, serverStatusManager, ReadServerConfig(), _clientManager, _donationManager, _damageManager, disguiseManager, creature, teleport, new Blood(this), antistack, portal, preferenceManager, inventoryManager, packetHandler, cosmeticManager, projectileManager, petManager, hologramManager, webServerAddress); new MemoryFix(this); new CustomTagFix(this, packetHandler); diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java index 14930eb8e..9f4a52c42 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java @@ -55,6 +55,7 @@ import mineplex.core.donation.DonationManager; import mineplex.core.elo.EloManager; import mineplex.core.energy.Energy; import mineplex.core.explosion.Explosion; +import mineplex.core.hologram.HologramManager; import mineplex.core.inventory.InventoryManager; import mineplex.core.itemstack.ItemStackFactory; import mineplex.core.movement.Movement; @@ -147,7 +148,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation private InventoryManager _inventoryManager; private CosmeticManager _cosmeticManager; private final IdleManager _idleManager; - + private HologramManager _hologramManager; private AchievementManager _achievementManager; private StatsManager _statsManager; private ClassManager _classManager; @@ -175,7 +176,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation CoreClientManager clientManager, DonationManager donationManager, DamageManager damageManager, DisguiseManager disguiseManager, Creature creature, Teleport teleport, Blood blood, AntiStack antistack, Portal portal, PreferencesManager preferences, InventoryManager inventoryManager, PacketHandler packetHandler, - CosmeticManager cosmeticManager, ProjectileManager projectileManager, PetManager petManager, String webAddress) + CosmeticManager cosmeticManager, ProjectileManager projectileManager, PetManager petManager, HologramManager hologramManager, String webAddress) { super("Game Manager", plugin); @@ -248,6 +249,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation new GameSpectatorManager(this); _gameWorldManager = new GameWorldManager(this); new MiscManager(this); + _hologramManager = hologramManager; _idleManager = new IdleManager(this); //new HalloweenManager(this); @@ -344,6 +346,11 @@ public class ArcadeManager extends MiniPlugin implements IRelation { return _disguiseManager; } + + public HologramManager getHologramManager() + { + return _hologramManager; + } public DamageManager GetDamage() { From 3ad3fb21ffc0410e2d5c85e973a411d12cb848bd Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Wed, 26 Nov 2014 21:35:45 +1300 Subject: [PATCH 04/29] Fix up mistakes in the previous modifications --- .../src/mineplex/core/hologram/HologramManager.java | 2 +- .../mineplex/core/treasure/animation/ChestOpenAnimation.java | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/hologram/HologramManager.java b/Plugins/Mineplex.Core/src/mineplex/core/hologram/HologramManager.java index a24869c17..5fc38db29 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/hologram/HologramManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/hologram/HologramManager.java @@ -55,7 +55,7 @@ public class HologramManager implements Listener { ArrayList canSee = hologram.getNearbyPlayers(); Iterator itel2 = hologram.getPlayersTracking().iterator(); - while (itel.hasNext()) + while (itel2.hasNext()) { Player player = itel2.next(); if (!canSee.contains(player)) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/ChestOpenAnimation.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/ChestOpenAnimation.java index cdc2e0b10..ccd8f5bca 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/ChestOpenAnimation.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/ChestOpenAnimation.java @@ -32,6 +32,7 @@ public class ChestOpenAnimation extends Animation public ChestOpenAnimation(Treasure treasure, ChestData chestData, RewardData rewardData, HologramManager hologramManager) { super(treasure); + _hologramManager = hologramManager; _chestData = chestData; _rewardData = rewardData; From 30e2de6f22c9329c0e932211d562b8eb2d1a0a42 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Thu, 27 Nov 2014 00:50:02 +1300 Subject: [PATCH 05/29] Remove the 'Made by Shaun' --- Plugins/Mineplex.Core/src/mineplex/core/hologram/Hologram.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/hologram/Hologram.java b/Plugins/Mineplex.Core/src/mineplex/core/hologram/Hologram.java index 2931bccb3..4f2750d45 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/hologram/Hologram.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/hologram/Hologram.java @@ -25,9 +25,6 @@ import org.bukkit.util.Vector; import mineplex.core.common.util.UtilEnt; import mineplex.core.common.util.UtilPlayer; -/** - * Created by shaun on 2014-09-09. - */ public class Hologram { From 84b56708f9955485d8e44d5dbe85a76b4b6e3c42 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Tue, 25 Nov 2014 14:20:18 +1300 Subject: [PATCH 06/29] Added new class ItemBuilder for chain building ItemStacks --- .../mineplex/core/itemstack/ItemBuilder.java | 360 ++++++++++++++++++ 1 file changed, 360 insertions(+) create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/itemstack/ItemBuilder.java diff --git a/Plugins/Mineplex.Core/src/mineplex/core/itemstack/ItemBuilder.java b/Plugins/Mineplex.Core/src/mineplex/core/itemstack/ItemBuilder.java new file mode 100644 index 000000000..b785bfae8 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/itemstack/ItemBuilder.java @@ -0,0 +1,360 @@ +package mineplex.core.itemstack; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Color; +import org.bukkit.Material; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.inventory.meta.LeatherArmorMeta; +import org.bukkit.potion.Potion; + +public class ItemBuilder +{ + + private static ArrayList split(String string, int maxLength) + { + String[] split = string.split(" "); + string = ""; + ArrayList newString = new ArrayList(); + for (int i = 0; i < split.length; i++) + { + string += (string.length() == 0 ? "" : " ") + split[i]; + if (ChatColor.stripColor(string).length() > maxLength) + { + newString + .add((newString.size() > 0 ? ChatColor.getLastColors(newString.get(newString.size() - 1)) : "") + string); + string = ""; + } + } + if (string.length() > 0) + newString.add((newString.size() > 0 ? ChatColor.getLastColors(newString.get(newString.size() - 1)) : "") + string); + return newString; + } + + private int _amount; + private Color _color; + private short _data; + private final HashMap _enchants = new HashMap(); + private final List _lore = new ArrayList(); + private Material _mat; + // private Potion potion; + private String _title = null; + private boolean _unbreakable; + + public ItemBuilder(ItemStack item) + { + this(item.getType(), item.getDurability()); + this._amount = item.getAmount(); + this._enchants.putAll(item.getEnchantments()); + if (item.getType() == Material.POTION) + { + // setPotion(Potion.fromItemStack(item)); + } + if (item.hasItemMeta()) + { + ItemMeta meta = item.getItemMeta(); + if (meta.hasDisplayName()) + { + this._title = meta.getDisplayName(); + } + if (meta.hasLore()) + { + this._lore.addAll(meta.getLore()); + } + if (meta instanceof LeatherArmorMeta) + { + this.setColor(((LeatherArmorMeta) meta).getColor()); + } + this._unbreakable = meta.spigot().isUnbreakable(); + } + } + + public ItemBuilder(Material mat) + { + this(mat, 1); + } + + public ItemBuilder(Material mat, int amount) + { + this(mat, amount, (short) 0); + } + + public ItemBuilder(Material mat, int amount, short data) + { + this._mat = mat; + this._amount = amount; + this._data = data; + } + + public ItemBuilder(Material mat, short data) + { + this(mat, 1, data); + } + + public ItemBuilder addEnchantment(Enchantment enchant, int level) + { + if (_enchants.containsKey(enchant)) + { + _enchants.remove(enchant); + } + _enchants.put(enchant, level); + return this; + } + + public ItemBuilder addLore(String... lores) + { + for (String lore : lores) + { + this._lore.add(ChatColor.GRAY + lore); + } + return this; + } + + public ItemBuilder addLore(String lore, int maxLength) + { + this._lore.addAll(split(lore, maxLength)); + return this; + } + + public ItemBuilder addLores(List lores) + { + this._lore.addAll(lores); + return this; + } + + public ItemBuilder addLores(List lores, int maxLength) + { + for (String lore : lores) + { + addLore(lore, maxLength); + } + return this; + } + + public ItemBuilder addLores(String[] description, int maxLength) + { + return addLores(Arrays.asList(description), maxLength); + } + + public ItemStack build() + { + Material mat = this._mat; + if (mat == null) + { + mat = Material.AIR; + Bukkit.getLogger().warning("Null material!"); + } + else if (mat == Material.AIR) + { + Bukkit.getLogger().warning("Air material!"); + } + ItemStack item = new ItemStack(mat, this._amount, this._data); + ItemMeta meta = item.getItemMeta(); + if (meta != null) + { + if (this._title != null) + { + meta.setDisplayName(this._title); + } + if (!this._lore.isEmpty()) + { + meta.setLore(this._lore); + } + if (meta instanceof LeatherArmorMeta) + { + ((LeatherArmorMeta) meta).setColor(this._color); + } + meta.spigot().setUnbreakable(isUnbreakable()); + item.setItemMeta(meta); + } + item.addUnsafeEnchantments(this._enchants); + // if (this.potion != null) { + // this.potion.apply(item); + // } + return item; + } + + @Override + public ItemBuilder clone() + { + ItemBuilder newBuilder = new ItemBuilder(this._mat); + + newBuilder.setTitle(this._title); + for (String lore : this._lore) + { + newBuilder.addLore(lore); + } + for (Map.Entry entry : this._enchants.entrySet()) + { + newBuilder.addEnchantment(entry.getKey(), entry.getValue()); + } + newBuilder.setColor(this._color); + // newBuilder.potion = this.potion; + + return newBuilder; + } + + public HashMap getAllEnchantments() + { + return this._enchants; + } + + public Color getColor() + { + return this._color; + } + + public short getData() + { + return this._data; + } + + public int getEnchantmentLevel(Enchantment enchant) + { + return this._enchants.get(enchant); + } + + public List getLore() + { + return this._lore; + } + + public String getTitle() + { + return this._title; + } + + public Material getType() + { + return this._mat; + } + + public boolean hasEnchantment(Enchantment enchant) + { + return this._enchants.containsKey(enchant); + } + + public boolean isItem(ItemStack item) + { + ItemMeta meta = item.getItemMeta(); + if (item.getType() != this.getType()) + { + return false; + } + if (!meta.hasDisplayName() && this.getTitle() != null) + { + return false; + } + if (!meta.getDisplayName().equals(this.getTitle())) + { + return false; + } + if (!meta.hasLore() && !this.getLore().isEmpty()) + { + return false; + } + if (meta.hasLore()) + { + for (String lore : meta.getLore()) + { + if (!this.getLore().contains(lore)) + { + return false; + } + } + } + for (Enchantment enchant : item.getEnchantments().keySet()) + { + if (!this.hasEnchantment(enchant)) + { + return false; + } + } + return true; + } + + public boolean isUnbreakable() + { + return this._unbreakable; + } + + public ItemBuilder setAmount(int amount) + { + this._amount = amount; + return this; + } + + public ItemBuilder setColor(Color color) + { + if (!this._mat.name().contains("LEATHER_")) + { + throw new IllegalArgumentException("Can only dye leather armor!"); + } + this._color = color; + return this; + } + + public void setData(short newData) + { + this._data = newData; + } + + public ItemBuilder setPotion(Potion potion) + { + if (this._mat != Material.POTION) + { + this._mat = Material.POTION; + } + // this.potion = potion; + return this; + } + + public ItemBuilder setRawTitle(String title) + { + this._title = title; + return this; + } + + public ItemBuilder setTitle(String title) + { + this._title = (title == null ? null + : (title.length() > 2 && ChatColor.getLastColors(title.substring(0, 2)).length() == 0 ? ChatColor.WHITE : "")) + + title; + return this; + } + + public ItemBuilder setTitle(String title, int maxLength) + { + if (title != null && ChatColor.stripColor(title).length() > maxLength) + { + ArrayList lores = split(title, maxLength); + for (int i = 1; i < lores.size(); i++) + { + this._lore.add(lores.get(i)); + } + title = lores.get(0); + } + setTitle(title); + return this; + } + + public ItemBuilder setType(Material mat) + { + this._mat = mat; + return this; + } + + public ItemBuilder setUnbreakable(boolean setUnbreakable) + { + this._unbreakable = setUnbreakable;return this; + } + +} \ No newline at end of file From aa0659828a9f76e37608db56a56057f48afdae10 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Tue, 25 Nov 2014 21:57:51 +1300 Subject: [PATCH 07/29] Register game SearchAndDestroy --- .../Nautilus.Game.Arcade/src/nautilus/game/arcade/GameType.java | 1 + 1 file changed, 1 insertion(+) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/GameType.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/GameType.java index a975248fb..a2623a36d 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/GameType.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/GameType.java @@ -34,6 +34,7 @@ public enum GameType Quiver("One in the Quiver"), QuiverTeams("One in the Quiver Teams"), Runner("Runner"), + SearchAndDestroy("Search and Destroy"), Sheep("Sheep Quest"), Smash("Super Smash Mobs"), SmashTeams("Super Smash Mobs Teams", "Super Smash Mobs"), From 60fd6b01cc3a19e3ff50d5e573989b2cc16cf0c9 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Tue, 25 Nov 2014 22:00:33 +1300 Subject: [PATCH 08/29] Add Search and Destroy code --- .../searchanddestroy/SearchAndDestroy.java | 213 +++++++++++++ .../game/games/searchanddestroy/TeamBomb.java | 298 ++++++++++++++++++ 2 files changed, 511 insertions(+) create mode 100644 Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/SearchAndDestroy.java create mode 100644 Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/TeamBomb.java diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/SearchAndDestroy.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/SearchAndDestroy.java new file mode 100644 index 000000000..037e79cba --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/SearchAndDestroy.java @@ -0,0 +1,213 @@ +package nautilus.game.arcade.game.games.searchanddestroy; + +import java.util.ArrayList; +import java.util.Iterator; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Effect; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.entity.Player; +import org.bukkit.entity.TNTPrimed; +import org.bukkit.event.EventHandler; +import org.bukkit.event.block.Action; +import org.bukkit.event.entity.EntityDamageEvent.DamageCause; +import org.bukkit.event.player.PlayerInteractEntityEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.inventory.ItemStack; + +import mineplex.core.common.util.C; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; +import nautilus.game.arcade.ArcadeManager; +import nautilus.game.arcade.GameType; +import nautilus.game.arcade.events.GameStateChangeEvent; +import nautilus.game.arcade.game.GameTeam; +import nautilus.game.arcade.game.TeamGame; +import nautilus.game.arcade.game.games.searchanddestroy.kits.*; +import nautilus.game.arcade.kit.Kit; + +public class SearchAndDestroy extends TeamGame +{ + + private ArrayList _teamBombs = new ArrayList(); + + public ArrayList getBombs() + { + return _teamBombs; + } + + @EventHandler + public void onBombTick(UpdateEvent event) + { + if (event.getType() == UpdateType.SEC && this.GetState() == GameState.Live) + { + Iterator itel = _teamBombs.iterator(); + while (itel.hasNext()) + { + TeamBomb bomb = itel.next(); + bomb.checkArmers(); + bomb.tickBomb(); + GameTeam bombOwner = bomb.getTeam(); + if (bomb.isArmed()) + { + int timeLeft = bomb.getTimeUntilExplode(); + if (((timeLeft <= 30 && timeLeft % 10 == 0) || (timeLeft <= 5)) && timeLeft >= 1) + { + Bukkit.broadcastMessage(C.cGold + "" + timeLeft + " seconds left until " + bombOwner.GetColor() + + bombOwner.GetName() + "'s" + C.cGold + " bomb goes off!"); + for (Player player : bombOwner.GetPlayers(true)) + { + player.playSound(player.getLocation(), Sound.BLAZE_DEATH, 30, 3); + } + } + else if (timeLeft == 0) + { + // It exploded + itel.remove(); + bomb.getBlockLocation().getWorld().playSound(bomb.getBlockLocation(), Sound.EXPLODE, 1000, 0); + bomb.getBlockLocation().getWorld().playEffect(bomb.getBomb().getLocation(), Effect.EXPLOSION_HUGE, 0); + bomb.removeBomb(); + for (Player player : this.GetPlayers(true)) + { + GameTeam pTeam = GetTeam(player); + if (bombOwner == pTeam) + { + Manager.GetDamage().NewDamageEvent(player, null, null, DamageCause.CUSTOM, 999, false, true, + true, "Bomb", "Bomb Exploded"); + } + } + // TODO The code below may need changing + if (_teamBombs.size() == 1) + { + GameTeam winning = _teamBombs.get(0).getTeam(); + Bukkit.broadcastMessage(bombOwner.GetColor() + bombOwner.GetName() + "'s" + ChatColor.RESET + + ChatColor.GOLD + " bomb exploded! " + winning.GetColor() + winning.GetName() + + ChatColor.RESET + ChatColor.GOLD + " wins!"); + } + else + { + Bukkit.broadcastMessage(bombOwner.GetColor() + bombOwner.GetName() + " was defeated!"); + } + } + if (timeLeft > 0) + { + // TODO Refresh bomb + } + } + } + } + } + + @EventHandler(ignoreCancelled = true) + public void onInteractBombBlock(PlayerInteractEvent event) + { + Player p = event.getPlayer(); + if (event.getAction() == Action.RIGHT_CLICK_BLOCK) + { + if (event.getItem() != null && event.getItem().getType() == Material.BLAZE_POWDER) + { + for (TeamBomb bomb : this._teamBombs) + { + if (!bomb.isArmed() && bomb.getBlockLocation().getBlock().equals(event.getClickedBlock())) + { + GameTeam team = GetTeam(p); + if (team == bomb.getTeam()) + { + p.sendMessage(ChatColor.RED + "That's your bomb!"); + } + else + { + bomb.onInteractWithFuse(p); + } + break; + } + } + } + } + } + + @EventHandler(ignoreCancelled = true) + public void onInteractBombEntity(PlayerInteractEntityEvent event) + { + Player p = event.getPlayer(); + if (event.getRightClicked() instanceof TNTPrimed) + { + ItemStack item = p.getItemInHand(); + if (item != null && item.getType() == Material.BLAZE_POWDER) + { + for (TeamBomb bomb : this._teamBombs) + { + if (bomb.isArmed() && bomb.getBomb().equals(event.getRightClicked())) + { + GameTeam team = GetTeam(p); + if (team != bomb.getTeam()) + { + p.sendMessage(ChatColor.RED + "That's not your bomb!"); + } + else if (team != null) + { + bomb.onInteractWithFuse(p); + } + break; + } + } + } + } + } + + @EventHandler + public void onGameEnd(GameStateChangeEvent event) + { + if (event.GetState() == GameState.End && !_teamBombs.isEmpty()) + { + for (TeamBomb bomb : _teamBombs) + { + if (bomb.getTeam().IsTeamAlive()) + { + bomb.restoreBomb(); + } + else + { + bomb.removeBomb(); + } + } + _teamBombs.clear(); + } + } + + public SearchAndDestroy(ArcadeManager manager) + { + super(manager, GameType.SearchAndDestroy, new Kit[] + { + new KitBow(manager) + }, new String[] + { + "A test game of", "Search and Destroy" + }); + + InventoryClick = true; + WorldTimeSet = -1; + WorldBoundaryKill = false; + HungerSet = 20; + RepairWeapons = false; + AnnounceJoinQuit = false; + DisableKillCommand = false; + AllowParticles = false; + } + + @Override + public void ParseData() + { + for (GameTeam team : GetTeamList()) + { + for (Location loc : WorldData.GetDataLocs(team.GetColor() == ChatColor.AQUA ? "BLUE" : team.GetColor().name())) + { + _teamBombs.add(new TeamBomb(this.Manager, this, team, loc)); + } + } + } + +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/TeamBomb.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/TeamBomb.java new file mode 100644 index 000000000..3db1048b6 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/TeamBomb.java @@ -0,0 +1,298 @@ +package nautilus.game.arcade.game.games.searchanddestroy; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.Random; + +import mineplex.core.common.util.C; +import nautilus.game.arcade.ArcadeManager; +import nautilus.game.arcade.game.GameTeam; +import nautilus.game.arcade.game.TeamGame; +import net.minecraft.server.v1_7_R4.EntityTNTPrimed; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Effect; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.craftbukkit.v1_7_R4.CraftWorld; +import org.bukkit.entity.Player; +import org.bukkit.entity.TNTPrimed; +import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; + +class TeamBomb implements Comparable +{ + private class ArmInfo + { + private ArrayList _armers = new ArrayList(); + private long _firstArmed = System.currentTimeMillis(); + private long _lastInteract; + private int _timeToArmBomb = 11; + private GameTeam _owningTeam; + + public ArmInfo(GameTeam team) + { + this._owningTeam = team; + } + + public void addArmer(Player gamer) + { + if (!_armers.contains(gamer)) + { + _timeToArmBomb -= 1; + _armers.add(gamer); + /* ItemStack item = gamer.getPlayer().getItemInHand(); + if (item != null && item.getType() != Material.AIR) + { + int timeToTake = 0; + if (item.containsEnchantment(Enchants.BOMB_SPEED) + && item.getEnchantmentLevel(Enchants.BOMB_SPEED) > timeToTake) + timeToTake = item.getEnchantmentLevel(Enchants.BOMB_SPEED); + if (item.containsEnchantment(Enchants.BOMB_ARMING) + && item.getEnchantmentLevel(Enchants.BOMB_ARMING) > timeToTake && _bombEntity == null) + timeToTake = item.getEnchantmentLevel(Enchants.BOMB_ARMING); + if (item.containsEnchantment(Enchants.BOMB_DEFUSING) + && item.getEnchantmentLevel(Enchants.BOMB_DEFUSING) > timeToTake && _bombEntity != null) + timeToTake = item.getEnchantmentLevel(Enchants.BOMB_DEFUSING); + _timeToArmBomb -= timeToTake; + }*/ + } + } + + public float getPercentageOfBombDone() + { + float done = (float) (System.currentTimeMillis() - _firstArmed) / (1000 * _timeToArmBomb); + return Math.min(done, 1); + } + + public boolean isFused() + { + return isValid() && _firstArmed + (1000 * _timeToArmBomb) < System.currentTimeMillis(); + } + + public boolean isValid() + { + return _owningTeam.IsTeamAlive() && _lastInteract + 1000 > System.currentTimeMillis(); + } + + } + + private Location _bombLocation; + private TNTPrimed _bombEntity; + private int _timeUntilExplode; + private long _timeBombArmed; + private long _lastHiss; + private GameTeam _owningTeam; + private ArrayList _armers = new ArrayList(); + private SearchAndDestroy _game; + + public int getTimeUntilExplode() + { + return _timeUntilExplode; + } + + public boolean isArmed() + { + return _bombEntity != null; + } + + public TNTPrimed getBomb() + { + return _bombEntity; + } + + public GameTeam getTeam() + { + return _owningTeam; + } + + public Location getBlockLocation() + { + return _bombLocation; + } + + public TeamBomb(ArcadeManager manager, SearchAndDestroy game, GameTeam owningTeam, Location bombLocation) + { + this._game = game; + this._owningTeam = owningTeam; + this._bombLocation = bombLocation; + } + + public void checkArmers() + { + Iterator armers = _armers.iterator(); + while (armers.hasNext()) + { + ArmInfo info = armers.next(); + if (!info.isValid()) + { + armers.remove(); + } + } + } + + public void onInteractWithFuse(Player player) + { + GameTeam hisTeam = _game.GetTeam(player); + if (hisTeam != null) + { + if (_owningTeam == hisTeam) + { + if (_bombEntity == null) + { + player.sendMessage(C.cRed + "You cannot arm your bomb"); + } + else + { + onInteract(hisTeam, player); + } + } + else + { + if (_bombEntity != null) + { + player.sendMessage(C.cRed + "You cannot disarm their bomb"); + } + else + { + onInteract(hisTeam, player); + } + } + } + } + + private void onInteract(GameTeam gTeam, Player p) + { + if (_lastHiss + 500 <= System.currentTimeMillis()) + { + p.getWorld().playSound(p.getLocation(), Sound.FIZZ, 1, 0); + _lastHiss = System.currentTimeMillis(); + } + p.getWorld() + .spigot() + .playEffect( + _bombEntity == null ? _bombLocation.clone().add(0.5, 1.1, 0.5) : _bombEntity.getLocation().add(0, 1, 0), + Effect.LARGE_SMOKE, 0, 0, 0.1F, 0.05F, 0.1F, 0, 3, 30); + ArmInfo info = null; + for (ArmInfo arm : _armers) + { + if (arm._owningTeam == gTeam) + { + info = arm; + break; + } + } + if (info != null && !info.isValid()) + { + _armers.remove(info); + info = null; + } + if (info == null) + { + info = new ArmInfo(gTeam); + _armers.add(info); + } + info.addArmer(p); + info._lastInteract = System.currentTimeMillis(); + if (info.isFused()) + { + activateBomb(gTeam); + return; + } + } + + private void activateBomb(GameTeam gameTeam) + { + if (!isArmed()) + { + _timeBombArmed = System.currentTimeMillis(); + getBlockLocation().getBlock().setType(Material.AIR); + _game.CreatureAllowOverride = true; + EntityTNTPrimed entity = new EntityTNTPrimed(((CraftWorld) getBlockLocation().getWorld()).getHandle()); + _game.CreatureAllowOverride = false; + double x = getBlockLocation().getX() + 0.5; + double y = getBlockLocation().getY() + 1; + double z = getBlockLocation().getZ() + 0.5; + entity.setPosition(x, y, z); + entity.motY = 0.20000000298023224D; + entity.fuseTicks = 120000; + entity.lastX = x; + entity.lastY = y; + entity.lastZ = z; + ((CraftWorld) getBlockLocation().getWorld()).getHandle().addEntity(entity, SpawnReason.CUSTOM); + _bombEntity = (TNTPrimed) entity.getBukkitEntity(); + _timeUntilExplode = 60; + Bukkit.broadcastMessage(ChatColor.GOLD + "" + ChatColor.MAGIC + "ab " + gameTeam.GetColor() + gameTeam.GetName() + + ChatColor.RESET + ChatColor.GOLD + " just armed " + getTeam().GetColor() + getTeam().GetName() + "'s" + + ChatColor.RESET + ChatColor.GOLD + " bomb! " + ChatColor.MAGIC + "ab"); + for (Player player : Bukkit.getOnlinePlayers()) + { + GameTeam hisTeam = _game.GetTeam(player); + if (hisTeam == getTeam()) + player.playSound(player.getLocation(), Sound.BLAZE_DEATH, 10000, 0); + else + player.playSound(player.getLocation(), Sound.AMBIENCE_THUNDER, 1, 0.8F + new Random().nextFloat() * 0.2F); + } + Collections.sort(_game.getBombs()); + } + else + { + Bukkit.broadcastMessage(_owningTeam.GetColor() + _owningTeam.GetName() + ChatColor.RESET + ChatColor.GOLD + + " have just defused their bomb!"); + restoreBomb(); + } + _armers.clear(); + } + + @Override + public int compareTo(TeamBomb o) + { + if (o._timeBombArmed == _timeBombArmed) + { + return 0; + } + if (o._timeBombArmed < _timeBombArmed) + { + return 1; + } + return -1; + } + + /** + * Sets the bomb block to tnt, updates the hologram and removes the bomb entity + */ + public void restoreBomb() + { + _armers.clear(); + getBlockLocation().getBlock().setType(Material.TNT); + if (getBomb() != null) + { + this.getBomb().remove(); + } + } + + /** + * Sets the bomb block to air and removes the hologram and bomb entity + */ + public void removeBomb() + { + _armers.clear(); + getBlockLocation().getBlock().setType(Material.AIR); + if (getBomb() != null) + { + this.getBomb().remove(); + } + } + + public void tickBomb() + { + if (_bombEntity != null) + { + _timeUntilExplode--; + _bombEntity.getWorld().playSound(_bombEntity.getLocation(), Sound.CREEPER_DEATH, 1.85F, 1.2F); + } + } + +} From 5bf185e5885f38a7f59ede7d11ab9da223aaf59f Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Tue, 25 Nov 2014 22:00:49 +1300 Subject: [PATCH 09/29] Register Search and Destroy in GameFactory --- .../src/nautilus/game/arcade/GameFactory.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/GameFactory.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/GameFactory.java index 1a12c7afb..ea33ee5b9 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/GameFactory.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/GameFactory.java @@ -3,6 +3,7 @@ package nautilus.game.arcade; import java.util.HashMap; import nautilus.game.arcade.game.games.sneakyassassins.*; + import org.bukkit.ChatColor; import nautilus.game.arcade.game.Game; @@ -31,6 +32,7 @@ import nautilus.game.arcade.game.games.mineware.MineWare; import nautilus.game.arcade.game.games.quiver.Quiver; import nautilus.game.arcade.game.games.quiver.QuiverTeams; import nautilus.game.arcade.game.games.runner.Runner; +import nautilus.game.arcade.game.games.searchanddestroy.SearchAndDestroy; import nautilus.game.arcade.game.games.sheep.SheepGame; import nautilus.game.arcade.game.games.smash.SuperSmash; import nautilus.game.arcade.game.games.smash.SuperSmashDominate; @@ -87,6 +89,7 @@ public class GameFactory else if (gameType == GameType.Quiver) return new Quiver(_manager); else if (gameType == GameType.QuiverTeams) return new QuiverTeams(_manager); else if (gameType == GameType.Runner) return new Runner(_manager); + else if (gameType == GameType.SearchAndDestroy) return new SearchAndDestroy(_manager); else if (gameType == GameType.SnowFight) return new SnowFight(_manager); else if (gameType == GameType.Sheep) return new SheepGame(_manager); else if (gameType == GameType.Smash) return new SuperSmash(_manager); From 3ae27ccc55641ccde1022ba5302f2bc42d67a332 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Tue, 25 Nov 2014 23:36:05 +1300 Subject: [PATCH 10/29] Store PacketHandler so that games can use it --- .../src/nautilus/game/arcade/ArcadeManager.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java index 55550b9f8..788d3f30c 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java @@ -154,7 +154,8 @@ public class ArcadeManager extends MiniPlugin implements IRelation private ClassCombatShop _classShop; private TaskManager _taskManager; private ArcadeRepository _arcadeRepository; - + private PacketHandler _packetHandler; + private EloManager _eloManager; // Observers @@ -214,6 +215,8 @@ public class ArcadeManager extends MiniPlugin implements IRelation _fire = new Fire(plugin, _conditionManager, damageManager); _projectileManager = projectileManager; + + _packetHandler = packetHandler; _statsManager = new StatsManager(plugin); _taskManager = new TaskManager(plugin, webAddress); @@ -325,6 +328,11 @@ public class ArcadeManager extends MiniPlugin implements IRelation { return _creature; } + + public PacketHandler getPacketHandler() + { + return _packetHandler; + } public CosmeticManager getCosmeticManager() { From c76ad50136c99e1483a312ff4176ecc58c5ae7ba Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Tue, 25 Nov 2014 23:36:53 +1300 Subject: [PATCH 11/29] Allow removal of packet handler --- .../src/mineplex/core/packethandler/PacketHandler.java | 10 ++++++++++ .../mineplex/core/packethandler/PacketVerifier.java | 5 +++++ 2 files changed, 15 insertions(+) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/packethandler/PacketHandler.java b/Plugins/Mineplex.Core/src/mineplex/core/packethandler/PacketHandler.java index 5ee3adc78..f7a47752d 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/packethandler/PacketHandler.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/packethandler/PacketHandler.java @@ -51,4 +51,14 @@ public class PacketHandler extends MiniPlugin verifier.addPacketHandler(packetHandler); } } + + public void removePacketHandler(IPacketHandler packetHandler) + { + _packetHandlers.remove(packetHandler); + + for (PacketVerifier verifier : _playerVerifierMap.values()) + { + verifier.removePacketHandler(packetHandler); + } + } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/packethandler/PacketVerifier.java b/Plugins/Mineplex.Core/src/mineplex/core/packethandler/PacketVerifier.java index f318ac341..3985cb70d 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/packethandler/PacketVerifier.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/packethandler/PacketVerifier.java @@ -88,4 +88,9 @@ public class PacketVerifier implements IPacketVerifier { _packetHandlers.add(packetHandler); } + + public void removePacketHandler(IPacketHandler packetHandler) + { + _packetHandlers.remove(packetHandler); + } } From b68c95c6a2e60c7f64efd0e6598fe35afd362a2a Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Tue, 25 Nov 2014 23:57:22 +1300 Subject: [PATCH 12/29] Finish up adding bombs and turn this into a working game. Add demo kit Bow --- .../searchanddestroy/SearchAndDestroy.java | 108 +++++++++++++++++- .../game/games/searchanddestroy/TeamBomb.java | 31 ++++- .../games/searchanddestroy/kits/KitBow.java | 37 ++++++ 3 files changed, 170 insertions(+), 6 deletions(-) create mode 100644 Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/kits/KitBow.java diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/SearchAndDestroy.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/SearchAndDestroy.java index 037e79cba..f20c86356 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/SearchAndDestroy.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/SearchAndDestroy.java @@ -1,6 +1,8 @@ package nautilus.game.arcade.game.games.searchanddestroy; +import java.lang.reflect.Field; import java.util.ArrayList; +import java.util.HashSet; import java.util.Iterator; import org.bukkit.Bukkit; @@ -9,6 +11,7 @@ import org.bukkit.Effect; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Sound; +import org.bukkit.craftbukkit.v1_7_R4.CraftWorld; import org.bukkit.entity.Player; import org.bukkit.entity.TNTPrimed; import org.bukkit.event.EventHandler; @@ -19,6 +22,8 @@ import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.ItemStack; import mineplex.core.common.util.C; +import mineplex.core.packethandler.IPacketHandler; +import mineplex.core.packethandler.PacketInfo; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import nautilus.game.arcade.ArcadeManager; @@ -28,11 +33,56 @@ import nautilus.game.arcade.game.GameTeam; import nautilus.game.arcade.game.TeamGame; import nautilus.game.arcade.game.games.searchanddestroy.kits.*; import nautilus.game.arcade.kit.Kit; +import net.minecraft.server.v1_7_R4.EntityPlayer; +import net.minecraft.server.v1_7_R4.EntityTrackerEntry; +import net.minecraft.server.v1_7_R4.Packet; +import net.minecraft.server.v1_7_R4.PacketPlayOutEntityDestroy; +import net.minecraft.server.v1_7_R4.PacketPlayOutSpawnEntity; + +; public class SearchAndDestroy extends TeamGame { private ArrayList _teamBombs = new ArrayList(); + private IPacketHandler _teamBombPackets = new IPacketHandler() + { + + @Override + public void handle(PacketInfo packetInfo) + { + try + { + Packet packet = packetInfo.getPacket(); + if (packet instanceof PacketPlayOutEntityDestroy) + { + Field field = packet.getClass().getDeclaredField("a"); + field.setAccessible(true); + int[] ids = (int[]) field.get(packet); + for (TeamBomb bomb : _teamBombs) + { + int id = bomb.getBomb().getEntityId(); + for (int i = 0; i < ids.length; i++) + { + if (id == ids[i]) + { + ids[i] = bomb.getFakeBombId(); + } + } + } + } + else if (packet instanceof PacketPlayOutSpawnEntity) + { + + } + + } + catch (Exception ex) + { + ex.printStackTrace(); + } + } + }; public ArrayList getBombs() { @@ -94,7 +144,47 @@ public class SearchAndDestroy extends TeamGame } if (timeLeft > 0) { - // TODO Refresh bomb + int a = timeLeft % 2; + if (a == 1) + { + // TODO Refresh bomb + try + { + PacketPlayOutEntityDestroy destroyPacket = new PacketPlayOutEntityDestroy(bomb.getBomb() + .getEntityId()); + final EntityTrackerEntry entityTrackerEntry = (EntityTrackerEntry) ((CraftWorld) bomb.getBomb() + .getWorld()).getHandle().tracker.trackedEntities.get(bomb.getBomb().getEntityId()); + if (entityTrackerEntry != null) + { + HashSet trackedPlayers = (HashSet) entityTrackerEntry.trackedPlayers; + HashSet cloned = (HashSet) trackedPlayers.clone(); + for (final EntityPlayer p : cloned) + { + entityTrackerEntry.clear(p); + p.playerConnection.sendPacket(destroyPacket); + Bukkit.getScheduler().scheduleSyncDelayedTask(getArcadeManager().GetPlugin(), + new Runnable() + { + public void run() + { + try + { + entityTrackerEntry.updatePlayer(p); + } + catch (Exception ex) + { + ex.printStackTrace(); + } + } + }, 2); + } + } + } + catch (Exception ex) + { + ex.printStackTrace(); + } + } } } } @@ -158,6 +248,19 @@ public class SearchAndDestroy extends TeamGame } } + // @EventHandler TODO Waiting for client packets to be modifiable + public void onBombsPacketListener(GameStateChangeEvent event) + { + if (event.GetState() == GameState.Live) + { + this.getArcadeManager().getPacketHandler().addPacketHandler(_teamBombPackets); + } + else if (event.GetState() == GameState.End) + { + this.getArcadeManager().getPacketHandler().removePacketHandler(_teamBombPackets); + } + } + @EventHandler public void onGameEnd(GameStateChangeEvent event) { @@ -187,7 +290,7 @@ public class SearchAndDestroy extends TeamGame { "A test game of", "Search and Destroy" }); - + InventoryClick = true; WorldTimeSet = -1; WorldBoundaryKill = false; @@ -206,6 +309,7 @@ public class SearchAndDestroy extends TeamGame for (Location loc : WorldData.GetDataLocs(team.GetColor() == ChatColor.AQUA ? "BLUE" : team.GetColor().name())) { _teamBombs.add(new TeamBomb(this.Manager, this, team, loc)); + loc.getBlock().setType(Material.TNT); } } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/TeamBomb.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/TeamBomb.java index 3db1048b6..d381e0360 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/TeamBomb.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/TeamBomb.java @@ -1,5 +1,6 @@ package nautilus.game.arcade.game.games.searchanddestroy; +import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; @@ -87,6 +88,12 @@ class TeamBomb implements Comparable private GameTeam _owningTeam; private ArrayList _armers = new ArrayList(); private SearchAndDestroy _game; + private int entityId; + + public int getFakeBombId() + { + return entityId; + } public int getTimeUntilExplode() { @@ -118,6 +125,21 @@ class TeamBomb implements Comparable this._game = game; this._owningTeam = owningTeam; this._bombLocation = bombLocation; + try + { + // Grab the entity ID the fake disguise will use + Field field = Class.forName( + "net.minecraft.server." + Bukkit.getServer().getClass().getName().split("\\.")[3] + ".Entity") + .getDeclaredField("entityCount"); + field.setAccessible(true); + entityId = field.getInt(null); + // Set the entitycount plus one so we don't have the id being reused + field.set(null, entityId + 1); + } + catch (Exception ex) + { + ex.printStackTrace(); + } } public void checkArmers() @@ -172,8 +194,7 @@ class TeamBomb implements Comparable } p.getWorld() .spigot() - .playEffect( - _bombEntity == null ? _bombLocation.clone().add(0.5, 1.1, 0.5) : _bombEntity.getLocation().add(0, 1, 0), + .playEffect(_bombEntity == null ? _bombLocation.clone().add(0, 1.1, 0) : _bombEntity.getLocation().add(0, 1, 0), Effect.LARGE_SMOKE, 0, 0, 0.1F, 0.05F, 0.1F, 0, 3, 30); ArmInfo info = null; for (ArmInfo arm : _armers) @@ -212,9 +233,9 @@ class TeamBomb implements Comparable _game.CreatureAllowOverride = true; EntityTNTPrimed entity = new EntityTNTPrimed(((CraftWorld) getBlockLocation().getWorld()).getHandle()); _game.CreatureAllowOverride = false; - double x = getBlockLocation().getX() + 0.5; + double x = getBlockLocation().getX(); double y = getBlockLocation().getY() + 1; - double z = getBlockLocation().getZ() + 0.5; + double z = getBlockLocation().getZ(); entity.setPosition(x, y, z); entity.motY = 0.20000000298023224D; entity.fuseTicks = 120000; @@ -270,6 +291,7 @@ class TeamBomb implements Comparable if (getBomb() != null) { this.getBomb().remove(); + _bombEntity = null; } } @@ -283,6 +305,7 @@ class TeamBomb implements Comparable if (getBomb() != null) { this.getBomb().remove(); + _bombEntity = null; } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/kits/KitBow.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/kits/KitBow.java new file mode 100644 index 000000000..2823a446b --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/kits/KitBow.java @@ -0,0 +1,37 @@ +package nautilus.game.arcade.game.games.searchanddestroy.kits; + +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.PlayerInventory; + +import mineplex.core.itemstack.ItemBuilder; +import nautilus.game.arcade.ArcadeManager; +import nautilus.game.arcade.game.games.castlesiege.kits.KitHuman; +import nautilus.game.arcade.kit.KitAvailability; +import nautilus.game.arcade.kit.Perk; + +public class KitBow extends KitHuman +{ + + public KitBow(ArcadeManager manager) + { + super(manager, "Bow", KitAvailability.Free, new String[] + { + "A basic kit with a bow" + }, new Perk[0], EntityType.SKELETON, new ItemStack(Material.BOW)); + } + + @Override + public void GiveItems(Player player) + { + PlayerInventory inv = player.getInventory(); + inv.addItem(new ItemBuilder(Material.BLAZE_POWDER).setTitle(ChatColor.GOLD + "Fuse").build()); + inv.addItem(new ItemBuilder(Material.BOW).setUnbreakable(true).addEnchantment(Enchantment.ARROW_INFINITE, 1).build()); + inv.setItem(9, new ItemStack(Material.ARROW, 1)); + } + +} From 52411a188fa28f207ac05338561ed0dea3a69ed5 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Wed, 26 Nov 2014 04:14:27 +1300 Subject: [PATCH 13/29] Fixed entityId not using UtilEnt --- .../game/games/searchanddestroy/TeamBomb.java | 20 +++---------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/TeamBomb.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/TeamBomb.java index d381e0360..11dba5038 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/TeamBomb.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/TeamBomb.java @@ -7,6 +7,7 @@ import java.util.Iterator; import java.util.Random; import mineplex.core.common.util.C; +import mineplex.core.common.util.UtilEnt; import nautilus.game.arcade.ArcadeManager; import nautilus.game.arcade.game.GameTeam; import nautilus.game.arcade.game.TeamGame; @@ -88,11 +89,11 @@ class TeamBomb implements Comparable private GameTeam _owningTeam; private ArrayList _armers = new ArrayList(); private SearchAndDestroy _game; - private int entityId; + private final int _entityId = UtilEnt.getNewEntityId();; public int getFakeBombId() { - return entityId; + return _entityId; } public int getTimeUntilExplode() @@ -125,21 +126,6 @@ class TeamBomb implements Comparable this._game = game; this._owningTeam = owningTeam; this._bombLocation = bombLocation; - try - { - // Grab the entity ID the fake disguise will use - Field field = Class.forName( - "net.minecraft.server." + Bukkit.getServer().getClass().getName().split("\\.")[3] + ".Entity") - .getDeclaredField("entityCount"); - field.setAccessible(true); - entityId = field.getInt(null); - // Set the entitycount plus one so we don't have the id being reused - field.set(null, entityId + 1); - } - catch (Exception ex) - { - ex.printStackTrace(); - } } public void checkArmers() From b1608222600a2a11e40c65eacfb50d36798acf91 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Thu, 27 Nov 2014 03:17:59 +1300 Subject: [PATCH 14/29] Add follow entity to holograms --- .../src/mineplex/core/hologram/Hologram.java | 38 ++++++++++++++++--- .../core/hologram/HologramManager.java | 14 +++++++ 2 files changed, 46 insertions(+), 6 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/hologram/Hologram.java b/Plugins/Mineplex.Core/src/mineplex/core/hologram/Hologram.java index 4f2750d45..902e54245 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/hologram/Hologram.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/hologram/Hologram.java @@ -19,6 +19,7 @@ import net.minecraft.server.v1_7_R4.PacketPlayOutSpawnEntityLiving; import org.bukkit.Location; import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer; +import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.util.Vector; @@ -40,6 +41,8 @@ public class Hologram * 1.7 packets uses both EntityIDs while 1.8 uses only the first. */ private ArrayList> _entityIds = new ArrayList>(); + private Entity _followEntity; + private HologramManager _hologramManager; private boolean _isWitherSkull; /** * Keeps track of the holograms movements. This fixes offset that occasionally happens when moving a hologram around. @@ -54,7 +57,7 @@ public class Hologram private HologramTarget _target = HologramTarget.BLACKLIST; private String[] _text = new String[0]; private int _viewDistance = 70; - private HologramManager _hologramManager; + protected Vector relativeToEntity; public Hologram(HologramManager hologramManager, Location location, String... text) { @@ -106,6 +109,11 @@ public class Hologram return UtilPlayer.is1_8(player) ? _destroy1_8 : _destroy1_7; } + public Entity getEntityFollowing() + { + return _followEntity; + } + /** * Get who can see the hologram * @@ -138,6 +146,11 @@ public class Hologram return nearbyPlayers; } + protected ArrayList getPlayersTracking() + { + return _playersTracking; + } + protected Packet[] getSpawnPackets(Player player) { if (_makePackets) @@ -348,6 +361,19 @@ public class Hologram return this; } + /** + * If the entity moves, the hologram will update its position to appear relative to the movement. + * + * @Please note the hologram updates every tick. + */ + public Hologram setFollowEntity(Entity entityToFollow) + { + _followEntity = entityToFollow; + relativeToEntity = entityToFollow == null ? null : this._location.clone().subtract(entityToFollow.getLocation()) + .toVector(); + return this; + } + /** * Set who can see the hologram * @@ -368,6 +394,11 @@ public class Hologram _makePackets = true; Location oldLocation = getLocation(); _location = newLocation.clone(); + // TODO Needs to set the new relativeToEntity + if (getEntityFollowing() != null) + { + relativeToEntity = _location.clone().subtract(getEntityFollowing().getLocation()).toVector(); + } if (isInUse()) { ArrayList canSee = getNearbyPlayers(); @@ -571,11 +602,6 @@ public class Hologram return setLocation(getLocation()); } - protected ArrayList getPlayersTracking() - { - return _playersTracking; - } - /** * Start the hologram */ diff --git a/Plugins/Mineplex.Core/src/mineplex/core/hologram/HologramManager.java b/Plugins/Mineplex.Core/src/mineplex/core/hologram/HologramManager.java index 5fc38db29..60651d279 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/hologram/HologramManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/hologram/HologramManager.java @@ -11,11 +11,13 @@ import net.minecraft.server.v1_7_R4.Packet; import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.craftbukkit.v1_7_R4.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.plugin.java.JavaPlugin; +import org.bukkit.util.Vector; public class HologramManager implements Listener { @@ -53,6 +55,18 @@ public class HologramManager implements Listener } else { + if (hologram.getEntityFollowing() != null) + { + Entity following = hologram.getEntityFollowing(); + if (!hologram.relativeToEntity.equals(following.getLocation().subtract(hologram.getLocation()).toVector())) + { + // 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(); + 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 canSee = hologram.getNearbyPlayers(); Iterator itel2 = hologram.getPlayersTracking().iterator(); while (itel2.hasNext()) From 9350aeb89a0e26a27211328e3086bda59744f7e0 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Thu, 27 Nov 2014 03:18:52 +1300 Subject: [PATCH 15/29] Use holograms in game --- .../searchanddestroy/SearchAndDestroy.java | 56 +++++++++------ .../game/games/searchanddestroy/TeamBomb.java | 69 +++++++++++++++++-- 2 files changed, 97 insertions(+), 28 deletions(-) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/SearchAndDestroy.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/SearchAndDestroy.java index f20c86356..e1229dce4 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/SearchAndDestroy.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/SearchAndDestroy.java @@ -39,8 +39,6 @@ import net.minecraft.server.v1_7_R4.Packet; import net.minecraft.server.v1_7_R4.PacketPlayOutEntityDestroy; import net.minecraft.server.v1_7_R4.PacketPlayOutSpawnEntity; -; - public class SearchAndDestroy extends TeamGame { @@ -59,7 +57,7 @@ public class SearchAndDestroy extends TeamGame Field field = packet.getClass().getDeclaredField("a"); field.setAccessible(true); int[] ids = (int[]) field.get(packet); - for (TeamBomb bomb : _teamBombs) + for (TeamBomb bomb : getBombs()) { int id = bomb.getBomb().getEntityId(); for (int i = 0; i < ids.length; i++) @@ -92,9 +90,20 @@ public class SearchAndDestroy extends TeamGame @EventHandler public void onBombTick(UpdateEvent event) { - if (event.getType() == UpdateType.SEC && this.GetState() == GameState.Live) + if (this.GetState() != GameState.Live) { - Iterator itel = _teamBombs.iterator(); + return; + } + if (event.getType() == UpdateType.FASTEST) + { + for (TeamBomb bomb : getBombs()) + { + bomb.updateBombHologram(); + } + } + if (event.getType() == UpdateType.SEC) + { + Iterator itel = getBombs().iterator(); while (itel.hasNext()) { TeamBomb bomb = itel.next(); @@ -107,7 +116,7 @@ public class SearchAndDestroy extends TeamGame if (((timeLeft <= 30 && timeLeft % 10 == 0) || (timeLeft <= 5)) && timeLeft >= 1) { Bukkit.broadcastMessage(C.cGold + "" + timeLeft + " seconds left until " + bombOwner.GetColor() - + bombOwner.GetName() + "'s" + C.cGold + " bomb goes off!"); + + bombOwner.GetName() + " Team's" + C.cGold + " bomb goes off!"); for (Player player : bombOwner.GetPlayers(true)) { player.playSound(player.getLocation(), Sound.BLAZE_DEATH, 30, 3); @@ -130,24 +139,23 @@ public class SearchAndDestroy extends TeamGame } } // TODO The code below may need changing - if (_teamBombs.size() == 1) + if (getBombs().size() == 1) { - GameTeam winning = _teamBombs.get(0).getTeam(); - Bukkit.broadcastMessage(bombOwner.GetColor() + bombOwner.GetName() + "'s" + ChatColor.RESET + GameTeam winning = getBombs().get(0).getTeam(); + Bukkit.broadcastMessage(bombOwner.GetColor() + bombOwner.GetName() + " Team's" + ChatColor.RESET + ChatColor.GOLD + " bomb exploded! " + winning.GetColor() + winning.GetName() + ChatColor.RESET + ChatColor.GOLD + " wins!"); } else { - Bukkit.broadcastMessage(bombOwner.GetColor() + bombOwner.GetName() + " was defeated!"); + Bukkit.broadcastMessage(bombOwner.GetColor() + bombOwner.GetName() + " Team was defeated!"); } } if (timeLeft > 0) { - int a = timeLeft % 2; + int a = timeLeft % 3; if (a == 1) { - // TODO Refresh bomb try { PacketPlayOutEntityDestroy destroyPacket = new PacketPlayOutEntityDestroy(bomb.getBomb() @@ -199,7 +207,7 @@ public class SearchAndDestroy extends TeamGame { if (event.getItem() != null && event.getItem().getType() == Material.BLAZE_POWDER) { - for (TeamBomb bomb : this._teamBombs) + for (TeamBomb bomb : this.getBombs()) { if (!bomb.isArmed() && bomb.getBlockLocation().getBlock().equals(event.getClickedBlock())) { @@ -228,7 +236,7 @@ public class SearchAndDestroy extends TeamGame ItemStack item = p.getItemInHand(); if (item != null && item.getType() == Material.BLAZE_POWDER) { - for (TeamBomb bomb : this._teamBombs) + for (TeamBomb bomb : this.getBombs()) { if (bomb.isArmed() && bomb.getBomb().equals(event.getRightClicked())) { @@ -248,25 +256,31 @@ public class SearchAndDestroy extends TeamGame } } - // @EventHandler TODO Waiting for client packets to be modifiable + @EventHandler public void onBombsPacketListener(GameStateChangeEvent event) { if (event.GetState() == GameState.Live) { - this.getArcadeManager().getPacketHandler().addPacketHandler(_teamBombPackets); + for (TeamBomb bomb : getBombs()) + { + bomb.setupHologram(); + } + // this.getArcadeManager().getPacketHandler().addPacketHandler(_teamBombPackets); + // TODO Waiting for client packets to be modifiable } else if (event.GetState() == GameState.End) { - this.getArcadeManager().getPacketHandler().removePacketHandler(_teamBombPackets); + // this.getArcadeManager().getPacketHandler().removePacketHandler(_teamBombPackets); + // TODO Waiting for client packets to be modifiable } } @EventHandler public void onGameEnd(GameStateChangeEvent event) { - if (event.GetState() == GameState.End && !_teamBombs.isEmpty()) + if (event.GetState() == GameState.End && !getBombs().isEmpty()) { - for (TeamBomb bomb : _teamBombs) + for (TeamBomb bomb : getBombs()) { if (bomb.getTeam().IsTeamAlive()) { @@ -277,7 +291,7 @@ public class SearchAndDestroy extends TeamGame bomb.removeBomb(); } } - _teamBombs.clear(); + getBombs().clear(); } } @@ -308,7 +322,7 @@ public class SearchAndDestroy extends TeamGame { for (Location loc : WorldData.GetDataLocs(team.GetColor() == ChatColor.AQUA ? "BLUE" : team.GetColor().name())) { - _teamBombs.add(new TeamBomb(this.Manager, this, team, loc)); + getBombs().add(new TeamBomb(this.Manager, this, team, loc)); loc.getBlock().setType(Material.TNT); } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/TeamBomb.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/TeamBomb.java index 11dba5038..b0ab66038 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/TeamBomb.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/TeamBomb.java @@ -1,16 +1,14 @@ package nautilus.game.arcade.game.games.searchanddestroy; -import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.Random; - import mineplex.core.common.util.C; import mineplex.core.common.util.UtilEnt; +import mineplex.core.hologram.Hologram; import nautilus.game.arcade.ArcadeManager; import nautilus.game.arcade.game.GameTeam; -import nautilus.game.arcade.game.TeamGame; import net.minecraft.server.v1_7_R4.EntityTNTPrimed; import org.bukkit.Bukkit; @@ -31,7 +29,7 @@ class TeamBomb implements Comparable private ArrayList _armers = new ArrayList(); private long _firstArmed = System.currentTimeMillis(); private long _lastInteract; - private int _timeToArmBomb = 11; + private int _timeToArmBomb = 4; private GameTeam _owningTeam; public ArmInfo(GameTeam team) @@ -89,7 +87,8 @@ class TeamBomb implements Comparable private GameTeam _owningTeam; private ArrayList _armers = new ArrayList(); private SearchAndDestroy _game; - private final int _entityId = UtilEnt.getNewEntityId();; + private final int _entityId = UtilEnt.getNewEntityId(); + private Hologram _hologram; public int getFakeBombId() { @@ -232,7 +231,7 @@ class TeamBomb implements Comparable _bombEntity = (TNTPrimed) entity.getBukkitEntity(); _timeUntilExplode = 60; Bukkit.broadcastMessage(ChatColor.GOLD + "" + ChatColor.MAGIC + "ab " + gameTeam.GetColor() + gameTeam.GetName() - + ChatColor.RESET + ChatColor.GOLD + " just armed " + getTeam().GetColor() + getTeam().GetName() + "'s" + + ChatColor.RESET + ChatColor.GOLD + " just armed " + getTeam().GetColor() + getTeam().GetName() + " Team's" + ChatColor.RESET + ChatColor.GOLD + " bomb! " + ChatColor.MAGIC + "ab"); for (Player player : Bukkit.getOnlinePlayers()) { @@ -243,10 +242,14 @@ class TeamBomb implements Comparable player.playSound(player.getLocation(), Sound.AMBIENCE_THUNDER, 1, 0.8F + new Random().nextFloat() * 0.2F); } Collections.sort(_game.getBombs()); + _hologram.setText(getTeam().GetColor() + C.Bold + "Exploding in " + ChatColor.DARK_RED + ChatColor.BOLD + + getTimeUntilExplode()); + _hologram.setLocation(getBomb().getLocation().add(0, .53, 0)); + _hologram.setFollowEntity(getBomb()); } else { - Bukkit.broadcastMessage(_owningTeam.GetColor() + _owningTeam.GetName() + ChatColor.RESET + ChatColor.GOLD + Bukkit.broadcastMessage(_owningTeam.GetColor() + _owningTeam.GetName() + " Team" + ChatColor.RESET + ChatColor.GOLD + " have just defused their bomb!"); restoreBomb(); } @@ -274,6 +277,9 @@ class TeamBomb implements Comparable { _armers.clear(); getBlockLocation().getBlock().setType(Material.TNT); + _hologram.setFollowEntity(null); + _hologram.setLocation(getBlockLocation().clone().add(0, 1, 0)); + _hologram.setText(getTeam().GetColor() + C.Bold + getTeam().GetName() + " Team's Bomb"); if (getBomb() != null) { this.getBomb().remove(); @@ -281,12 +287,48 @@ class TeamBomb implements Comparable } } + public void updateBombHologram() + { + if (!_armers.isEmpty()) + { + Iterator itel = _armers.iterator(); + ArrayList text = new ArrayList(); + while (itel.hasNext()) + { + ArmInfo info = itel.next(); + if (!info.isValid()) + { + itel.remove(); + } + else + { + float percent = info.getPercentageOfBombDone(); + String message = ""; + for (double i = 0; i < 1; i += .1) + { + message += (percent >= i ? info._owningTeam.GetColor() : ChatColor.DARK_RED) + "█"; + } + text.add(message); + } + } + if (_armers.isEmpty()) + { + _hologram.setText(getTeam().GetColor() + C.Bold + getTeam().GetName() + " Team's Bomb"); + } + else + { + _hologram.setText(text.toArray(new String[0])); + } + } + } + /** * Sets the bomb block to air and removes the hologram and bomb entity */ public void removeBomb() { _armers.clear(); + _hologram.stop(); getBlockLocation().getBlock().setType(Material.AIR); if (getBomb() != null) { @@ -295,12 +337,25 @@ class TeamBomb implements Comparable } } + public void setupHologram() + { + _hologram = new Hologram(this._game.getArcadeManager().getHologramManager(), getBlockLocation().clone().add(0, 1, 0)) + .setUsesWitherSkull(); + _hologram.setText(getTeam().GetColor() + C.Bold + getTeam().GetName() + " Team's Bomb"); + _hologram.start(); + } + public void tickBomb() { if (_bombEntity != null) { _timeUntilExplode--; _bombEntity.getWorld().playSound(_bombEntity.getLocation(), Sound.CREEPER_DEATH, 1.85F, 1.2F); + if (this._armers.isEmpty()) + { + _hologram.setText(getTeam().GetColor() + C.Bold + "Exploding in " + ChatColor.DARK_RED + C.Bold + + this.getTimeUntilExplode()); + } } } From 34e320dfeebfa8ff70f933a37f517ffecffccb3d Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Thu, 27 Nov 2014 06:03:28 +1300 Subject: [PATCH 16/29] Create untested ItemLayouts for your customized layouts of your items. If you look to your right (ComplexItemLayout) you can define layouts such as "XX(de)XX(fg)XX" then call to replace all occurances of the letter d with this item. The (de) will then be set to that item. --- .../core/itemstack/ComplexItemLayout.java | 113 ++++++++++++++++++ .../mineplex/core/itemstack/ItemLayout.java | 60 ++++++++++ 2 files changed, 173 insertions(+) create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/itemstack/ComplexItemLayout.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/itemstack/ItemLayout.java diff --git a/Plugins/Mineplex.Core/src/mineplex/core/itemstack/ComplexItemLayout.java b/Plugins/Mineplex.Core/src/mineplex/core/itemstack/ComplexItemLayout.java new file mode 100644 index 000000000..7338d1e1f --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/itemstack/ComplexItemLayout.java @@ -0,0 +1,113 @@ +package mineplex.core.itemstack; + +import java.util.ArrayList; +import java.util.HashMap; + +import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; + +public class ComplexItemLayout +{ + + private int _invSize = 0; + private HashMap> placing = new HashMap>(); + + public ComplexItemLayout(String... strings) + { + _invSize = strings.length * 9; + for (int row = 0; row < strings.length; row++) + { + final String string = strings[row]; + char[] cArray = string.toCharArray(); + int entries = 0; + for (int i = 0; i < cArray.length; i++) + { + entries++; + if (cArray[i] == '(') + { + for (; i < cArray.length; i++) + { + if (cArray[i] == ')') + { + break; + } + else + { + if (!placing.containsKey(cArray[i])) + { + placing.put(cArray[i], new ArrayList()); + } + placing.get(cArray[i]).add((row * 9) + i); + } + if (i + 1 >= cArray.length) + { + throw new IllegalArgumentException("String '" + string + "' does not have a enclosing ) after the ("); + + } + } + } + else + { + if (!placing.containsKey(cArray[i])) + { + placing.put(cArray[i], new ArrayList()); + } + placing.get(cArray[i]).add((row * 9) + i); + } + } + if (entries != 9) + throw new IllegalArgumentException("String '" + string + "' does not 9 entries but instead has " + entries + + " entries"); + } + } + + public ItemStack[] generate(char toReplace, ArrayList items, boolean replaceExistingItems) + { + return generate(toReplace, items.toArray(new ItemStack[0]), replaceExistingItems); + } + + public ItemStack[] generate(ItemStack[] existingItems, char toReplace, ItemStack[] items, boolean replaceExistingItems) + { + ArrayList list = placing.get(toReplace); + for (int i = 0; i < list.size(); i++) + { + if (i < items.length && i < existingItems.length) + { + ItemStack item = existingItems[list.get(i)]; + if (replaceExistingItems || item == null || item.getType() == Material.AIR) + { + existingItems[list.get(i)] = items[i]; + } + } + } + return existingItems; + } + + public ItemStack[] generate(char toReplace, ItemStack[] items, boolean replaceExistingItems) + { + return generate(new ItemStack[this._invSize], toReplace, items, replaceExistingItems); + } + + public ItemStack[] generate(ItemStack[] existingItems, char toReplace, ItemStack item, boolean replaceExistingItems) + { + ArrayList list = placing.get(toReplace); + for (int i = 0; i < list.size(); i++) + { + if (i < existingItems.length) + { + ItemStack checkItem = existingItems[list.get(i)]; + if (replaceExistingItems || checkItem == null || checkItem.getType() == Material.AIR) + { + existingItems[list.get(i)] = item; + } + } + } + return existingItems; + } + + public ItemStack[] generate(char toReplace, ItemStack item, boolean replaceExistingItems) + { + return generate(new ItemStack[this._invSize], toReplace, item, replaceExistingItems); + } + +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/itemstack/ItemLayout.java b/Plugins/Mineplex.Core/src/mineplex/core/itemstack/ItemLayout.java new file mode 100644 index 000000000..3af1e8e7f --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/itemstack/ItemLayout.java @@ -0,0 +1,60 @@ +package mineplex.core.itemstack; + +import java.util.ArrayList; + +import org.bukkit.inventory.ItemStack; + +public class ItemLayout +{ + + private int _invSize = 0; + private ArrayList _size = new ArrayList(); + + public ItemLayout(String... strings) + { + _invSize = strings.length * 9; + for (int row = 0; row < strings.length; row++) + { + String string = strings[row]; + if (string.length() != 9) + throw new IllegalArgumentException("String '" + string + "' does not a length of 9 but instead has a length of " + + string.length()); + char[] cArray = string.toCharArray(); + for (int slot = 0; slot < 9; slot++) + { + char letter = cArray[slot]; + if ('x' == Character.toLowerCase(letter)) + { + continue; + } + else if ('o' == Character.toLowerCase(letter)) + { + _size.add((row * 9) + slot); + } + else + throw new IllegalArgumentException("Unrecognised character " + letter); + } + } + } + + public ItemStack[] generate(ArrayList items) + { + return generate(items.toArray(new ItemStack[0])); + } + + public ItemStack[] generate(ItemStack... items) + { + ItemStack[] itemArray = new ItemStack[_invSize]; + for (int i = 0; i < _size.size(); i++) + { + if (i < items.length) + { + ItemStack itemToInsert = items[i]; + if (itemToInsert != null) + itemArray[_size.get(i)] = itemToInsert; + } + } + return itemArray; + } + +} From 1bb4d902c692f267579db62c68ee996641be97f1 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Thu, 27 Nov 2014 06:44:46 +1300 Subject: [PATCH 17/29] Start on a kit manager --- .../games/searchanddestroy/KitManager.java | 251 ++++++++++++++++++ 1 file changed, 251 insertions(+) create mode 100644 Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/KitManager.java diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/KitManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/KitManager.java new file mode 100644 index 000000000..c3de3f5b2 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/KitManager.java @@ -0,0 +1,251 @@ +package nautilus.game.arcade.game.games.searchanddestroy; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map.Entry; + +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +import mineplex.core.itemstack.ComplexItemLayout; +import mineplex.core.itemstack.ItemBuilder; +import nautilus.game.arcade.ArcadeManager; +import nautilus.game.arcade.game.games.searchanddestroy.kits.KitBow; +import nautilus.game.arcade.kit.Kit; + +public class KitManager +{ + + private class KitTree + { + Kit baseKit; + Kit[] tier2; + HashMap tier3; + + public KitTree(Kit baseKit, Kit[] tier2, HashMap tier3) + { + this.baseKit = baseKit; + this.tier2 = tier2; + this.tier3 = tier3; + } + + public int getTier(Kit kit) + { + if (baseKit == kit) + return 1; + for (Kit k : tier2) + if (k == kit) + return 2; + for (Kit[] ki : tier3.values()) + { + for (Kit k : ki) + { + if (k == kit) + return 3; + } + } + return -1; + } + + public Kit[] getOwned(Kit kit) + { + int tier = getTier(kit); + if (tier == 2) + { + return new Kit[] + { + kit, baseKit + }; + } + else if (tier == 3) + { + for (Kit k : tier2) + { + for (Kit k1 : tier3.get(k)) + { + if (k1 == kit) + { + return new Kit[] + { + kit, baseKit, k1 + }; + } + } + } + } + return new Kit[] + { + kit + }; + } + + public Kit[] getUnowned(Kit kit) + { + int tier = getTier(kit); + Kit[] kits = new Kit[7 - tier]; + int i = 0; + if (tier == 1) + { + for (Kit k1 : tier2) + kits[i] = k1; + for (Kit[] k : tier3.values()) + for (Kit k1 : k) + kits[i] = k1; + } + if (tier == 2) + { + for (Kit k1 : tier2) + if (k1 != kit) + kits[i] = k1; + for (Kit[] k : tier3.values()) + for (Kit k1 : k) + kits[i] = k1; + } + if (tier == 3) + { + for (Kit k1 : tier2) + kits[i] = k1; + for (Kit[] k : tier3.values()) + for (Kit k1 : k) + if (k1 != kit) + kits[i] = k1; + } + return kits; + } + + public Kit[] getEvolve(Kit kit) + { + if (baseKit == kit) + { + return tier2; + } + if (tier3.containsKey(kit)) + { + return tier3.get(kit); + } + return new Kit[0]; + } + + public char getLetter(Kit kit) + { + if (baseKit == kit) + return 'a'; + for (int i = 0; i < 2; i++) + { + if (tier2[i] == kit) + return "bc".toCharArray()[i]; + for (int a = 0; a < 2; a++) + { + Kit k = tier3.get(tier2[i])[a]; + if (k == kit) + return (i == 0 ? "de" : "fg").toCharArray()[a]; + } + } + return ' '; + } + } + + private ArrayList kits = new ArrayList(); + private SearchAndDestroy _search; + private ComplexItemLayout kitLayout = new ComplexItemLayout("XXXXAXXXX", "XXXbXcXXX", "XXBXXXCXX", "XX(de)XXX(fg)XX", + "XXdeXXfgX", "XDXEXFXGX"); + + public KitManager(SearchAndDestroy search) + { + ArcadeManager man = search.getArcadeManager(); + _search = search; + { + Kit bow_T1 = new KitBow(man); + Kit bow_T2_1 = new KitBow(man); + Kit bow_T2_2 = new KitBow(man); + Kit bow_T3_1 = new KitBow(man); + Kit bow_T3_2 = new KitBow(man); + Kit bow_T3_3 = new KitBow(man); + Kit bow_T3_4 = new KitBow(man); + HashMap tier3 = new HashMap(); + tier3.put(bow_T2_1, new Kit[] + { + bow_T3_1, bow_T3_2 + }); + tier3.put(bow_T2_2, new Kit[] + { + bow_T3_3, bow_T3_4 + }); + KitTree tree = new KitTree(bow_T1, new Kit[] + { + bow_T2_1, bow_T2_2 + }, tier3); + kits.add(tree); + } + + // TODO Create kits + } + + public Kit[] getKits() + { + Kit[] kitArray = new Kit[kits.size() * 9]; + int i = 0; + for (KitTree tree : kits) + { + kitArray[i++] = tree.baseKit; + for (Entry entry : tree.tier3.entrySet()) + { + kitArray[i++] = entry.getKey(); + for (Kit kit : entry.getValue()) + { + kitArray[i++] = kit; + } + } + } + return kitArray; + } + + /** + * Opens whenever he can upgrade to a new kit. So it opens on tier 1 and 2. He could also possibly view this anytime he wanted + * just to look? + */ + public void openKitTree(Player player) + { + ItemStack[] items = new ItemStack[27]; + Kit hisKit = _search.GetKit(player); + boolean canEvolve = true; + for (KitTree tree : kits) + { + int tier = tree.getTier(hisKit); + if (tier > 0) + { + // Found his KitTree + Kit[] owned = tree.getOwned(hisKit); + for (Kit kit : owned) + { + char c = tree.getLetter(kit); + kitLayout.generate(items, c, makeItem(kit), false); + kitLayout.generate(items, Character.toLowerCase(c), new ItemStack(Material.STAINED_GLASS_PANE), false); + } + if (canEvolve) + { + Kit[] evolve = tree.getEvolve(hisKit); + for (Kit kit : evolve) + { + kitLayout.generate(items, tree.getLetter(kit), makeItem(kit), false); + } + } + for (Kit kit : tree.getUnowned(hisKit)) + { + char c = tree.getLetter(kit); + kitLayout.generate(items, Character.toUpperCase(c), + new ItemBuilder(Material.STONE).setTitle(ChatColor.DARK_RED + "LOCKED").build(), false); + } + break; + } + } + } + + private ItemStack makeItem(Kit kit) + { + return new ItemBuilder(kit.GetItemInHand()).setTitle(kit.GetName()).build(); + } + +} From 86fe7344c7367d57ec3ac4400da748754c269ea1 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Thu, 27 Nov 2014 06:56:19 +1300 Subject: [PATCH 18/29] When another inventory is opened with a previous inventory already open, this fixes the cursor position from being reset to the center of the screen. For those interested. Its basically denying the inventory close packet from being sent. --- .../src/mineplex/core/shop/ShopBase.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/shop/ShopBase.java b/Plugins/Mineplex.Core/src/mineplex/core/shop/ShopBase.java index 09ea6051f..b0a4202b2 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/shop/ShopBase.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/shop/ShopBase.java @@ -5,7 +5,11 @@ import java.util.Arrays; import java.util.HashSet; import java.util.List; +import net.minecraft.server.v1_7_R4.EntityPlayer; + import org.bukkit.ChatColor; +import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_7_R4.event.CraftEventFactory; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -211,7 +215,14 @@ public abstract class ShopBase implements Listene } SetCurrentPageForPlayer(player, page); - + + EntityPlayer nmsPlayer = ((CraftPlayer) player).getHandle(); + if (nmsPlayer.activeContainer != nmsPlayer.defaultContainer) + { + // Do this so that other inventories know their time is over. + CraftEventFactory.handleInventoryCloseEvent(nmsPlayer); + nmsPlayer.activeContainer = nmsPlayer.defaultContainer; + } player.openInventory(page); } From ac0c024b1b3bc89db18dd9b5e54d706a8681340a Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Thu, 27 Nov 2014 07:16:59 +1300 Subject: [PATCH 19/29] Use nmsPlayer.m() instead. This sets both the container to default and tells the open inventory to close. Which fixes any normal blocks like DoubleChest from remaining visually open to others. --- Plugins/Mineplex.Core/src/mineplex/core/shop/ShopBase.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/shop/ShopBase.java b/Plugins/Mineplex.Core/src/mineplex/core/shop/ShopBase.java index b0a4202b2..3e9723dd1 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/shop/ShopBase.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/shop/ShopBase.java @@ -221,7 +221,7 @@ public abstract class ShopBase implements Listene { // Do this so that other inventories know their time is over. CraftEventFactory.handleInventoryCloseEvent(nmsPlayer); - nmsPlayer.activeContainer = nmsPlayer.defaultContainer; + nmsPlayer.m(); } player.openInventory(page); } From d731b6ee69c0687bc8cc51bc3e62b32c55777000 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Thu, 27 Nov 2014 09:47:43 +1300 Subject: [PATCH 20/29] Registering of KitManager --- .../game/games/searchanddestroy/SearchAndDestroy.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/SearchAndDestroy.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/SearchAndDestroy.java index e1229dce4..c062d50d3 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/SearchAndDestroy.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/SearchAndDestroy.java @@ -31,7 +31,6 @@ import nautilus.game.arcade.GameType; import nautilus.game.arcade.events.GameStateChangeEvent; import nautilus.game.arcade.game.GameTeam; import nautilus.game.arcade.game.TeamGame; -import nautilus.game.arcade.game.games.searchanddestroy.kits.*; import nautilus.game.arcade.kit.Kit; import net.minecraft.server.v1_7_R4.EntityPlayer; import net.minecraft.server.v1_7_R4.EntityTrackerEntry; @@ -275,6 +274,8 @@ public class SearchAndDestroy extends TeamGame } } + private KitManager kitManager = new KitManager(this); + @EventHandler public void onGameEnd(GameStateChangeEvent event) { @@ -297,14 +298,11 @@ public class SearchAndDestroy extends TeamGame public SearchAndDestroy(ArcadeManager manager) { - super(manager, GameType.SearchAndDestroy, new Kit[] - { - new KitBow(manager) - }, new String[] + super(manager, GameType.SearchAndDestroy, new Kit[0], new String[] { "A test game of", "Search and Destroy" }); - + setKits(kitManager.getKits()); InventoryClick = true; WorldTimeSet = -1; WorldBoundaryKill = false; From d1b6aee8023f75073b683aa9b2e509e8771e88ca Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Thu, 27 Nov 2014 14:34:34 +1300 Subject: [PATCH 21/29] Change ItemLayout to allow repeats of item arrays --- .../mineplex/core/itemstack/ItemLayout.java | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/itemstack/ItemLayout.java b/Plugins/Mineplex.Core/src/mineplex/core/itemstack/ItemLayout.java index 3af1e8e7f..ac13d69f7 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/itemstack/ItemLayout.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/itemstack/ItemLayout.java @@ -43,16 +43,29 @@ public class ItemLayout } public ItemStack[] generate(ItemStack... items) + { + return generate(true, items); + } + + public ItemStack[] generate(boolean doRepeats, ItemStack... items) { ItemStack[] itemArray = new ItemStack[_invSize]; - for (int i = 0; i < _size.size(); i++) + if (items.length == 0) + return itemArray; + int i = 0; + for (int slot : _size) { if (i < items.length) { - ItemStack itemToInsert = items[i]; - if (itemToInsert != null) - itemArray[_size.get(i)] = itemToInsert; + if (doRepeats) + i = 0; + else + break; } + ItemStack itemToInsert = items[i]; + if (itemToInsert != null) + itemArray[slot] = itemToInsert; + } return itemArray; } From 8d12b8e565c42a380584a569473c5ea1da1af210 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Fri, 28 Nov 2014 09:30:27 +1300 Subject: [PATCH 22/29] Check item has Lore before trying to use it --- .../Mineplex.Core/src/mineplex/core/shop/item/ShopItem.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/shop/item/ShopItem.java b/Plugins/Mineplex.Core/src/mineplex/core/shop/item/ShopItem.java index 669fb6663..9803f670b 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/shop/item/ShopItem.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/shop/item/ShopItem.java @@ -26,7 +26,10 @@ public class ShopItem extends CraftItemStack _deliveryName = deliveryName; _displayItem = displayItem; _deliveryAmount = deliveryAmount; - _lore = itemStack.getItemMeta().getLore().toArray(new String[0]); + if (itemStack.getItemMeta().hasLore()) + _lore = itemStack.getItemMeta().getLore().toArray(new String[0]); + else + _lore = new String[0]; CraftItemStack craftItem = CraftItemStack.asCraftCopy(itemStack); getHandle().tag = craftItem.getHandle().tag; From d5d9e2eb14041e5a5bc19a74f7b7d1516534a1fc Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Fri, 28 Nov 2014 09:30:57 +1300 Subject: [PATCH 23/29] Don't bother with these checks in ItemLayout --- .../mineplex/core/itemstack/ItemLayout.java | 4 +- .../games/searchanddestroy/KitManager.java | 250 +++--------------- .../searchanddestroy/SearchAndDestroy.java | 7 +- .../games/searchanddestroy/kits/KitBow.java | 3 +- .../game/arcade/gui/page/SpectatorPage.java | 194 +++++++------- 5 files changed, 148 insertions(+), 310 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/itemstack/ItemLayout.java b/Plugins/Mineplex.Core/src/mineplex/core/itemstack/ItemLayout.java index ac13d69f7..b2bf96240 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/itemstack/ItemLayout.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/itemstack/ItemLayout.java @@ -62,9 +62,7 @@ public class ItemLayout else break; } - ItemStack itemToInsert = items[i]; - if (itemToInsert != null) - itemArray[slot] = itemToInsert; + itemArray[slot] = items[i]; } return itemArray; diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/KitManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/KitManager.java index c3de3f5b2..52f18375d 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/KitManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/KitManager.java @@ -1,15 +1,11 @@ package nautilus.game.arcade.game.games.searchanddestroy; import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map.Entry; - -import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; -import mineplex.core.itemstack.ComplexItemLayout; +import mineplex.core.common.util.C; import mineplex.core.itemstack.ItemBuilder; import nautilus.game.arcade.ArcadeManager; import nautilus.game.arcade.game.games.searchanddestroy.kits.KitBow; @@ -18,234 +14,72 @@ import nautilus.game.arcade.kit.Kit; public class KitManager { - private class KitTree + public class UpgradeKit { - Kit baseKit; - Kit[] tier2; - HashMap tier3; + UpgradeKit _daddy; + Kit _kit; + ArrayList _children; + int[] _path; + int _kitSlot; - public KitTree(Kit baseKit, Kit[] tier2, HashMap tier3) + public UpgradeKit(UpgradeKit daddy, Kit me, ArrayList children, int kitSlot, int... pathSlots) { - this.baseKit = baseKit; - this.tier2 = tier2; - this.tier3 = tier3; - } - - public int getTier(Kit kit) - { - if (baseKit == kit) - return 1; - for (Kit k : tier2) - if (k == kit) - return 2; - for (Kit[] ki : tier3.values()) - { - for (Kit k : ki) - { - if (k == kit) - return 3; - } - } - return -1; - } - - public Kit[] getOwned(Kit kit) - { - int tier = getTier(kit); - if (tier == 2) - { - return new Kit[] - { - kit, baseKit - }; - } - else if (tier == 3) - { - for (Kit k : tier2) - { - for (Kit k1 : tier3.get(k)) - { - if (k1 == kit) - { - return new Kit[] - { - kit, baseKit, k1 - }; - } - } - } - } - return new Kit[] - { - kit - }; - } - - public Kit[] getUnowned(Kit kit) - { - int tier = getTier(kit); - Kit[] kits = new Kit[7 - tier]; - int i = 0; - if (tier == 1) - { - for (Kit k1 : tier2) - kits[i] = k1; - for (Kit[] k : tier3.values()) - for (Kit k1 : k) - kits[i] = k1; - } - if (tier == 2) - { - for (Kit k1 : tier2) - if (k1 != kit) - kits[i] = k1; - for (Kit[] k : tier3.values()) - for (Kit k1 : k) - kits[i] = k1; - } - if (tier == 3) - { - for (Kit k1 : tier2) - kits[i] = k1; - for (Kit[] k : tier3.values()) - for (Kit k1 : k) - if (k1 != kit) - kits[i] = k1; - } - return kits; - } - - public Kit[] getEvolve(Kit kit) - { - if (baseKit == kit) - { - return tier2; - } - if (tier3.containsKey(kit)) - { - return tier3.get(kit); - } - return new Kit[0]; - } - - public char getLetter(Kit kit) - { - if (baseKit == kit) - return 'a'; - for (int i = 0; i < 2; i++) - { - if (tier2[i] == kit) - return "bc".toCharArray()[i]; - for (int a = 0; a < 2; a++) - { - Kit k = tier3.get(tier2[i])[a]; - if (k == kit) - return (i == 0 ? "de" : "fg").toCharArray()[a]; - } - } - return ' '; + _kitSlot = kitSlot; + _path = pathSlots; + _daddy = daddy; + _kit = me; + _children = children; } } - private ArrayList kits = new ArrayList(); + private ArrayList kits = new ArrayList(); private SearchAndDestroy _search; - private ComplexItemLayout kitLayout = new ComplexItemLayout("XXXXAXXXX", "XXXbXcXXX", "XXBXXXCXX", "XX(de)XXX(fg)XX", - "XXdeXXfgX", "XDXEXFXGX"); public KitManager(SearchAndDestroy search) { ArcadeManager man = search.getArcadeManager(); _search = search; { - Kit bow_T1 = new KitBow(man); - Kit bow_T2_1 = new KitBow(man); - Kit bow_T2_2 = new KitBow(man); - Kit bow_T3_1 = new KitBow(man); - Kit bow_T3_2 = new KitBow(man); - Kit bow_T3_3 = new KitBow(man); - Kit bow_T3_4 = new KitBow(man); - HashMap tier3 = new HashMap(); - tier3.put(bow_T2_1, new Kit[] - { - bow_T3_1, bow_T3_2 - }); - tier3.put(bow_T2_2, new Kit[] - { - bow_T3_3, bow_T3_4 - }); - KitTree tree = new KitTree(bow_T1, new Kit[] - { - bow_T2_1, bow_T2_2 - }, tier3); - kits.add(tree); + ArrayList children1 = new ArrayList(); + ArrayList children2 = new ArrayList(); + ArrayList children3 = new ArrayList(); + + UpgradeKit bow1 = new UpgradeKit(null, new KitBow(man), children1, 4); + kits.add(bow1); + UpgradeKit bow2 = new UpgradeKit(bow1, new KitBow(man), children2, 20, 12); + kits.add(bow2); + UpgradeKit bow3 = new UpgradeKit(bow1, new KitBow(man), children3, 24, 14); + kits.add(bow3); + UpgradeKit bow4 = new UpgradeKit(bow2, new KitBow(man), new ArrayList(), 46, 29, 37); + kits.add(bow4); + UpgradeKit bow5 = new UpgradeKit(bow2, new KitBow(man), new ArrayList(), 50, 29, 39); + kits.add(bow5); + UpgradeKit bow6 = new UpgradeKit(bow3, new KitBow(man), new ArrayList(), 51, 33, 41); + kits.add(bow6); + UpgradeKit bow7 = new UpgradeKit(bow3, new KitBow(man), new ArrayList(), 53, 33, 43); + kits.add(bow7); + children2.add(bow4); + children2.add(bow5); + children3.add(bow6); + children3.add(bow7); + } - // TODO Create kits } public Kit[] getKits() { - Kit[] kitArray = new Kit[kits.size() * 9]; - int i = 0; - for (KitTree tree : kits) + Kit[] kitArray = new Kit[kits.size()]; + for (int i = 0; i < kitArray.length; i++) { - kitArray[i++] = tree.baseKit; - for (Entry entry : tree.tier3.entrySet()) - { - kitArray[i++] = entry.getKey(); - for (Kit kit : entry.getValue()) - { - kitArray[i++] = kit; - } - } + kitArray[i] = kits.get(i)._kit; } return kitArray; } - /** - * Opens whenever he can upgrade to a new kit. So it opens on tier 1 and 2. He could also possibly view this anytime he wanted - * just to look? - */ - public void openKitTree(Player player) + public ArrayList getUpgradeKits() { - ItemStack[] items = new ItemStack[27]; - Kit hisKit = _search.GetKit(player); - boolean canEvolve = true; - for (KitTree tree : kits) - { - int tier = tree.getTier(hisKit); - if (tier > 0) - { - // Found his KitTree - Kit[] owned = tree.getOwned(hisKit); - for (Kit kit : owned) - { - char c = tree.getLetter(kit); - kitLayout.generate(items, c, makeItem(kit), false); - kitLayout.generate(items, Character.toLowerCase(c), new ItemStack(Material.STAINED_GLASS_PANE), false); - } - if (canEvolve) - { - Kit[] evolve = tree.getEvolve(hisKit); - for (Kit kit : evolve) - { - kitLayout.generate(items, tree.getLetter(kit), makeItem(kit), false); - } - } - for (Kit kit : tree.getUnowned(hisKit)) - { - char c = tree.getLetter(kit); - kitLayout.generate(items, Character.toUpperCase(c), - new ItemBuilder(Material.STONE).setTitle(ChatColor.DARK_RED + "LOCKED").build(), false); - } - break; - } - } - } - - private ItemStack makeItem(Kit kit) - { - return new ItemBuilder(kit.GetItemInHand()).setTitle(kit.GetName()).build(); + return kits; } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/SearchAndDestroy.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/SearchAndDestroy.java index c062d50d3..2e2836d85 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/SearchAndDestroy.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/SearchAndDestroy.java @@ -15,6 +15,7 @@ import org.bukkit.craftbukkit.v1_7_R4.CraftWorld; import org.bukkit.entity.Player; import org.bukkit.entity.TNTPrimed; import org.bukkit.event.EventHandler; +import org.bukkit.event.HandlerList; import org.bukkit.event.block.Action; import org.bukkit.event.entity.EntityDamageEvent.DamageCause; import org.bukkit.event.player.PlayerInteractEntityEvent; @@ -279,8 +280,9 @@ public class SearchAndDestroy extends TeamGame @EventHandler public void onGameEnd(GameStateChangeEvent event) { - if (event.GetState() == GameState.End && !getBombs().isEmpty()) + if (event.GetState() == GameState.End) { + HandlerList.unregisterAll(evolve); for (TeamBomb bomb : getBombs()) { if (bomb.getTeam().IsTeamAlive()) @@ -296,6 +298,8 @@ public class SearchAndDestroy extends TeamGame } } + private KitEvolve evolve; + public SearchAndDestroy(ArcadeManager manager) { super(manager, GameType.SearchAndDestroy, new Kit[0], new String[] @@ -303,6 +307,7 @@ public class SearchAndDestroy extends TeamGame "A test game of", "Search and Destroy" }); setKits(kitManager.getKits()); + evolve = new KitEvolve(manager.GetPlugin(), this, kitManager.getUpgradeKits()); InventoryClick = true; WorldTimeSet = -1; WorldBoundaryKill = false; diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/kits/KitBow.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/kits/KitBow.java index 2823a446b..2ee7d267f 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/kits/KitBow.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/kits/KitBow.java @@ -16,10 +16,11 @@ import nautilus.game.arcade.kit.Perk; public class KitBow extends KitHuman { + private static int bowNo = 0; public KitBow(ArcadeManager manager) { - super(manager, "Bow", KitAvailability.Free, new String[] + super(manager, "Bow" + ++bowNo, bowNo == 1 ? KitAvailability.Free : KitAvailability.Hide, new String[] { "A basic kit with a bow" }, new Perk[0], EntityType.SKELETON, new ItemStack(Material.BOW)); diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/gui/page/SpectatorPage.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/gui/page/SpectatorPage.java index 591136d3c..5166e9999 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/gui/page/SpectatorPage.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/gui/page/SpectatorPage.java @@ -32,127 +32,127 @@ import nautilus.game.arcade.gui.button.SpectatorButton; public class SpectatorPage extends ShopPageBase { - private ArcadeManager _arcadeManager; + private ArcadeManager _arcadeManager; - public SpectatorPage(CompassAddon plugin, ArcadeManager arcadeManager, SpectatorShop shop, CoreClientManager clientManager, DonationManager donationManager, Player player) - { - super(plugin, shop, clientManager, donationManager, "Spectator Menu", player); - _arcadeManager = arcadeManager; - BuildPage(); - } + public SpectatorPage(CompassAddon plugin, ArcadeManager arcadeManager, SpectatorShop shop, CoreClientManager clientManager, + DonationManager donationManager, Player player) + { + super(plugin, shop, clientManager, donationManager, "Spectator Menu", player); + _arcadeManager = arcadeManager; + BuildPage(); + } - @Override - protected void BuildPage() - { - int playerCount = _arcadeManager.GetGame().GetPlayers(true).size(); - List teamList = _arcadeManager.GetGame().GetTeamList(); + @Override + protected void BuildPage() + { + int playerCount = _arcadeManager.GetGame().GetPlayers(true).size(); + List teamList = _arcadeManager.GetGame().GetTeamList(); - if (teamList.size() == 1 && playerCount < 28) - buildSingleTeam(teamList.get(0), playerCount); - else - buildMultipleTeams(teamList, playerCount); + if (teamList.size() == 1 && playerCount < 28) + buildSingleTeam(teamList.get(0), playerCount); + else + buildMultipleTeams(teamList, playerCount); - } + } - private void buildSingleTeam(GameTeam team, int playerCount) - { - setItem(13, getTeamItem(team, playerCount)); + private void buildSingleTeam(GameTeam team, int playerCount) + { + setItem(13, getTeamItem(team, playerCount)); - int slot = 19; + int slot = 19; - for (Player other : team.GetPlayers(true)) - { - addPlayerItem(slot, team, other); + for (Player other : team.GetPlayers(true)) + { + addPlayerItem(slot, team, other); - if ((slot + 2) % 9 == 0) - slot += 3; - else - slot++; - } - } + if ((slot + 2) % 9 == 0) + slot += 3; + else + slot++; + } + } - private void buildMultipleTeams(List teamList, int playerCount) - { - int currentRow = 0; + private void buildMultipleTeams(List teamList, int playerCount) + { + int currentRow = 0; - for (GameTeam team : teamList) - { - ArrayList teamPlayers = team.GetPlayers(true); - int rowsNeeded = (teamPlayers.size() / 8) + 1; + for (GameTeam team : teamList) + { + ArrayList teamPlayers = team.GetPlayers(true); + int rowsNeeded = (teamPlayers.size() / 8) + 1; - for (int row = 0; row < rowsNeeded; row++) - { - int woolSlot = (row * 9) + (currentRow * 9); + for (int row = 0; row < rowsNeeded; row++) + { + int woolSlot = (row * 9) + (currentRow * 9); + // TODO Need to handle too many players in a better way + if (woolSlot >= getSize()) + continue; - // TODO Need to handle too many players in a better way - if (woolSlot >= getSize()) - continue; + setItem(woolSlot, getTeamItem(team, teamPlayers.size())); - setItem(woolSlot, getTeamItem(team, teamPlayers.size())); + int startPlayerIndex = row * 9; + for (int playerIndex = startPlayerIndex; playerIndex < teamPlayers.size() && playerIndex < startPlayerIndex + 9; playerIndex++) + { + Player other = teamPlayers.get(playerIndex); + int slot = woolSlot + 1 + playerIndex; - int startPlayerIndex = row * 9; - for (int playerIndex = startPlayerIndex; playerIndex < teamPlayers.size() && playerIndex < startPlayerIndex + 9; playerIndex++) - { - Player other = teamPlayers.get(playerIndex); - int slot = woolSlot + 1 + playerIndex; + // TODO Need to handle too many players in a better way + if (slot >= getSize()) + continue; - // TODO Need to handle too many players in a better way - if (slot >= getSize()) - continue; + addPlayerItem(slot, team, other); + } + } - addPlayerItem(slot, team, other); - } - } + // Add a line in between teams if the player count is low enough and there are less than 4 teams + if (rowsNeeded == 1 && teamList.size() < 4 && playerCount <= 26) + currentRow += 2; + else + currentRow += rowsNeeded; + } + } - // Add a line in between teams if the player count is low enough and there are less than 4 teams - if (rowsNeeded == 1 && teamList.size() < 4 && playerCount <= 26) - currentRow += 2; - else - currentRow += rowsNeeded; - } - } + private void addPlayerItem(int slot, GameTeam team, Player other) + { + ItemStack playerItem = getPlayerItem(team, other); + ShopItem shopItem = new ShopItem(playerItem, other.getName(), other.getName(), 1, false, false); + AddButton(slot, shopItem, new SpectatorButton(_arcadeManager, Player, other)); + } - private void addPlayerItem(int slot, GameTeam team, Player other) - { - ItemStack playerItem = getPlayerItem(team, other); - ShopItem shopItem = new ShopItem(playerItem, other.getName(), other.getName(), 1, false, false); - AddButton(slot, shopItem, new SpectatorButton(_arcadeManager, Player, other)); - } + private ItemStack getTeamItem(GameTeam team, int playerCount) + { + ItemStack item = new ItemStack(Material.WOOL, 1, (short) 0, UtilColor.chatColorToWoolData(team.GetColor())); - private ItemStack getTeamItem(GameTeam team, int playerCount) - { - ItemStack item = new ItemStack(Material.WOOL, 1, (short)0, UtilColor.chatColorToWoolData(team.GetColor())); + ItemMeta meta = item.getItemMeta(); + meta.setDisplayName(team.GetFormattedName()); + meta.setLore(Arrays.asList(" ", ChatColor.RESET + C.cYellow + "Players Alive: " + C.cWhite + playerCount)); + item.setItemMeta(meta); - ItemMeta meta = item.getItemMeta(); - meta.setDisplayName(team.GetFormattedName()); - meta.setLore(Arrays.asList(" ", ChatColor.RESET + C.cYellow + "Players Alive: " + C.cWhite + playerCount)); - item.setItemMeta(meta); + return item; + } - return item; - } + private ItemStack getPlayerItem(GameTeam team, Player other) + { + ItemStack item = new ItemStack(Material.SKULL_ITEM, 1, (byte) 3); - private ItemStack getPlayerItem(GameTeam team, Player other) - { - ItemStack item = new ItemStack(Material.SKULL_ITEM, 1, (byte) 3); + double distance = UtilMath.offset(Player, other); + double heightDifference = other.getLocation().getY() - Player.getLocation().getY(); - double distance = UtilMath.offset(Player, other); - double heightDifference = other.getLocation().getY() - Player.getLocation().getY(); + ArrayList lore = new ArrayList(); + lore.add(" "); + lore.add(ChatColor.RESET + C.cYellow + "Kit: " + C.cWhite + _arcadeManager.GetGame().GetKit(other).GetName()); + lore.add(ChatColor.RESET + C.cYellow + "Distance: " + C.cWhite + UtilMath.trim(1, distance)); + lore.add(ChatColor.RESET + C.cYellow + "Height Difference: " + C.cWhite + UtilMath.trim(1, heightDifference)); + lore.add(" "); + lore.add(ChatColor.RESET + C.Line + "Click to Spectate"); + SkullMeta skullMeta = ((SkullMeta) item.getItemMeta()); + skullMeta.setOwner(other.getName()); + skullMeta.setDisplayName(team.GetColor() + other.getName()); + skullMeta.setLore(lore); + item.setItemMeta(skullMeta); - ArrayList lore = new ArrayList(); - lore.add(" "); - lore.add(ChatColor.RESET + C.cYellow + "Kit: " + C.cWhite + _arcadeManager.GetGame().GetKit(other).GetName()); - lore.add(ChatColor.RESET + C.cYellow + "Distance: " + C.cWhite + UtilMath.trim(1, distance)); - lore.add(ChatColor.RESET + C.cYellow + "Height Difference: " + C.cWhite + UtilMath.trim(1, heightDifference)); - lore.add(" "); - lore.add(ChatColor.RESET + C.Line + "Click to Spectate"); - SkullMeta skullMeta = ((SkullMeta) item.getItemMeta()); - skullMeta.setOwner(other.getName()); - skullMeta.setDisplayName(team.GetColor() + other.getName()); - skullMeta.setLore(lore); - item.setItemMeta(skullMeta); - - return item; - } + return item; + } } \ No newline at end of file From e56970a2126452d43e69a67287187287cf9c5d6b Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Sat, 29 Nov 2014 07:21:37 +1300 Subject: [PATCH 24/29] Let ShopItem no longer extend CraftItemStack and instead extend ItemStack to remain useful to other plugins and use ItemMeta --- .../src/mineplex/core/shop/item/ShopItem.java | 61 ++++++++----------- 1 file changed, 27 insertions(+), 34 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/shop/item/ShopItem.java b/Plugins/Mineplex.Core/src/mineplex/core/shop/item/ShopItem.java index 9803f670b..89ee6e903 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/shop/item/ShopItem.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/shop/item/ShopItem.java @@ -1,15 +1,16 @@ package mineplex.core.shop.item; -import org.bukkit.ChatColor; +import java.util.ArrayList; + import org.bukkit.Material; import org.bukkit.craftbukkit.v1_7_R4.inventory.CraftItemStack; import org.bukkit.inventory.ItemStack; -import net.minecraft.server.v1_7_R4.NBTTagList; -import net.minecraft.server.v1_7_R4.NBTTagString; +import org.bukkit.inventory.meta.ItemMeta; +import mineplex.core.common.util.C; import mineplex.core.common.util.UtilInv; -public class ShopItem extends CraftItemStack +public class ShopItem extends ItemStack { protected String _name; private String _deliveryName; @@ -31,11 +32,11 @@ public class ShopItem extends CraftItemStack else _lore = new String[0]; - CraftItemStack craftItem = CraftItemStack.asCraftCopy(itemStack); - getHandle().tag = craftItem.getHandle().tag; - UpdateVisual(true); - getHandle().tag.set("AttributeModifiers", new NBTTagList()); + } + + public net.minecraft.server.v1_7_R4.ItemStack getHandle() { + return CraftItemStack.asNMSCopy(this); } public ShopItem(Material type, String name, int deliveryAmount, boolean locked) @@ -96,8 +97,7 @@ public class ShopItem extends CraftItemStack UpdateVisual(false); - getHandle().tag.setByte("Count", (byte)Math.max(deliveryAmount, 1)); - getHandle().tag.set("AttributeModifiers", new NBTTagList()); + setAmount(Math.max(deliveryAmount, 1)); } public boolean IsLocked() @@ -111,7 +111,11 @@ public class ShopItem extends CraftItemStack //Delivery Name if (_deliveryName != null) - this.getHandle().c(_deliveryName); + { + ItemMeta meta = getItemMeta(); + meta.setDisplayName(_deliveryName); + setItemMeta(meta); + } } public ShopItem clone() @@ -122,43 +126,30 @@ public class ShopItem extends CraftItemStack @Override public boolean equals(Object obj) { - if (!super.equals(obj)) - { - return false; - } - - net.minecraft.server.v1_7_R4.ItemStack original = ((CraftItemStack)this).getHandle(); - net.minecraft.server.v1_7_R4.ItemStack comparison = ((CraftItemStack)obj).getHandle(); - - return original.tag == null || original.tag.equals(comparison.tag); + return super.equals(obj); } protected void UpdateVisual(boolean clone) { + ItemMeta meta = getItemMeta(); if (!clone) { - if (_locked && !_displayItem) - { - this.getHandle().c(ChatColor.RED + "§l" + _name); - } - else - { - this.getHandle().c(ChatColor.GREEN + "§l" + _name); - } + meta.setDisplayName((_locked && !_displayItem? C.cRed:C.cGreen) + C.Bold + _name); } - NBTTagList lore = new NBTTagList(); + ArrayList lore = new ArrayList(); if (_lore != null) { for (String line : _lore) { if (line != null && !line.isEmpty()) - lore.add(new NBTTagString(line)); + lore.add(line); } } + meta.setLore(lore);; - getHandle().tag.getCompound("display").set("Lore", lore); + setItemMeta(meta); } public boolean IsDisplay() @@ -191,17 +182,19 @@ public class ShopItem extends CraftItemStack { _lore = string; - NBTTagList lore = new NBTTagList(); + ArrayList lore = new ArrayList(); if (_lore != null) { for (String line : _lore) { if (line != null && !line.isEmpty()) - lore.add(new NBTTagString(line)); + lore.add(line); } } - getHandle().tag.getCompound("display").set("Lore", lore); + ItemMeta meta = getItemMeta(); + meta.setLore(lore); + setItemMeta(meta); } } From e6fac6de3921bf59443d1308e83301061f3efc4a Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Sat, 29 Nov 2014 07:22:02 +1300 Subject: [PATCH 25/29] Small typo in UpgradeKit stuff --- .../arcade/game/games/searchanddestroy/KitManager.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/KitManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/KitManager.java index 52f18375d..6375a3475 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/KitManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/KitManager.java @@ -52,12 +52,14 @@ public class KitManager kits.add(bow3); UpgradeKit bow4 = new UpgradeKit(bow2, new KitBow(man), new ArrayList(), 46, 29, 37); kits.add(bow4); - UpgradeKit bow5 = new UpgradeKit(bow2, new KitBow(man), new ArrayList(), 50, 29, 39); + UpgradeKit bow5 = new UpgradeKit(bow2, new KitBow(man), new ArrayList(), 48, 29, 39); kits.add(bow5); - UpgradeKit bow6 = new UpgradeKit(bow3, new KitBow(man), new ArrayList(), 51, 33, 41); + UpgradeKit bow6 = new UpgradeKit(bow3, new KitBow(man), new ArrayList(), 50, 33, 41); kits.add(bow6); - UpgradeKit bow7 = new UpgradeKit(bow3, new KitBow(man), new ArrayList(), 53, 33, 43); + UpgradeKit bow7 = new UpgradeKit(bow3, new KitBow(man), new ArrayList(), 52, 33, 43); kits.add(bow7); + children1.add(bow2); + children1.add(bow3); children2.add(bow4); children2.add(bow5); children3.add(bow6); From 5544bbb440c1c204df82012ada429f817dc85e38 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Sat, 29 Nov 2014 07:22:18 +1300 Subject: [PATCH 26/29] Add KitEvolve inventory --- .../games/searchanddestroy/EvolveButton.java | 30 ++++++ .../games/searchanddestroy/KitEvolve.java | 40 ++++++++ .../games/searchanddestroy/KitEvolvePage.java | 93 +++++++++++++++++++ .../games/searchanddestroy/KitEvolveShop.java | 41 ++++++++ 4 files changed, 204 insertions(+) create mode 100644 Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/EvolveButton.java create mode 100644 Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/KitEvolve.java create mode 100644 Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/KitEvolvePage.java create mode 100644 Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/KitEvolveShop.java diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/EvolveButton.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/EvolveButton.java new file mode 100644 index 000000000..e61cf792c --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/EvolveButton.java @@ -0,0 +1,30 @@ +package nautilus.game.arcade.game.games.searchanddestroy; + +import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer; +import org.bukkit.entity.Player; + +import mineplex.core.shop.item.SingleButton; +import nautilus.game.arcade.kit.Kit; + +public class EvolveButton extends SingleButton +{ + private SearchAndDestroy _arcadeManager; + private Kit _kit; + + public EvolveButton(SearchAndDestroy arcadeManager, Kit kit) + { + _arcadeManager = arcadeManager; + _kit = kit; + } + + @Override + public void Clicked(Player player) + { + // Make sure this player isn't a spectator + if (((CraftPlayer) player).getHandle().spectating) + return; + + _arcadeManager.SetKit(player, _kit, true); + player.closeInventory(); + } +} \ No newline at end of file diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/KitEvolve.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/KitEvolve.java new file mode 100644 index 000000000..26e8655df --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/KitEvolve.java @@ -0,0 +1,40 @@ +package nautilus.game.arcade.game.games.searchanddestroy; + +import java.util.ArrayList; + +import nautilus.game.arcade.ArcadeManager; +import nautilus.game.arcade.game.Game.GameState; +import nautilus.game.arcade.game.games.searchanddestroy.KitManager.UpgradeKit; + +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerChatEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.plugin.java.JavaPlugin; + +import mineplex.core.MiniPlugin; + +public class KitEvolve extends MiniPlugin +{ + + private SearchAndDestroy arcadeManager; + private KitEvolveShop kitEvolve; + + public KitEvolve(JavaPlugin plugin, SearchAndDestroy manager, ArrayList kits) + { + super("SnD Kit Evolving", plugin); + arcadeManager = manager; + kitEvolve = new KitEvolveShop(this, manager, manager.getArcadeManager().GetClients(), manager.getArcadeManager() + .GetDonation(), kits); + // TODO Auto-generated constructor stub + } + + @EventHandler + public void onInteract(PlayerChatEvent event) + { + if (arcadeManager.GetState() == GameState.Live) + { + kitEvolve.attemptShopOpen(event.getPlayer()); + } + } + +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/KitEvolvePage.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/KitEvolvePage.java new file mode 100644 index 000000000..1aa089739 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/KitEvolvePage.java @@ -0,0 +1,93 @@ +package nautilus.game.arcade.game.games.searchanddestroy; + +import java.util.ArrayList; + +import mineplex.core.account.CoreClientManager; +import mineplex.core.common.util.C; +import mineplex.core.donation.DonationManager; +import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.shop.item.ShopItem; +import mineplex.core.shop.page.ShopPageBase; +import nautilus.game.arcade.game.games.searchanddestroy.KitManager.UpgradeKit; +import nautilus.game.arcade.kit.Kit; + +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +public class KitEvolvePage extends ShopPageBase +{ + private SearchAndDestroy _search; + private ArrayList _kits; + + public KitEvolvePage(KitEvolve plugin, SearchAndDestroy arcadeManager, KitEvolveShop shop, CoreClientManager clientManager, + DonationManager donationManager, Player player, ArrayList kits) + { + super(plugin, shop, clientManager, donationManager, "Kit Evolve Menu", player); + _search = arcadeManager; + _kits = kits; + BuildPage(); + } + + @Override + protected void BuildPage() + { + Kit hisKit = _search.GetKit(Player); + UpgradeKit kit = null; + for (UpgradeKit k : _kits) + { + if (k._kit == hisKit) + { + kit = k; + break; + } + } + boolean canEvolve = true; + AddItem(kit._kitSlot, makeItem(kit._kit)); + for (int slot : kit._path) + { + AddItem(slot, makeItem(new ItemBuilder(Material.STAINED_GLASS_PANE, 1, (short) 15).setTitle(" ").build())); + } + if (kit._daddy != null) + { + AddItem(kit._daddy._kitSlot, makeItem(kit._daddy._kit)); + for (int slot : kit._daddy._path) + { + AddItem(slot, makeItem(new ItemBuilder(Material.STAINED_GLASS_PANE, 1, (short) 15).setTitle(" ").build())); + } + if (kit._daddy._daddy != null) + { + AddItem(kit._daddy._daddy._kitSlot, makeItem(kit._daddy._daddy._kit)); + } + } + if (canEvolve) + { + for (UpgradeKit child : kit._children) + { + for (int slot : child._path) + AddItem(slot, makeItem(new ItemBuilder(Material.STAINED_GLASS_PANE).setTitle(" ").build())); + AddButton(child._kitSlot, makeItem(child._kit), new EvolveButton(_search, child._kit)); + } + } + for (UpgradeKit k : _kits) + { + if (getItem(k._kitSlot) == null) + { + AddItem(k._kitSlot, makeItem(new ItemBuilder(Material.STONE).setTitle(C.cRed + "Locked").build())); + } + } + } + + private ShopItem makeItem(Kit kit) + { + return new ShopItem(new ItemBuilder(kit.GetItemInHand()).setTitle(kit.GetName()).build(), kit.GetName(), kit.GetName(), + 1, false, false); + } + + private ShopItem makeItem(ItemStack item) + { + System.out.print("Making shop item " + item); + return new ShopItem(item, "", "", 1, false, false); + } + +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/KitEvolveShop.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/KitEvolveShop.java new file mode 100644 index 000000000..dbf16c98f --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/KitEvolveShop.java @@ -0,0 +1,41 @@ +package nautilus.game.arcade.game.games.searchanddestroy; + +import java.util.ArrayList; + +import mineplex.core.account.CoreClientManager; +import mineplex.core.common.CurrencyType; +import mineplex.core.donation.DonationManager; +import mineplex.core.shop.ShopBase; +import mineplex.core.shop.page.ShopPageBase; +import nautilus.game.arcade.game.games.searchanddestroy.KitManager.UpgradeKit; + +import org.bukkit.entity.Player; + +public class KitEvolveShop extends ShopBase +{ + + private SearchAndDestroy _arcadeManager; + private ArrayList _kits; + + public KitEvolveShop(KitEvolve plugin, SearchAndDestroy arcadeManager, CoreClientManager clientManager, + DonationManager donationManager, ArrayList kits, CurrencyType... currencyTypes) + { + super(plugin, clientManager, donationManager, "Kit Evolve Menu", currencyTypes); + _arcadeManager = arcadeManager; + _kits = kits; + } + + @Override + protected ShopPageBase> BuildPagesFor(Player player) + { + return new KitEvolvePage(Plugin, _arcadeManager, this, ClientManager, DonationManager, player, _kits); + } + + public void update() + { + for (ShopPageBase> shopPage : PlayerPageMap.values()) + { + shopPage.Refresh(); + } + } +} From e587fca8f1d9198a0a1cf2c0ab818571ac99a5a7 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Sat, 29 Nov 2014 07:53:33 +1300 Subject: [PATCH 27/29] Move KitBow to its own package --- .../game/games/searchanddestroy/kits/{ => bow}/KitBow.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/kits/{ => bow}/KitBow.java (95%) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/kits/KitBow.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/kits/bow/KitBow.java similarity index 95% rename from Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/kits/KitBow.java rename to Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/kits/bow/KitBow.java index 2ee7d267f..6778e84e5 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/kits/KitBow.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/kits/bow/KitBow.java @@ -1,4 +1,4 @@ -package nautilus.game.arcade.game.games.searchanddestroy.kits; +package nautilus.game.arcade.game.games.searchanddestroy.kits.bow; import org.bukkit.ChatColor; import org.bukkit.Material; From 24bc581f352e1369b58fb24953c945afdd7d5071 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Sat, 29 Nov 2014 10:36:34 +1300 Subject: [PATCH 28/29] Add the kits I have --- .../games/searchanddestroy/KitEvolvePage.java | 5 +- .../games/searchanddestroy/KitManager.java | 13 ++- .../searchanddestroy/kits/bow/KitBow.java | 3 +- .../searchanddestroy/kits/bow/KitPinner.java | 98 +++++++++++++++++ .../searchanddestroy/kits/bow/KitPunch.java | 54 ++++++++++ .../searchanddestroy/kits/bow/KitSniper.java | 76 +++++++++++++ .../kits/bow/KitStitcher.java | 101 ++++++++++++++++++ 7 files changed, 338 insertions(+), 12 deletions(-) create mode 100644 Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/kits/bow/KitPinner.java create mode 100644 Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/kits/bow/KitPunch.java create mode 100644 Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/kits/bow/KitSniper.java create mode 100644 Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/kits/bow/KitStitcher.java diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/KitEvolvePage.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/KitEvolvePage.java index 1aa089739..ffb2c58fb 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/KitEvolvePage.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/KitEvolvePage.java @@ -80,13 +80,12 @@ public class KitEvolvePage extends ShopPageBase private ShopItem makeItem(Kit kit) { - return new ShopItem(new ItemBuilder(kit.GetItemInHand()).setTitle(kit.GetName()).build(), kit.GetName(), kit.GetName(), - 1, false, false); + return new ShopItem(new ItemBuilder(kit.GetItemInHand()).setTitle(kit.GetName()).addLore(kit.GetDesc()).build(), + kit.GetName(), kit.GetName(), 1, false, false); } private ShopItem makeItem(ItemStack item) { - System.out.print("Making shop item " + item); return new ShopItem(item, "", "", 1, false, false); } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/KitManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/KitManager.java index 6375a3475..cccbb6463 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/KitManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/KitManager.java @@ -1,6 +1,7 @@ package nautilus.game.arcade.game.games.searchanddestroy; import java.util.ArrayList; + import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -8,7 +9,7 @@ import org.bukkit.inventory.ItemStack; import mineplex.core.common.util.C; import mineplex.core.itemstack.ItemBuilder; import nautilus.game.arcade.ArcadeManager; -import nautilus.game.arcade.game.games.searchanddestroy.kits.KitBow; +import nautilus.game.arcade.game.games.searchanddestroy.kits.bow.*; import nautilus.game.arcade.kit.Kit; public class KitManager @@ -33,12 +34,10 @@ public class KitManager } private ArrayList kits = new ArrayList(); - private SearchAndDestroy _search; public KitManager(SearchAndDestroy search) { ArcadeManager man = search.getArcadeManager(); - _search = search; { ArrayList children1 = new ArrayList(); ArrayList children2 = new ArrayList(); @@ -46,15 +45,15 @@ public class KitManager UpgradeKit bow1 = new UpgradeKit(null, new KitBow(man), children1, 4); kits.add(bow1); - UpgradeKit bow2 = new UpgradeKit(bow1, new KitBow(man), children2, 20, 12); + UpgradeKit bow2 = new UpgradeKit(bow1, new KitStitcher(man), children2, 20, 12); kits.add(bow2); - UpgradeKit bow3 = new UpgradeKit(bow1, new KitBow(man), children3, 24, 14); + UpgradeKit bow3 = new UpgradeKit(bow1, new KitPunch(man), children3, 24, 14); kits.add(bow3); - UpgradeKit bow4 = new UpgradeKit(bow2, new KitBow(man), new ArrayList(), 46, 29, 37); + UpgradeKit bow4 = new UpgradeKit(bow2, new KitSniper(man), new ArrayList(), 46, 29, 37); kits.add(bow4); UpgradeKit bow5 = new UpgradeKit(bow2, new KitBow(man), new ArrayList(), 48, 29, 39); kits.add(bow5); - UpgradeKit bow6 = new UpgradeKit(bow3, new KitBow(man), new ArrayList(), 50, 33, 41); + UpgradeKit bow6 = new UpgradeKit(bow3, new KitPinner(man), new ArrayList(), 50, 33, 41); kits.add(bow6); UpgradeKit bow7 = new UpgradeKit(bow3, new KitBow(man), new ArrayList(), 52, 33, 43); kits.add(bow7); diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/kits/bow/KitBow.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/kits/bow/KitBow.java index 6778e84e5..376898caa 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/kits/bow/KitBow.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/kits/bow/KitBow.java @@ -16,11 +16,10 @@ import nautilus.game.arcade.kit.Perk; public class KitBow extends KitHuman { - private static int bowNo = 0; public KitBow(ArcadeManager manager) { - super(manager, "Bow" + ++bowNo, bowNo == 1 ? KitAvailability.Free : KitAvailability.Hide, new String[] + super(manager, "Bow", KitAvailability.Free, new String[] { "A basic kit with a bow" }, new Perk[0], EntityType.SKELETON, new ItemStack(Material.BOW)); diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/kits/bow/KitPinner.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/kits/bow/KitPinner.java new file mode 100644 index 000000000..e1518e2ba --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/kits/bow/KitPinner.java @@ -0,0 +1,98 @@ +package nautilus.game.arcade.game.games.searchanddestroy.kits.bow; + +import java.util.Iterator; + +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.entity.EntityDamageEvent.DamageCause; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.PlayerInventory; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; +import org.bukkit.util.Vector; + +import mineplex.core.common.util.NautHashMap; +import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; +import mineplex.minecraft.game.core.damage.CustomDamageEvent; +import nautilus.game.arcade.ArcadeManager; +import nautilus.game.arcade.game.games.castlesiege.kits.KitHuman; +import nautilus.game.arcade.kit.KitAvailability; +import nautilus.game.arcade.kit.Perk; + +public class KitPinner extends KitHuman +{ + + public KitPinner(ArcadeManager manager) + { + super(manager, "Pinner", KitAvailability.Hide, new String[] + { + "Your arrows have been enchanted with gravity magic.", "As such, the player will find it hard to lift", + "their body and move around for a few seconds." + }, new Perk[0], EntityType.SKELETON, new ItemStack(Material.OBSIDIAN)); + } + + private NautHashMap _secondsPinned = new NautHashMap(); + + @EventHandler + public void onSecond(UpdateEvent event) + { + if (event.getType() != UpdateType.FASTER) + { + return; + } + + Iterator itel = _secondsPinned.keySet().iterator(); + while (itel.hasNext()) + { + LivingEntity entity = itel.next(); + if (entity.isDead() || (entity instanceof Player && !Manager.IsAlive((Player) entity))) + { + itel.remove(); + continue; + } + entity.setVelocity(entity.getVelocity().add(new Vector(0, -1, 0))); + if (_secondsPinned.get(entity) <= 1) + { + itel.remove(); + } + else + { + _secondsPinned.put(entity, _secondsPinned.get(entity) - 1); + } + } + } + + @EventHandler(ignoreCancelled = true) + public void onDamage(CustomDamageEvent event) + { + if (event.GetCause() == DamageCause.PROJECTILE) + { + Player player = event.GetDamagerPlayer(true); + if (player != null && this.HasKit(player)) + { + LivingEntity entity = event.GetDamageeEntity(); + entity.setVelocity(entity.getVelocity().add(new Vector(0, -1, 0))); + entity.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 40, 1), true); + _secondsPinned.put(entity, 8); + } + } + } + + @Override + public void GiveItems(Player player) + { + PlayerInventory inv = player.getInventory(); + inv.addItem(new ItemBuilder(Material.BLAZE_POWDER).setTitle(ChatColor.GOLD + "Fuse").build()); + inv.addItem(new ItemBuilder(Material.BOW).setUnbreakable(true).addEnchantment(Enchantment.ARROW_INFINITE, 1).build()); + inv.setItem(9, new ItemStack(Material.ARROW, 1)); + } + +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/kits/bow/KitPunch.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/kits/bow/KitPunch.java new file mode 100644 index 000000000..2bb547ed4 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/kits/bow/KitPunch.java @@ -0,0 +1,54 @@ +package nautilus.game.arcade.game.games.searchanddestroy.kits.bow; + +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.entity.EntityDamageEvent.DamageCause; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.PlayerInventory; + +import mineplex.core.itemstack.ItemBuilder; +import mineplex.minecraft.game.core.damage.CustomDamageEvent; +import nautilus.game.arcade.ArcadeManager; +import nautilus.game.arcade.game.games.castlesiege.kits.KitHuman; +import nautilus.game.arcade.kit.KitAvailability; +import nautilus.game.arcade.kit.Perk; + +public class KitPunch extends KitHuman +{ + + public KitPunch(ArcadeManager manager) + { + super(manager, "Punch", KitAvailability.Hide, new String[] + { + "Your bow is super stretchy", "Your arrows are huge", "What does this mean?", + "Your arrows will knock em flying!" + }, new Perk[0], EntityType.SKELETON, new ItemStack(Material.FENCE)); + } + + @EventHandler(ignoreCancelled = true) + public void onDamage(CustomDamageEvent event) + { + if (event.GetCause() == DamageCause.PROJECTILE) + { + Player player = event.GetDamagerPlayer(true); + if (player != null && this.HasKit(player)) + { + event.AddKnockback("Punch", 2.5D); + } + } + } + + @Override + public void GiveItems(Player player) + { + PlayerInventory inv = player.getInventory(); + inv.addItem(new ItemBuilder(Material.BLAZE_POWDER).setTitle(ChatColor.GOLD + "Fuse").build()); + inv.addItem(new ItemBuilder(Material.BOW).setUnbreakable(true).addEnchantment(Enchantment.ARROW_INFINITE, 1).build()); + inv.setItem(9, new ItemStack(Material.ARROW, 1)); + } + +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/kits/bow/KitSniper.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/kits/bow/KitSniper.java new file mode 100644 index 000000000..e2c0fb4e7 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/kits/bow/KitSniper.java @@ -0,0 +1,76 @@ +package nautilus.game.arcade.game.games.searchanddestroy.kits.bow; + +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.Arrow; +import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.entity.Projectile; +import org.bukkit.event.EventHandler; +import org.bukkit.event.entity.ProjectileLaunchEvent; +import org.bukkit.event.entity.EntityDamageEvent.DamageCause; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.PlayerInventory; +import org.bukkit.metadata.FixedMetadataValue; + +import mineplex.core.itemstack.ItemBuilder; +import mineplex.minecraft.game.core.damage.CustomDamageEvent; +import nautilus.game.arcade.ArcadeManager; +import nautilus.game.arcade.game.games.castlesiege.kits.KitHuman; +import nautilus.game.arcade.kit.KitAvailability; +import nautilus.game.arcade.kit.Perk; + +public class KitSniper extends KitHuman +{ + + public KitSniper(ArcadeManager manager) + { + super(manager, "Sniper", KitAvailability.Hide, new String[] + { + "Arrows do 0.1 damage per block travelled.", "Shoot from afar to score major damage!" + }, new Perk[0], EntityType.SKELETON, new ItemStack(Material.ARROW)); + } + + @EventHandler + public void onShoot(ProjectileLaunchEvent event) + { + Projectile entity = event.getEntity(); + if (entity instanceof Arrow && entity.getShooter() instanceof Player && HasKit((Player) entity.getShooter())) + { + entity.setMetadata("ShotFrom", + new FixedMetadataValue(Manager.GetPlugin(), ((Player) entity.getShooter()).getLocation())); + } + } + + @EventHandler(ignoreCancelled = true) + public void onDamage(CustomDamageEvent event) + { + if (event.GetCause() == DamageCause.PROJECTILE) + { + Entity entity = event.GetProjectile(); + if (entity != null && entity.hasMetadata("ShotFrom")) + { + // TODO Remove orig damage + event.AddMod("AntiNormal", "AntiNormal", -event.GetDamageInitial(), false); + event.AddMod( + "Sniper", + "Sniper", + event.GetDamageeEntity().getLocation().distance((Location) entity.getMetadata("ShotFrom").get(0).value()) / 10, + true); + } + } + } + + @Override + public void GiveItems(Player player) + { + PlayerInventory inv = player.getInventory(); + inv.addItem(new ItemBuilder(Material.BLAZE_POWDER).setTitle(ChatColor.GOLD + "Fuse").build()); + inv.addItem(new ItemBuilder(Material.BOW).setUnbreakable(true).addEnchantment(Enchantment.ARROW_INFINITE, 1).build()); + inv.setItem(9, new ItemStack(Material.ARROW, 1)); + } + +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/kits/bow/KitStitcher.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/kits/bow/KitStitcher.java new file mode 100644 index 000000000..3c192cbc3 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/kits/bow/KitStitcher.java @@ -0,0 +1,101 @@ +package nautilus.game.arcade.game.games.searchanddestroy.kits.bow; + +import java.util.Iterator; + +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.entity.EntityDamageEvent.DamageCause; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.PlayerInventory; + +import mineplex.core.common.util.NautHashMap; +import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; +import mineplex.minecraft.game.core.damage.CustomDamageEvent; +import nautilus.game.arcade.ArcadeManager; +import nautilus.game.arcade.game.games.castlesiege.kits.KitHuman; +import nautilus.game.arcade.kit.KitAvailability; +import nautilus.game.arcade.kit.Perk; + +public class KitStitcher extends KitHuman +{ + + private NautHashMap _secondsBleeding = new NautHashMap(); + + public KitStitcher(ArcadeManager manager) + { + super(manager, "Stitcher", KitAvailability.Hide, new String[] + { + "Your arrows tend to hit people in tender places.", + "Its only logical they are going to start bleeding isn't it?" + }, new Perk[0], EntityType.SKELETON, new ItemStack(Material.INK_SACK, 1, (short) 14)); + } + + @EventHandler + public void onSecond(UpdateEvent event) + { + if (event.getType() != UpdateType.SEC) + { + return; + } + + Iterator itel = _secondsBleeding.keySet().iterator(); + while (itel.hasNext()) + { + LivingEntity entity = itel.next(); + if (entity.isDead() || (entity instanceof Player && !Manager.IsAlive((Player) entity))) + { + itel.remove(); + continue; + } + Manager.GetDamage().NewDamageEvent(entity, null, null, DamageCause.CUSTOM, 2, false, true, true, "Bleed", + "Stitcher Bleeding"); + if (_secondsBleeding.get(entity) <= 1) + { + itel.remove(); + } + else + { + _secondsBleeding.put(entity, _secondsBleeding.get(entity) - 1); + } + } + } + + @EventHandler(ignoreCancelled = true) + public void onDamage(CustomDamageEvent event) + { + if (event.GetCause() == DamageCause.PROJECTILE) + { + Player player = event.GetDamagerPlayer(true); + if (player != null && this.HasKit(player)) + { + LivingEntity entity = event.GetDamageeEntity(); + if (!_secondsBleeding.containsKey(entity)) + { + _secondsBleeding.put(entity, 2); + } + else + { + _secondsBleeding.put(entity, _secondsBleeding.get(entity) + 2); + } + } + } + } + + @Override + public void GiveItems(Player player) + { + PlayerInventory inv = player.getInventory(); + inv.addItem(new ItemBuilder(Material.BLAZE_POWDER).setTitle(ChatColor.GOLD + "Fuse").build()); + inv.addItem(new ItemBuilder(Material.BOW).setUnbreakable(true).addEnchantment(Enchantment.ARROW_INFINITE, 1).build()); + inv.setItem(9, new ItemStack(Material.ARROW, 1)); + } + +} From b0e62bfedf36c08a4c71ee233d4cf9187fb1274e Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Sat, 29 Nov 2014 10:51:34 +1300 Subject: [PATCH 29/29] Cleanup imports and rename fields to your _ and non _ --- .../games/searchanddestroy/EvolveButton.java | 6 +- .../games/searchanddestroy/KitEvolve.java | 17 +- .../games/searchanddestroy/KitEvolvePage.java | 38 +-- .../games/searchanddestroy/KitManager.java | 56 ++-- .../searchanddestroy/SearchAndDestroy.java | 159 +++++---- .../game/games/searchanddestroy/TeamBomb.java | 315 +++++++++--------- .../searchanddestroy/kits/bow/KitBow.java | 12 +- .../searchanddestroy/kits/bow/KitPinner.java | 29 +- .../searchanddestroy/kits/bow/KitPunch.java | 14 +- .../searchanddestroy/kits/bow/KitSniper.java | 16 +- .../kits/bow/KitStitcher.java | 23 +- 11 files changed, 339 insertions(+), 346 deletions(-) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/EvolveButton.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/EvolveButton.java index e61cf792c..8bbbb7020 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/EvolveButton.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/EvolveButton.java @@ -1,11 +1,11 @@ package nautilus.game.arcade.game.games.searchanddestroy; -import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer; -import org.bukkit.entity.Player; - import mineplex.core.shop.item.SingleButton; import nautilus.game.arcade.kit.Kit; +import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer; +import org.bukkit.entity.Player; + public class EvolveButton extends SingleButton { private SearchAndDestroy _arcadeManager; diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/KitEvolve.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/KitEvolve.java index 26e8655df..b1c01c939 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/KitEvolve.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/KitEvolve.java @@ -2,28 +2,25 @@ package nautilus.game.arcade.game.games.searchanddestroy; import java.util.ArrayList; -import nautilus.game.arcade.ArcadeManager; +import mineplex.core.MiniPlugin; import nautilus.game.arcade.game.Game.GameState; import nautilus.game.arcade.game.games.searchanddestroy.KitManager.UpgradeKit; import org.bukkit.event.EventHandler; import org.bukkit.event.player.PlayerChatEvent; -import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.plugin.java.JavaPlugin; -import mineplex.core.MiniPlugin; - public class KitEvolve extends MiniPlugin { - private SearchAndDestroy arcadeManager; - private KitEvolveShop kitEvolve; + private SearchAndDestroy _arcadeManager; + private KitEvolveShop _kitEvolve; public KitEvolve(JavaPlugin plugin, SearchAndDestroy manager, ArrayList kits) { super("SnD Kit Evolving", plugin); - arcadeManager = manager; - kitEvolve = new KitEvolveShop(this, manager, manager.getArcadeManager().GetClients(), manager.getArcadeManager() + _arcadeManager = manager; + _kitEvolve = new KitEvolveShop(this, manager, manager.getArcadeManager().GetClients(), manager.getArcadeManager() .GetDonation(), kits); // TODO Auto-generated constructor stub } @@ -31,9 +28,9 @@ public class KitEvolve extends MiniPlugin @EventHandler public void onInteract(PlayerChatEvent event) { - if (arcadeManager.GetState() == GameState.Live) + if (_arcadeManager.GetState() == GameState.Live) { - kitEvolve.attemptShopOpen(event.getPlayer()); + _kitEvolve.attemptShopOpen(event.getPlayer()); } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/KitEvolvePage.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/KitEvolvePage.java index ffb2c58fb..a88659ea2 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/KitEvolvePage.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/KitEvolvePage.java @@ -17,8 +17,8 @@ import org.bukkit.inventory.ItemStack; public class KitEvolvePage extends ShopPageBase { - private SearchAndDestroy _search; private ArrayList _kits; + private SearchAndDestroy _search; public KitEvolvePage(KitEvolve plugin, SearchAndDestroy arcadeManager, KitEvolveShop shop, CoreClientManager clientManager, DonationManager donationManager, Player player, ArrayList kits) @@ -36,57 +36,57 @@ public class KitEvolvePage extends ShopPageBase UpgradeKit kit = null; for (UpgradeKit k : _kits) { - if (k._kit == hisKit) + if (k.kit == hisKit) { kit = k; break; } } boolean canEvolve = true; - AddItem(kit._kitSlot, makeItem(kit._kit)); - for (int slot : kit._path) + AddItem(kit.kitSlot, makeItem(kit.kit)); + for (int slot : kit.path) { AddItem(slot, makeItem(new ItemBuilder(Material.STAINED_GLASS_PANE, 1, (short) 15).setTitle(" ").build())); } - if (kit._daddy != null) + if (kit.daddy != null) { - AddItem(kit._daddy._kitSlot, makeItem(kit._daddy._kit)); - for (int slot : kit._daddy._path) + AddItem(kit.daddy.kitSlot, makeItem(kit.daddy.kit)); + for (int slot : kit.daddy.path) { AddItem(slot, makeItem(new ItemBuilder(Material.STAINED_GLASS_PANE, 1, (short) 15).setTitle(" ").build())); } - if (kit._daddy._daddy != null) + if (kit.daddy.daddy != null) { - AddItem(kit._daddy._daddy._kitSlot, makeItem(kit._daddy._daddy._kit)); + AddItem(kit.daddy.daddy.kitSlot, makeItem(kit.daddy.daddy.kit)); } } if (canEvolve) { - for (UpgradeKit child : kit._children) + for (UpgradeKit child : kit.children) { - for (int slot : child._path) + for (int slot : child.path) AddItem(slot, makeItem(new ItemBuilder(Material.STAINED_GLASS_PANE).setTitle(" ").build())); - AddButton(child._kitSlot, makeItem(child._kit), new EvolveButton(_search, child._kit)); + AddButton(child.kitSlot, makeItem(child.kit), new EvolveButton(_search, child.kit)); } } for (UpgradeKit k : _kits) { - if (getItem(k._kitSlot) == null) + if (getItem(k.kitSlot) == null) { - AddItem(k._kitSlot, makeItem(new ItemBuilder(Material.STONE).setTitle(C.cRed + "Locked").build())); + AddItem(k.kitSlot, makeItem(new ItemBuilder(Material.STONE).setTitle(C.cRed + "Locked").build())); } } } + private ShopItem makeItem(ItemStack item) + { + return new ShopItem(item, "", "", 1, false, false); + } + private ShopItem makeItem(Kit kit) { return new ShopItem(new ItemBuilder(kit.GetItemInHand()).setTitle(kit.GetName()).addLore(kit.GetDesc()).build(), kit.GetName(), kit.GetName(), 1, false, false); } - private ShopItem makeItem(ItemStack item) - { - return new ShopItem(item, "", "", 1, false, false); - } - } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/KitManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/KitManager.java index cccbb6463..8ae7ad5d9 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/KitManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/KitManager.java @@ -2,14 +2,12 @@ package nautilus.game.arcade.game.games.searchanddestroy; import java.util.ArrayList; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; - -import mineplex.core.common.util.C; -import mineplex.core.itemstack.ItemBuilder; import nautilus.game.arcade.ArcadeManager; -import nautilus.game.arcade.game.games.searchanddestroy.kits.bow.*; +import nautilus.game.arcade.game.games.searchanddestroy.kits.bow.KitBow; +import nautilus.game.arcade.game.games.searchanddestroy.kits.bow.KitPinner; +import nautilus.game.arcade.game.games.searchanddestroy.kits.bow.KitPunch; +import nautilus.game.arcade.game.games.searchanddestroy.kits.bow.KitSniper; +import nautilus.game.arcade.game.games.searchanddestroy.kits.bow.KitStitcher; import nautilus.game.arcade.kit.Kit; public class KitManager @@ -17,23 +15,23 @@ public class KitManager public class UpgradeKit { - UpgradeKit _daddy; - Kit _kit; - ArrayList _children; - int[] _path; - int _kitSlot; + ArrayList children; + UpgradeKit daddy; + Kit kit; + int kitSlot; + int[] path; public UpgradeKit(UpgradeKit daddy, Kit me, ArrayList children, int kitSlot, int... pathSlots) { - _kitSlot = kitSlot; - _path = pathSlots; - _daddy = daddy; - _kit = me; - _children = children; + this.kitSlot = kitSlot; + this.path = pathSlots; + this.daddy = daddy; + this.kit = me; + this.children = children; } } - private ArrayList kits = new ArrayList(); + private ArrayList _kits = new ArrayList(); public KitManager(SearchAndDestroy search) { @@ -44,19 +42,19 @@ public class KitManager ArrayList children3 = new ArrayList(); UpgradeKit bow1 = new UpgradeKit(null, new KitBow(man), children1, 4); - kits.add(bow1); + _kits.add(bow1); UpgradeKit bow2 = new UpgradeKit(bow1, new KitStitcher(man), children2, 20, 12); - kits.add(bow2); + _kits.add(bow2); UpgradeKit bow3 = new UpgradeKit(bow1, new KitPunch(man), children3, 24, 14); - kits.add(bow3); + _kits.add(bow3); UpgradeKit bow4 = new UpgradeKit(bow2, new KitSniper(man), new ArrayList(), 46, 29, 37); - kits.add(bow4); + _kits.add(bow4); UpgradeKit bow5 = new UpgradeKit(bow2, new KitBow(man), new ArrayList(), 48, 29, 39); - kits.add(bow5); + _kits.add(bow5); UpgradeKit bow6 = new UpgradeKit(bow3, new KitPinner(man), new ArrayList(), 50, 33, 41); - kits.add(bow6); + _kits.add(bow6); UpgradeKit bow7 = new UpgradeKit(bow3, new KitBow(man), new ArrayList(), 52, 33, 43); - kits.add(bow7); + _kits.add(bow7); children1.add(bow2); children1.add(bow3); children2.add(bow4); @@ -68,19 +66,19 @@ public class KitManager } - public Kit[] getKits() + public Kit[] get_kits() { - Kit[] kitArray = new Kit[kits.size()]; + Kit[] kitArray = new Kit[_kits.size()]; for (int i = 0; i < kitArray.length; i++) { - kitArray[i] = kits.get(i)._kit; + kitArray[i] = _kits.get(i).kit; } return kitArray; } public ArrayList getUpgradeKits() { - return kits; + return _kits; } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/SearchAndDestroy.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/SearchAndDestroy.java index 2e2836d85..82b320f15 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/SearchAndDestroy.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/SearchAndDestroy.java @@ -5,23 +5,6 @@ import java.util.ArrayList; import java.util.HashSet; import java.util.Iterator; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Effect; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.Sound; -import org.bukkit.craftbukkit.v1_7_R4.CraftWorld; -import org.bukkit.entity.Player; -import org.bukkit.entity.TNTPrimed; -import org.bukkit.event.EventHandler; -import org.bukkit.event.HandlerList; -import org.bukkit.event.block.Action; -import org.bukkit.event.entity.EntityDamageEvent.DamageCause; -import org.bukkit.event.player.PlayerInteractEntityEvent; -import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.inventory.ItemStack; - import mineplex.core.common.util.C; import mineplex.core.packethandler.IPacketHandler; import mineplex.core.packethandler.PacketInfo; @@ -39,10 +22,28 @@ import net.minecraft.server.v1_7_R4.Packet; import net.minecraft.server.v1_7_R4.PacketPlayOutEntityDestroy; import net.minecraft.server.v1_7_R4.PacketPlayOutSpawnEntity; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Effect; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.craftbukkit.v1_7_R4.CraftWorld; +import org.bukkit.entity.Player; +import org.bukkit.entity.TNTPrimed; +import org.bukkit.event.EventHandler; +import org.bukkit.event.HandlerList; +import org.bukkit.event.block.Action; +import org.bukkit.event.entity.EntityDamageEvent.DamageCause; +import org.bukkit.event.player.PlayerInteractEntityEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.inventory.ItemStack; + public class SearchAndDestroy extends TeamGame { - private ArrayList _teamBombs = new ArrayList(); + private KitEvolve _evolve; + private KitManager _kitManager = new KitManager(this); private IPacketHandler _teamBombPackets = new IPacketHandler() { @@ -81,12 +82,50 @@ public class SearchAndDestroy extends TeamGame } } }; + private ArrayList _teamBombs = new ArrayList(); + + public SearchAndDestroy(ArcadeManager manager) + { + super(manager, GameType.SearchAndDestroy, new Kit[0], new String[] + { + "A test game of", "Search and Destroy" + }); + setKits(_kitManager.get_kits()); + _evolve = new KitEvolve(manager.GetPlugin(), this, _kitManager.getUpgradeKits()); + InventoryClick = true; + WorldTimeSet = -1; + WorldBoundaryKill = false; + HungerSet = 20; + RepairWeapons = false; + AnnounceJoinQuit = false; + DisableKillCommand = false; + AllowParticles = false; + } public ArrayList getBombs() { return _teamBombs; } + @EventHandler + public void onBombsPacketListener(GameStateChangeEvent event) + { + if (event.GetState() == GameState.Live) + { + for (TeamBomb bomb : getBombs()) + { + bomb.setupHologram(); + } + // this.getArcadeManager().getPacketHandler().addPacketHandler(_teamBombPackets); + // TODO Waiting for client packets to be modifiable + } + else if (event.GetState() == GameState.End) + { + // this.getArcadeManager().getPacketHandler().removePacketHandler(_teamBombPackets); + // TODO Waiting for client packets to be modifiable + } + } + @EventHandler public void onBombTick(UpdateEvent event) { @@ -173,6 +212,7 @@ public class SearchAndDestroy extends TeamGame Bukkit.getScheduler().scheduleSyncDelayedTask(getArcadeManager().GetPlugin(), new Runnable() { + @Override public void run() { try @@ -199,6 +239,27 @@ public class SearchAndDestroy extends TeamGame } } + @EventHandler + public void onGameEnd(GameStateChangeEvent event) + { + if (event.GetState() == GameState.End) + { + HandlerList.unregisterAll(_evolve); + for (TeamBomb bomb : getBombs()) + { + if (bomb.getTeam().IsTeamAlive()) + { + bomb.restoreBomb(); + } + else + { + bomb.removeBomb(); + } + } + getBombs().clear(); + } + } + @EventHandler(ignoreCancelled = true) public void onInteractBombBlock(PlayerInteractEvent event) { @@ -256,68 +317,6 @@ public class SearchAndDestroy extends TeamGame } } - @EventHandler - public void onBombsPacketListener(GameStateChangeEvent event) - { - if (event.GetState() == GameState.Live) - { - for (TeamBomb bomb : getBombs()) - { - bomb.setupHologram(); - } - // this.getArcadeManager().getPacketHandler().addPacketHandler(_teamBombPackets); - // TODO Waiting for client packets to be modifiable - } - else if (event.GetState() == GameState.End) - { - // this.getArcadeManager().getPacketHandler().removePacketHandler(_teamBombPackets); - // TODO Waiting for client packets to be modifiable - } - } - - private KitManager kitManager = new KitManager(this); - - @EventHandler - public void onGameEnd(GameStateChangeEvent event) - { - if (event.GetState() == GameState.End) - { - HandlerList.unregisterAll(evolve); - for (TeamBomb bomb : getBombs()) - { - if (bomb.getTeam().IsTeamAlive()) - { - bomb.restoreBomb(); - } - else - { - bomb.removeBomb(); - } - } - getBombs().clear(); - } - } - - private KitEvolve evolve; - - public SearchAndDestroy(ArcadeManager manager) - { - super(manager, GameType.SearchAndDestroy, new Kit[0], new String[] - { - "A test game of", "Search and Destroy" - }); - setKits(kitManager.getKits()); - evolve = new KitEvolve(manager.GetPlugin(), this, kitManager.getUpgradeKits()); - InventoryClick = true; - WorldTimeSet = -1; - WorldBoundaryKill = false; - HungerSet = 20; - RepairWeapons = false; - AnnounceJoinQuit = false; - DisableKillCommand = false; - AllowParticles = false; - } - @Override public void ParseData() { diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/TeamBomb.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/TeamBomb.java index b0ab66038..6080f387e 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/TeamBomb.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/TeamBomb.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.Random; + import mineplex.core.common.util.C; import mineplex.core.common.util.UtilEnt; import mineplex.core.hologram.Hologram; @@ -29,8 +30,8 @@ class TeamBomb implements Comparable private ArrayList _armers = new ArrayList(); private long _firstArmed = System.currentTimeMillis(); private long _lastInteract; - private int _timeToArmBomb = 4; private GameTeam _owningTeam; + private int _timeToArmBomb = 4; public ArmInfo(GameTeam team) { @@ -79,46 +80,16 @@ class TeamBomb implements Comparable } - private Location _bombLocation; + private ArrayList _armers = new ArrayList(); private TNTPrimed _bombEntity; - private int _timeUntilExplode; - private long _timeBombArmed; + private Location _bombLocation; + private final int _entityId = UtilEnt.getNewEntityId(); + private SearchAndDestroy _game; + private Hologram _hologram; private long _lastHiss; private GameTeam _owningTeam; - private ArrayList _armers = new ArrayList(); - private SearchAndDestroy _game; - private final int _entityId = UtilEnt.getNewEntityId(); - private Hologram _hologram; - - public int getFakeBombId() - { - return _entityId; - } - - public int getTimeUntilExplode() - { - return _timeUntilExplode; - } - - public boolean isArmed() - { - return _bombEntity != null; - } - - public TNTPrimed getBomb() - { - return _bombEntity; - } - - public GameTeam getTeam() - { - return _owningTeam; - } - - public Location getBlockLocation() - { - return _bombLocation; - } + private long _timeBombArmed; + private int _timeUntilExplode; public TeamBomb(ArcadeManager manager, SearchAndDestroy game, GameTeam owningTeam, Location bombLocation) { @@ -127,88 +98,6 @@ class TeamBomb implements Comparable this._bombLocation = bombLocation; } - public void checkArmers() - { - Iterator armers = _armers.iterator(); - while (armers.hasNext()) - { - ArmInfo info = armers.next(); - if (!info.isValid()) - { - armers.remove(); - } - } - } - - public void onInteractWithFuse(Player player) - { - GameTeam hisTeam = _game.GetTeam(player); - if (hisTeam != null) - { - if (_owningTeam == hisTeam) - { - if (_bombEntity == null) - { - player.sendMessage(C.cRed + "You cannot arm your bomb"); - } - else - { - onInteract(hisTeam, player); - } - } - else - { - if (_bombEntity != null) - { - player.sendMessage(C.cRed + "You cannot disarm their bomb"); - } - else - { - onInteract(hisTeam, player); - } - } - } - } - - private void onInteract(GameTeam gTeam, Player p) - { - if (_lastHiss + 500 <= System.currentTimeMillis()) - { - p.getWorld().playSound(p.getLocation(), Sound.FIZZ, 1, 0); - _lastHiss = System.currentTimeMillis(); - } - p.getWorld() - .spigot() - .playEffect(_bombEntity == null ? _bombLocation.clone().add(0, 1.1, 0) : _bombEntity.getLocation().add(0, 1, 0), - Effect.LARGE_SMOKE, 0, 0, 0.1F, 0.05F, 0.1F, 0, 3, 30); - ArmInfo info = null; - for (ArmInfo arm : _armers) - { - if (arm._owningTeam == gTeam) - { - info = arm; - break; - } - } - if (info != null && !info.isValid()) - { - _armers.remove(info); - info = null; - } - if (info == null) - { - info = new ArmInfo(gTeam); - _armers.add(info); - } - info.addArmer(p); - info._lastInteract = System.currentTimeMillis(); - if (info.isFused()) - { - activateBomb(gTeam); - return; - } - } - private void activateBomb(GameTeam gameTeam) { if (!isArmed()) @@ -256,6 +145,19 @@ class TeamBomb implements Comparable _armers.clear(); } + public void checkArmers() + { + Iterator armers = _armers.iterator(); + while (armers.hasNext()) + { + ArmInfo info = armers.next(); + if (!info.isValid()) + { + armers.remove(); + } + } + } + @Override public int compareTo(TeamBomb o) { @@ -270,6 +172,120 @@ class TeamBomb implements Comparable return -1; } + public Location getBlockLocation() + { + return _bombLocation; + } + + public TNTPrimed getBomb() + { + return _bombEntity; + } + + public int getFakeBombId() + { + return _entityId; + } + + public GameTeam getTeam() + { + return _owningTeam; + } + + public int getTimeUntilExplode() + { + return _timeUntilExplode; + } + + public boolean isArmed() + { + return _bombEntity != null; + } + + private void onInteract(GameTeam gTeam, Player p) + { + if (_lastHiss + 500 <= System.currentTimeMillis()) + { + p.getWorld().playSound(p.getLocation(), Sound.FIZZ, 1, 0); + _lastHiss = System.currentTimeMillis(); + } + p.getWorld() + .spigot() + .playEffect(_bombEntity == null ? _bombLocation.clone().add(0, 1.1, 0) : _bombEntity.getLocation().add(0, 1, 0), + Effect.LARGE_SMOKE, 0, 0, 0.1F, 0.05F, 0.1F, 0, 3, 30); + ArmInfo info = null; + for (ArmInfo arm : _armers) + { + if (arm._owningTeam == gTeam) + { + info = arm; + break; + } + } + if (info != null && !info.isValid()) + { + _armers.remove(info); + info = null; + } + if (info == null) + { + info = new ArmInfo(gTeam); + _armers.add(info); + } + info.addArmer(p); + info._lastInteract = System.currentTimeMillis(); + if (info.isFused()) + { + activateBomb(gTeam); + return; + } + } + + public void onInteractWithFuse(Player player) + { + GameTeam hisTeam = _game.GetTeam(player); + if (hisTeam != null) + { + if (_owningTeam == hisTeam) + { + if (_bombEntity == null) + { + player.sendMessage(C.cRed + "You cannot arm your bomb"); + } + else + { + onInteract(hisTeam, player); + } + } + else + { + if (_bombEntity != null) + { + player.sendMessage(C.cRed + "You cannot disarm their bomb"); + } + else + { + onInteract(hisTeam, player); + } + } + } + } + + /** + * Sets the bomb block to air and removes the hologram and bomb entity + */ + public void removeBomb() + { + _armers.clear(); + _hologram.stop(); + getBlockLocation().getBlock().setType(Material.AIR); + if (getBomb() != null) + { + this.getBomb().remove(); + _bombEntity = null; + } + } + /** * Sets the bomb block to tnt, updates the hologram and removes the bomb entity */ @@ -287,6 +303,28 @@ class TeamBomb implements Comparable } } + public void setupHologram() + { + _hologram = new Hologram(this._game.getArcadeManager().getHologramManager(), getBlockLocation().clone().add(0, 1, 0)) + .setUsesWitherSkull(); + _hologram.setText(getTeam().GetColor() + C.Bold + getTeam().GetName() + " Team's Bomb"); + _hologram.start(); + } + + public void tickBomb() + { + if (_bombEntity != null) + { + _timeUntilExplode--; + _bombEntity.getWorld().playSound(_bombEntity.getLocation(), Sound.CREEPER_DEATH, 1.85F, 1.2F); + if (this._armers.isEmpty()) + { + _hologram.setText(getTeam().GetColor() + C.Bold + "Exploding in " + ChatColor.DARK_RED + C.Bold + + this.getTimeUntilExplode()); + } + } + } + public void updateBombHologram() { if (!_armers.isEmpty()) @@ -322,41 +360,4 @@ class TeamBomb implements Comparable } } - /** - * Sets the bomb block to air and removes the hologram and bomb entity - */ - public void removeBomb() - { - _armers.clear(); - _hologram.stop(); - getBlockLocation().getBlock().setType(Material.AIR); - if (getBomb() != null) - { - this.getBomb().remove(); - _bombEntity = null; - } - } - - public void setupHologram() - { - _hologram = new Hologram(this._game.getArcadeManager().getHologramManager(), getBlockLocation().clone().add(0, 1, 0)) - .setUsesWitherSkull(); - _hologram.setText(getTeam().GetColor() + C.Bold + getTeam().GetName() + " Team's Bomb"); - _hologram.start(); - } - - public void tickBomb() - { - if (_bombEntity != null) - { - _timeUntilExplode--; - _bombEntity.getWorld().playSound(_bombEntity.getLocation(), Sound.CREEPER_DEATH, 1.85F, 1.2F); - if (this._armers.isEmpty()) - { - _hologram.setText(getTeam().GetColor() + C.Bold + "Exploding in " + ChatColor.DARK_RED + C.Bold - + this.getTimeUntilExplode()); - } - } - } - } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/kits/bow/KitBow.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/kits/bow/KitBow.java index 376898caa..51cbdae09 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/kits/bow/KitBow.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/kits/bow/KitBow.java @@ -1,5 +1,11 @@ package nautilus.game.arcade.game.games.searchanddestroy.kits.bow; +import mineplex.core.itemstack.ItemBuilder; +import nautilus.game.arcade.ArcadeManager; +import nautilus.game.arcade.game.games.castlesiege.kits.KitHuman; +import nautilus.game.arcade.kit.KitAvailability; +import nautilus.game.arcade.kit.Perk; + import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.enchantments.Enchantment; @@ -8,12 +14,6 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; -import mineplex.core.itemstack.ItemBuilder; -import nautilus.game.arcade.ArcadeManager; -import nautilus.game.arcade.game.games.castlesiege.kits.KitHuman; -import nautilus.game.arcade.kit.KitAvailability; -import nautilus.game.arcade.kit.Perk; - public class KitBow extends KitHuman { diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/kits/bow/KitPinner.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/kits/bow/KitPinner.java index e1518e2ba..e9a53a2a4 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/kits/bow/KitPinner.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/kits/bow/KitPinner.java @@ -2,21 +2,6 @@ package nautilus.game.arcade.game.games.searchanddestroy.kits.bow; import java.util.Iterator; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.entity.Entity; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.entity.EntityDamageEvent.DamageCause; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.PlayerInventory; -import org.bukkit.potion.PotionEffect; -import org.bukkit.potion.PotionEffectType; -import org.bukkit.util.Vector; - import mineplex.core.common.util.NautHashMap; import mineplex.core.itemstack.ItemBuilder; import mineplex.core.updater.UpdateType; @@ -27,6 +12,20 @@ import nautilus.game.arcade.game.games.castlesiege.kits.KitHuman; import nautilus.game.arcade.kit.KitAvailability; import nautilus.game.arcade.kit.Perk; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.entity.EntityDamageEvent.DamageCause; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.PlayerInventory; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; +import org.bukkit.util.Vector; + public class KitPinner extends KitHuman { diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/kits/bow/KitPunch.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/kits/bow/KitPunch.java index 2bb547ed4..5d387ffd5 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/kits/bow/KitPunch.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/kits/bow/KitPunch.java @@ -1,5 +1,12 @@ package nautilus.game.arcade.game.games.searchanddestroy.kits.bow; +import mineplex.core.itemstack.ItemBuilder; +import mineplex.minecraft.game.core.damage.CustomDamageEvent; +import nautilus.game.arcade.ArcadeManager; +import nautilus.game.arcade.game.games.castlesiege.kits.KitHuman; +import nautilus.game.arcade.kit.KitAvailability; +import nautilus.game.arcade.kit.Perk; + import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.enchantments.Enchantment; @@ -10,13 +17,6 @@ import org.bukkit.event.entity.EntityDamageEvent.DamageCause; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; -import mineplex.core.itemstack.ItemBuilder; -import mineplex.minecraft.game.core.damage.CustomDamageEvent; -import nautilus.game.arcade.ArcadeManager; -import nautilus.game.arcade.game.games.castlesiege.kits.KitHuman; -import nautilus.game.arcade.kit.KitAvailability; -import nautilus.game.arcade.kit.Perk; - public class KitPunch extends KitHuman { diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/kits/bow/KitSniper.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/kits/bow/KitSniper.java index e2c0fb4e7..11b74ae49 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/kits/bow/KitSniper.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/kits/bow/KitSniper.java @@ -1,5 +1,12 @@ package nautilus.game.arcade.game.games.searchanddestroy.kits.bow; +import mineplex.core.itemstack.ItemBuilder; +import mineplex.minecraft.game.core.damage.CustomDamageEvent; +import nautilus.game.arcade.ArcadeManager; +import nautilus.game.arcade.game.games.castlesiege.kits.KitHuman; +import nautilus.game.arcade.kit.KitAvailability; +import nautilus.game.arcade.kit.Perk; + import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.Material; @@ -10,19 +17,12 @@ import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.entity.Projectile; import org.bukkit.event.EventHandler; -import org.bukkit.event.entity.ProjectileLaunchEvent; import org.bukkit.event.entity.EntityDamageEvent.DamageCause; +import org.bukkit.event.entity.ProjectileLaunchEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; import org.bukkit.metadata.FixedMetadataValue; -import mineplex.core.itemstack.ItemBuilder; -import mineplex.minecraft.game.core.damage.CustomDamageEvent; -import nautilus.game.arcade.ArcadeManager; -import nautilus.game.arcade.game.games.castlesiege.kits.KitHuman; -import nautilus.game.arcade.kit.KitAvailability; -import nautilus.game.arcade.kit.Perk; - public class KitSniper extends KitHuman { diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/kits/bow/KitStitcher.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/kits/bow/KitStitcher.java index 3c192cbc3..8ecc6e31b 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/kits/bow/KitStitcher.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/searchanddestroy/kits/bow/KitStitcher.java @@ -2,18 +2,6 @@ package nautilus.game.arcade.game.games.searchanddestroy.kits.bow; import java.util.Iterator; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.entity.Entity; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.entity.EntityDamageEvent.DamageCause; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.PlayerInventory; - import mineplex.core.common.util.NautHashMap; import mineplex.core.itemstack.ItemBuilder; import mineplex.core.updater.UpdateType; @@ -24,6 +12,17 @@ import nautilus.game.arcade.game.games.castlesiege.kits.KitHuman; import nautilus.game.arcade.kit.KitAvailability; import nautilus.game.arcade.kit.Perk; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.entity.EntityDamageEvent.DamageCause; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.PlayerInventory; + public class KitStitcher extends KitHuman {