To disguise players as another Entity, I made a disguise class, as you can see here:
public class Disguise { private static HashSet<Disguise> disguises = new HashSet<>(); private net.minecraft.server.v1_8_R2.EntityLiving nmsEntity; private Player disguise; public Disguise(Player disguise, EntityLiving entity, boolean affectLogin) { if(affectLogin) disguises.add(this); this.disguise = disguise; this.nmsEntity = entity; } public Disguise(Player disguise, EntityLiving entity) { this(disguise, entity, true); } public void send(Player visible) { if(visible == disguise) return; EntityPlayer player = NMSUtils.getNMSPlayer(visible); nmsEntity.setPosition(player.locX, player.locY, player.locZ); nmsEntity.d(disguise.getEntityId()); nmsEntity.setCustomName(disguise.getDisplayName()); nmsEntity.setCustomNameVisible(true); PacketPlayOutSpawnEntityLiving spawn = new PacketPlayOutSpawnEntityLiving(nmsEntity); PacketPlayOutEntityDestroy destroy = new PacketPlayOutEntityDestroy(disguise.getEntityId()); player.playerConnection.sendPacket(destroy); player.playerConnection.sendPacket(spawn); } public void send(List<Player> visible) { for(Player player : visible) send(player); } public void send(Player... visible) { send(Arrays.asList(visible)); } public void send() { send(new ArrayList<>(Bukkit.getOnlinePlayers())); } public Player getDisguised() { return disguise; } public static HashSet<Disguise> getDisguises() { return disguises; } }
I also have a static HashSet that stores all instances made. I do this because I want the players who are logged in to also see the disguise, and I want to remove the disguise from the player when the player leaves the game. Is a static HashSet way to do this (how do I do it)? And if not, how to do it?
source share