Merge branch 'master' of ssh://184.154.0.242:7999/min/Mineplex
This commit is contained in:
commit
54aefbf40d
@ -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<Player, NautHashMap<Integer, String>> _entityNameMap = new NautHashMap<Player, NautHashMap<Integer, String>>();
|
||||
private NautHashMap<Player, NautHashMap<Integer, Integer>> _entityVehicleMap = new NautHashMap<Player, NautHashMap<Integer, Integer>>();
|
||||
private NautHashMap<Player, Long> _loggedIn = new NautHashMap<Player, Long>();
|
||||
private HashSet<Integer> _ignoreSkulls = new HashSet<Integer>();
|
||||
|
||||
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)
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -1,68 +1,644 @@
|
||||
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.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;
|
||||
|
||||
import mineplex.core.common.util.UtilEnt;
|
||||
import mineplex.core.common.util.UtilPlayer;
|
||||
|
||||
/**
|
||||
* Created by shaun on 2014-09-09.
|
||||
*/
|
||||
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<Entry<Integer, Integer>> _entityIds = new ArrayList<Entry<Integer, Integer>>();
|
||||
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.
|
||||
*/
|
||||
private Vector _lastMovement;
|
||||
private Location _location;
|
||||
private boolean _makePackets = true;
|
||||
private Packet[] _packets1_7;
|
||||
private Packet[] _packets1_8;
|
||||
private HashSet<String> _playersInList = new HashSet<String>();
|
||||
private ArrayList<Player> _playersTracking = new ArrayList<Player>();
|
||||
private HologramTarget _target = HologramTarget.BLACKLIST;
|
||||
private String[] _text = new String[0];
|
||||
private int _viewDistance = 70;
|
||||
protected Vector relativeToEntity;
|
||||
|
||||
_horseHologram = new HorseHologram(location, text);
|
||||
_armorStandHologram = new ArmorStandHologram(location, text);
|
||||
}
|
||||
public Hologram(HologramManager hologramManager, Location location, String... text)
|
||||
{
|
||||
_hologramManager = hologramManager;
|
||||
_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);
|
||||
}
|
||||
|
||||
protected Packet getDestroyPacket(Player player)
|
||||
{
|
||||
if (_destroyPackets)
|
||||
{
|
||||
makeDestroyPacket();
|
||||
_destroyPackets = false;
|
||||
}
|
||||
return UtilPlayer.is1_8(player) ? _destroy1_8 : _destroy1_7;
|
||||
}
|
||||
|
||||
public Entity getEntityFollowing()
|
||||
{
|
||||
return _followEntity;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
|
||||
protected ArrayList<Player> getNearbyPlayers()
|
||||
{
|
||||
ArrayList<Player> nearbyPlayers = new ArrayList<Player>();
|
||||
for (Player player : getLocation().getWorld().getPlayers())
|
||||
{
|
||||
if (isVisible(player))
|
||||
{
|
||||
nearbyPlayers.add(player);
|
||||
}
|
||||
}
|
||||
return nearbyPlayers;
|
||||
}
|
||||
|
||||
protected ArrayList<Player> getPlayersTracking()
|
||||
{
|
||||
return _playersTracking;
|
||||
}
|
||||
|
||||
protected 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 _lastMovement != 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<Integer, Integer> 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<Integer, Integer> 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
* @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();
|
||||
// TODO Needs to set the new relativeToEntity
|
||||
if (getEntityFollowing() != null)
|
||||
{
|
||||
relativeToEntity = _location.clone().subtract(getEntityFollowing().getLocation()).toVector();
|
||||
}
|
||||
if (isInUse())
|
||||
{
|
||||
ArrayList<Player> canSee = getNearbyPlayers();
|
||||
Iterator<Player> 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<Integer, Integer> 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<Integer, Integer> 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<Packet> packets1_7 = new ArrayList<Packet>();
|
||||
int[] destroy1_7 = new int[0];
|
||||
int[] destroy1_8 = new int[0];
|
||||
ArrayList<Packet> packets1_8 = new ArrayList<Packet>();
|
||||
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<Integer, Integer> 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<Integer, Integer> 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<Integer, Integer> 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())
|
||||
{
|
||||
_hologramManager.addHologram(this);
|
||||
_playersTracking.addAll(getNearbyPlayers());
|
||||
for (Player player : _playersTracking)
|
||||
{
|
||||
for (Packet packet : getSpawnPackets(player))
|
||||
{
|
||||
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
|
||||
}
|
||||
}
|
||||
_lastMovement = new Vector();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop the hologram
|
||||
*/
|
||||
public Hologram stop()
|
||||
{
|
||||
if (isInUse())
|
||||
{
|
||||
_hologramManager.removeHologram(this);
|
||||
for (Player player : _playersTracking)
|
||||
{
|
||||
((CraftPlayer) player).getHandle().playerConnection.sendPacket(getDestroyPacket(player));
|
||||
}
|
||||
_playersTracking.clear();
|
||||
_lastMovement = null;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,98 @@
|
||||
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.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
|
||||
{
|
||||
private ArrayList<Hologram> _activeHolograms = new ArrayList<Hologram>();
|
||||
|
||||
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<World> worlds = Bukkit.getWorlds();
|
||||
Iterator<Hologram> itel = _activeHolograms.iterator();
|
||||
while (itel.hasNext())
|
||||
{
|
||||
Hologram hologram = itel.next();
|
||||
if (!worlds.contains(hologram.getLocation().getWorld()))
|
||||
{
|
||||
itel.remove();
|
||||
hologram.stop();
|
||||
}
|
||||
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<Player> canSee = hologram.getNearbyPlayers();
|
||||
Iterator<Player> itel2 = hologram.getPlayersTracking().iterator();
|
||||
while (itel2.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
@ -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<Character, ArrayList<Integer>> placing = new HashMap<Character, ArrayList<Integer>>();
|
||||
|
||||
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<Integer>());
|
||||
}
|
||||
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<Integer>());
|
||||
}
|
||||
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<ItemStack> items, boolean replaceExistingItems)
|
||||
{
|
||||
return generate(toReplace, items.toArray(new ItemStack[0]), replaceExistingItems);
|
||||
}
|
||||
|
||||
public ItemStack[] generate(ItemStack[] existingItems, char toReplace, ItemStack[] items, boolean replaceExistingItems)
|
||||
{
|
||||
ArrayList<Integer> 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<Integer> 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);
|
||||
}
|
||||
|
||||
}
|
@ -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<String> split(String string, int maxLength)
|
||||
{
|
||||
String[] split = string.split(" ");
|
||||
string = "";
|
||||
ArrayList<String> newString = new ArrayList<String>();
|
||||
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<Enchantment, Integer> _enchants = new HashMap<Enchantment, Integer>();
|
||||
private final List<String> _lore = new ArrayList<String>();
|
||||
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<String> lores)
|
||||
{
|
||||
this._lore.addAll(lores);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemBuilder addLores(List<String> 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<Enchantment, Integer> entry : this._enchants.entrySet())
|
||||
{
|
||||
newBuilder.addEnchantment(entry.getKey(), entry.getValue());
|
||||
}
|
||||
newBuilder.setColor(this._color);
|
||||
// newBuilder.potion = this.potion;
|
||||
|
||||
return newBuilder;
|
||||
}
|
||||
|
||||
public HashMap<Enchantment, Integer> 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<String> 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<String> 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;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
package mineplex.core.itemstack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class ItemLayout
|
||||
{
|
||||
|
||||
private int _invSize = 0;
|
||||
private ArrayList<Integer> _size = new ArrayList<Integer>();
|
||||
|
||||
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<ItemStack> items)
|
||||
{
|
||||
return generate(items.toArray(new ItemStack[0]));
|
||||
}
|
||||
|
||||
public ItemStack[] generate(ItemStack... items)
|
||||
{
|
||||
return generate(true, items);
|
||||
}
|
||||
|
||||
public ItemStack[] generate(boolean doRepeats, ItemStack... items)
|
||||
{
|
||||
ItemStack[] itemArray = new ItemStack[_invSize];
|
||||
if (items.length == 0)
|
||||
return itemArray;
|
||||
int i = 0;
|
||||
for (int slot : _size)
|
||||
{
|
||||
if (i < items.length)
|
||||
{
|
||||
if (doRepeats)
|
||||
i = 0;
|
||||
else
|
||||
break;
|
||||
}
|
||||
itemArray[slot] = items[i];
|
||||
|
||||
}
|
||||
return itemArray;
|
||||
}
|
||||
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -88,4 +88,9 @@ public class PacketVerifier implements IPacketVerifier
|
||||
{
|
||||
_packetHandlers.add(packetHandler);
|
||||
}
|
||||
|
||||
public void removePacketHandler(IPacketHandler packetHandler)
|
||||
{
|
||||
_packetHandlers.remove(packetHandler);
|
||||
}
|
||||
}
|
||||
|
@ -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<PluginType extends MiniPlugin> 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.m();
|
||||
}
|
||||
player.openInventory(page);
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
@ -26,13 +27,16 @@ public class ShopItem extends CraftItemStack
|
||||
_deliveryName = deliveryName;
|
||||
_displayItem = displayItem;
|
||||
_deliveryAmount = deliveryAmount;
|
||||
_lore = itemStack.getItemMeta().getLore().toArray(new String[0]);
|
||||
|
||||
CraftItemStack craftItem = CraftItemStack.asCraftCopy(itemStack);
|
||||
getHandle().tag = craftItem.getHandle().tag;
|
||||
if (itemStack.getItemMeta().hasLore())
|
||||
_lore = itemStack.getItemMeta().getLore().toArray(new String[0]);
|
||||
else
|
||||
_lore = new String[0];
|
||||
|
||||
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)
|
||||
@ -93,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()
|
||||
@ -108,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()
|
||||
@ -119,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<String> lore = new ArrayList<String>();
|
||||
|
||||
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()
|
||||
@ -188,17 +182,19 @@ public class ShopItem extends CraftItemStack
|
||||
{
|
||||
_lore = string;
|
||||
|
||||
NBTTagList lore = new NBTTagList();
|
||||
ArrayList<String> lore = new ArrayList<String>();
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -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<Animation> _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<Animation>();
|
||||
_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
|
||||
|
@ -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<Player, Treasure>();
|
||||
_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);
|
||||
|
@ -1,5 +1,13 @@
|
||||
package mineplex.core.treasure.animation;
|
||||
|
||||
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;
|
||||
import org.bukkit.block.Block;
|
||||
@ -8,64 +16,61 @@ 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 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.
|
||||
*/
|
||||
public class ChestOpenAnimation extends Animation
|
||||
{
|
||||
private ChestData _chestData;
|
||||
private RewardData _rewardData;
|
||||
private ChestData _chestData;
|
||||
private RewardData _rewardData;
|
||||
private HologramManager _hologramManager;
|
||||
|
||||
private Item _itemEntity;
|
||||
private Hologram _hologram;
|
||||
private Item _itemEntity;
|
||||
private Hologram _hologram;
|
||||
|
||||
public ChestOpenAnimation(Treasure treasure, ChestData chestData, RewardData rewardData)
|
||||
{
|
||||
super(treasure);
|
||||
_chestData = chestData;
|
||||
_rewardData = rewardData;
|
||||
public ChestOpenAnimation(Treasure treasure, ChestData chestData, RewardData rewardData, HologramManager hologramManager)
|
||||
{
|
||||
super(treasure);
|
||||
_hologramManager = hologramManager;
|
||||
_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 = new Hologram(_hologramManager, _chestData.getBlock().getLocation().add(0.5, 1.1, 0.5),
|
||||
_rewardData.getFriendlyName());
|
||||
_hologram.start();
|
||||
}
|
||||
}
|
||||
|
||||
public void onFinish()
|
||||
{
|
||||
if (_hologram != null)
|
||||
{
|
||||
_hologram.removeForPlayers(_chestData.getBlock().getLocation().getWorld().getPlayers().toArray(new Player[0]));
|
||||
_itemEntity.remove();
|
||||
}
|
||||
}
|
||||
public void onFinish()
|
||||
{
|
||||
if (_hologram != null)
|
||||
{
|
||||
_hologram.stop();
|
||||
_itemEntity.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,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;
|
||||
@ -101,7 +102,7 @@ public class Hub extends JavaPlugin implements IRelation
|
||||
DisguiseManager disguiseManager = new DisguiseManager(this, packetHandler);
|
||||
StatsManager statsManager = new StatsManager(this, clientManager);
|
||||
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, clientManager), partyManager);
|
||||
|
||||
|
@ -64,6 +64,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;
|
||||
@ -143,7 +144,7 @@ public class HubManager extends MiniClientPlugin<HubClient>
|
||||
//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);
|
||||
|
||||
@ -174,7 +175,7 @@ public class HubManager extends MiniClientPlugin<HubClient>
|
||||
_inventoryManager = new InventoryManager(plugin, clientManager);
|
||||
new BenefitManager(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;
|
||||
|
@ -20,6 +20,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;
|
||||
@ -107,6 +108,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, _clientManager);
|
||||
@ -117,7 +119,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), portal, preferenceManager, inventoryManager, packetHandler, cosmeticManager, projectileManager, petManager, webServerAddress);
|
||||
_gameManager = new ArcadeManager(this, serverStatusManager, ReadServerConfig(), _clientManager, _donationManager, _damageManager, disguiseManager, creature, teleport, new Blood(this), portal, preferenceManager, inventoryManager, packetHandler, cosmeticManager, projectileManager, petManager, hologramManager, webServerAddress);
|
||||
|
||||
new MemoryFix(this);
|
||||
new CustomTagFix(this, packetHandler);
|
||||
|
@ -54,6 +54,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;
|
||||
@ -145,7 +146,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;
|
||||
@ -154,7 +155,8 @@ public class ArcadeManager extends MiniPlugin implements IRelation
|
||||
private ClassCombatShop _classShop;
|
||||
private TaskManager _taskManager;
|
||||
private ArcadeRepository _arcadeRepository;
|
||||
|
||||
private PacketHandler _packetHandler;
|
||||
|
||||
private EloManager _eloManager;
|
||||
|
||||
// Observers
|
||||
@ -173,7 +175,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation
|
||||
CoreClientManager clientManager, DonationManager donationManager, DamageManager damageManager,
|
||||
DisguiseManager disguiseManager, Creature creature, Teleport teleport, Blood blood,
|
||||
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);
|
||||
|
||||
@ -214,6 +216,8 @@ public class ArcadeManager extends MiniPlugin implements IRelation
|
||||
_fire = new Fire(plugin, _conditionManager, damageManager);
|
||||
|
||||
_projectileManager = projectileManager;
|
||||
|
||||
_packetHandler = packetHandler;
|
||||
|
||||
_statsManager = new StatsManager(plugin, clientManager);
|
||||
_taskManager = new TaskManager(plugin, webAddress);
|
||||
@ -244,6 +248,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);
|
||||
|
||||
@ -325,6 +330,11 @@ public class ArcadeManager extends MiniPlugin implements IRelation
|
||||
{
|
||||
return _creature;
|
||||
}
|
||||
|
||||
public PacketHandler getPacketHandler()
|
||||
{
|
||||
return _packetHandler;
|
||||
}
|
||||
|
||||
public CosmeticManager getCosmeticManager()
|
||||
{
|
||||
@ -335,6 +345,11 @@ public class ArcadeManager extends MiniPlugin implements IRelation
|
||||
{
|
||||
return _disguiseManager;
|
||||
}
|
||||
|
||||
public HologramManager getHologramManager()
|
||||
{
|
||||
return _hologramManager;
|
||||
}
|
||||
|
||||
public DamageManager GetDamage()
|
||||
{
|
||||
|
@ -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);
|
||||
|
@ -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"),
|
||||
|
@ -0,0 +1,30 @@
|
||||
package nautilus.game.arcade.game.games.searchanddestroy;
|
||||
|
||||
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;
|
||||
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();
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package nautilus.game.arcade.game.games.searchanddestroy;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
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.plugin.java.JavaPlugin;
|
||||
|
||||
public class KitEvolve extends MiniPlugin
|
||||
{
|
||||
|
||||
private SearchAndDestroy _arcadeManager;
|
||||
private KitEvolveShop _kitEvolve;
|
||||
|
||||
public KitEvolve(JavaPlugin plugin, SearchAndDestroy manager, ArrayList<UpgradeKit> 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());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,92 @@
|
||||
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<KitEvolve, KitEvolveShop>
|
||||
{
|
||||
private ArrayList<UpgradeKit> _kits;
|
||||
private SearchAndDestroy _search;
|
||||
|
||||
public KitEvolvePage(KitEvolve plugin, SearchAndDestroy arcadeManager, KitEvolveShop shop, CoreClientManager clientManager,
|
||||
DonationManager donationManager, Player player, ArrayList<UpgradeKit> 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(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);
|
||||
}
|
||||
|
||||
}
|
@ -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<KitEvolve>
|
||||
{
|
||||
|
||||
private SearchAndDestroy _arcadeManager;
|
||||
private ArrayList<UpgradeKit> _kits;
|
||||
|
||||
public KitEvolveShop(KitEvolve plugin, SearchAndDestroy arcadeManager, CoreClientManager clientManager,
|
||||
DonationManager donationManager, ArrayList<UpgradeKit> kits, CurrencyType... currencyTypes)
|
||||
{
|
||||
super(plugin, clientManager, donationManager, "Kit Evolve Menu", currencyTypes);
|
||||
_arcadeManager = arcadeManager;
|
||||
_kits = kits;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ShopPageBase<KitEvolve, ? extends ShopBase<KitEvolve>> BuildPagesFor(Player player)
|
||||
{
|
||||
return new KitEvolvePage(Plugin, _arcadeManager, this, ClientManager, DonationManager, player, _kits);
|
||||
}
|
||||
|
||||
public void update()
|
||||
{
|
||||
for (ShopPageBase<KitEvolve, ? extends ShopBase<KitEvolve>> shopPage : PlayerPageMap.values())
|
||||
{
|
||||
shopPage.Refresh();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,84 @@
|
||||
package nautilus.game.arcade.game.games.searchanddestroy;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import nautilus.game.arcade.ArcadeManager;
|
||||
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
|
||||
{
|
||||
|
||||
public class UpgradeKit
|
||||
{
|
||||
ArrayList<UpgradeKit> children;
|
||||
UpgradeKit daddy;
|
||||
Kit kit;
|
||||
int kitSlot;
|
||||
int[] path;
|
||||
|
||||
public UpgradeKit(UpgradeKit daddy, Kit me, ArrayList<UpgradeKit> children, int kitSlot, int... pathSlots)
|
||||
{
|
||||
this.kitSlot = kitSlot;
|
||||
this.path = pathSlots;
|
||||
this.daddy = daddy;
|
||||
this.kit = me;
|
||||
this.children = children;
|
||||
}
|
||||
}
|
||||
|
||||
private ArrayList<UpgradeKit> _kits = new ArrayList<UpgradeKit>();
|
||||
|
||||
public KitManager(SearchAndDestroy search)
|
||||
{
|
||||
ArcadeManager man = search.getArcadeManager();
|
||||
{
|
||||
ArrayList<UpgradeKit> children1 = new ArrayList<UpgradeKit>();
|
||||
ArrayList<UpgradeKit> children2 = new ArrayList<UpgradeKit>();
|
||||
ArrayList<UpgradeKit> children3 = new ArrayList<UpgradeKit>();
|
||||
|
||||
UpgradeKit bow1 = new UpgradeKit(null, new KitBow(man), children1, 4);
|
||||
_kits.add(bow1);
|
||||
UpgradeKit bow2 = new UpgradeKit(bow1, new KitStitcher(man), children2, 20, 12);
|
||||
_kits.add(bow2);
|
||||
UpgradeKit bow3 = new UpgradeKit(bow1, new KitPunch(man), children3, 24, 14);
|
||||
_kits.add(bow3);
|
||||
UpgradeKit bow4 = new UpgradeKit(bow2, new KitSniper(man), new ArrayList<UpgradeKit>(), 46, 29, 37);
|
||||
_kits.add(bow4);
|
||||
UpgradeKit bow5 = new UpgradeKit(bow2, new KitBow(man), new ArrayList<UpgradeKit>(), 48, 29, 39);
|
||||
_kits.add(bow5);
|
||||
UpgradeKit bow6 = new UpgradeKit(bow3, new KitPinner(man), new ArrayList<UpgradeKit>(), 50, 33, 41);
|
||||
_kits.add(bow6);
|
||||
UpgradeKit bow7 = new UpgradeKit(bow3, new KitBow(man), new ArrayList<UpgradeKit>(), 52, 33, 43);
|
||||
_kits.add(bow7);
|
||||
children1.add(bow2);
|
||||
children1.add(bow3);
|
||||
children2.add(bow4);
|
||||
children2.add(bow5);
|
||||
children3.add(bow6);
|
||||
children3.add(bow7);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Kit[] get_kits()
|
||||
{
|
||||
Kit[] kitArray = new Kit[_kits.size()];
|
||||
for (int i = 0; i < kitArray.length; i++)
|
||||
{
|
||||
kitArray[i] = _kits.get(i).kit;
|
||||
}
|
||||
return kitArray;
|
||||
}
|
||||
|
||||
public ArrayList<UpgradeKit> getUpgradeKits()
|
||||
{
|
||||
return _kits;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,333 @@
|
||||
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 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;
|
||||
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.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;
|
||||
|
||||
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 KitEvolve _evolve;
|
||||
private KitManager _kitManager = new KitManager(this);
|
||||
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 : getBombs())
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
};
|
||||
private ArrayList<TeamBomb> _teamBombs = new ArrayList<TeamBomb>();
|
||||
|
||||
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<TeamBomb> 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)
|
||||
{
|
||||
if (this.GetState() != GameState.Live)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (event.getType() == UpdateType.FASTEST)
|
||||
{
|
||||
for (TeamBomb bomb : getBombs())
|
||||
{
|
||||
bomb.updateBombHologram();
|
||||
}
|
||||
}
|
||||
if (event.getType() == UpdateType.SEC)
|
||||
{
|
||||
Iterator<TeamBomb> itel = getBombs().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() + " Team'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 (getBombs().size() == 1)
|
||||
{
|
||||
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() + " Team was defeated!");
|
||||
}
|
||||
}
|
||||
if (timeLeft > 0)
|
||||
{
|
||||
int a = timeLeft % 3;
|
||||
if (a == 1)
|
||||
{
|
||||
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<EntityPlayer> cloned = (HashSet) trackedPlayers.clone();
|
||||
for (final EntityPlayer p : cloned)
|
||||
{
|
||||
entityTrackerEntry.clear(p);
|
||||
p.playerConnection.sendPacket(destroyPacket);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(getArcadeManager().GetPlugin(),
|
||||
new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
try
|
||||
{
|
||||
entityTrackerEntry.updatePlayer(p);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@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)
|
||||
{
|
||||
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.getBombs())
|
||||
{
|
||||
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.getBombs())
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ParseData()
|
||||
{
|
||||
for (GameTeam team : GetTeamList())
|
||||
{
|
||||
for (Location loc : WorldData.GetDataLocs(team.GetColor() == ChatColor.AQUA ? "BLUE" : team.GetColor().name()))
|
||||
{
|
||||
getBombs().add(new TeamBomb(this.Manager, this, team, loc));
|
||||
loc.getBlock().setType(Material.TNT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,363 @@
|
||||
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 mineplex.core.common.util.UtilEnt;
|
||||
import mineplex.core.hologram.Hologram;
|
||||
import nautilus.game.arcade.ArcadeManager;
|
||||
import nautilus.game.arcade.game.GameTeam;
|
||||
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<TeamBomb>
|
||||
{
|
||||
private class ArmInfo
|
||||
{
|
||||
private ArrayList<Player> _armers = new ArrayList<Player>();
|
||||
private long _firstArmed = System.currentTimeMillis();
|
||||
private long _lastInteract;
|
||||
private GameTeam _owningTeam;
|
||||
private int _timeToArmBomb = 4;
|
||||
|
||||
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 ArrayList<ArmInfo> _armers = new ArrayList<ArmInfo>();
|
||||
private TNTPrimed _bombEntity;
|
||||
private Location _bombLocation;
|
||||
private final int _entityId = UtilEnt.getNewEntityId();
|
||||
private SearchAndDestroy _game;
|
||||
private Hologram _hologram;
|
||||
private long _lastHiss;
|
||||
private GameTeam _owningTeam;
|
||||
private long _timeBombArmed;
|
||||
private int _timeUntilExplode;
|
||||
|
||||
public TeamBomb(ArcadeManager manager, SearchAndDestroy game, GameTeam owningTeam, Location bombLocation)
|
||||
{
|
||||
this._game = game;
|
||||
this._owningTeam = owningTeam;
|
||||
this._bombLocation = bombLocation;
|
||||
}
|
||||
|
||||
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();
|
||||
double y = getBlockLocation().getY() + 1;
|
||||
double z = getBlockLocation().getZ();
|
||||
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() + " Team'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());
|
||||
_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() + " Team" + ChatColor.RESET + ChatColor.GOLD
|
||||
+ " have just defused their bomb!");
|
||||
restoreBomb();
|
||||
}
|
||||
_armers.clear();
|
||||
}
|
||||
|
||||
public void checkArmers()
|
||||
{
|
||||
Iterator<ArmInfo> armers = _armers.iterator();
|
||||
while (armers.hasNext())
|
||||
{
|
||||
ArmInfo info = armers.next();
|
||||
if (!info.isValid())
|
||||
{
|
||||
armers.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(TeamBomb o)
|
||||
{
|
||||
if (o._timeBombArmed == _timeBombArmed)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (o._timeBombArmed < _timeBombArmed)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
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
|
||||
*/
|
||||
public void restoreBomb()
|
||||
{
|
||||
_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();
|
||||
_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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void updateBombHologram()
|
||||
{
|
||||
if (!_armers.isEmpty())
|
||||
{
|
||||
Iterator<ArmInfo> itel = _armers.iterator();
|
||||
ArrayList<String> text = new ArrayList<String>();
|
||||
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]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
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;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,97 @@
|
||||
package nautilus.game.arcade.game.games.searchanddestroy.kits.bow;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
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;
|
||||
|
||||
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
|
||||
{
|
||||
|
||||
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<LivingEntity, Integer> _secondsPinned = new NautHashMap<LivingEntity, Integer>();
|
||||
|
||||
@EventHandler
|
||||
public void onSecond(UpdateEvent event)
|
||||
{
|
||||
if (event.getType() != UpdateType.FASTER)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Iterator<LivingEntity> 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));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
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;
|
||||
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;
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,76 @@
|
||||
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;
|
||||
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.EntityDamageEvent.DamageCause;
|
||||
import org.bukkit.event.entity.ProjectileLaunchEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,100 @@
|
||||
package nautilus.game.arcade.game.games.searchanddestroy.kits.bow;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
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;
|
||||
|
||||
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
|
||||
{
|
||||
|
||||
private NautHashMap<LivingEntity, Integer> _secondsBleeding = new NautHashMap<LivingEntity, Integer>();
|
||||
|
||||
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<LivingEntity> 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));
|
||||
}
|
||||
|
||||
}
|
@ -32,127 +32,127 @@ import nautilus.game.arcade.gui.button.SpectatorButton;
|
||||
|
||||
public class SpectatorPage extends ShopPageBase<CompassAddon, SpectatorShop>
|
||||
{
|
||||
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<GameTeam> teamList = _arcadeManager.GetGame().GetTeamList();
|
||||
@Override
|
||||
protected void BuildPage()
|
||||
{
|
||||
int playerCount = _arcadeManager.GetGame().GetPlayers(true).size();
|
||||
List<GameTeam> 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<GameTeam> teamList, int playerCount)
|
||||
{
|
||||
int currentRow = 0;
|
||||
private void buildMultipleTeams(List<GameTeam> teamList, int playerCount)
|
||||
{
|
||||
int currentRow = 0;
|
||||
|
||||
for (GameTeam team : teamList)
|
||||
{
|
||||
ArrayList<Player> teamPlayers = team.GetPlayers(true);
|
||||
int rowsNeeded = (teamPlayers.size() / 8) + 1;
|
||||
for (GameTeam team : teamList)
|
||||
{
|
||||
ArrayList<Player> 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<String> lore = new ArrayList<String>();
|
||||
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<String> lore = new ArrayList<String>();
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user