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 which stores all the instances made. I am doing this because I want players who login to see the disguise aswell and I want to remove the disguise from the player when the player logs out. Is a static HashSet the way to do it (like I'm doing it)? And if not, how should it be done?