@Override public void setItem(Hologram hologram, Object rawitem) { if (!(rawitem instanceof EntityItem)) throw new IllegalStateException("The item has to be a instance of EntityItem!"); EntityItem item = (EntityItem) rawitem; EntityArmorStand as = (EntityArmorStand) hologram.getArmorStand(0); if (hologram.hasItem()) { EntityItem oldItem = (EntityItem) hologram.getItem(); for (Player p : hologram.getPlayers()) { PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(oldItem.getId()); ((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet); } } for (Player p : hologram.getPlayers()) { PlayerConnection playerConnection = ((CraftPlayer) p).getHandle().playerConnection; PacketPlayOutSpawnEntity itemPacket = new PacketPlayOutSpawnEntity(item, 2, 0); playerConnection.sendPacket(itemPacket); PacketPlayOutEntityMetadata itemMetaDataPacket = new PacketPlayOutEntityMetadata(item.getId(), item.getDataWatcher(), true); playerConnection.sendPacket(itemMetaDataPacket); PacketPlayOutAttachEntity attachEntityPacket = new PacketPlayOutAttachEntity(0, item, as); playerConnection.sendPacket(attachEntityPacket); } }
@Override public void showPlayer(Hologram hologram, Player player) { PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection; for (Object as : hologram.getArmorStands()) { PacketPlayOutSpawnEntityLiving packet = new PacketPlayOutSpawnEntityLiving((EntityArmorStand) as); ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); } if (hologram.hasItem()) { EntityItem item = (EntityItem) hologram.getItem(); PacketPlayOutSpawnEntity itemPacket = new PacketPlayOutSpawnEntity(item, 2, 0); playerConnection.sendPacket(itemPacket); PacketPlayOutEntityMetadata itemMetaDataPacket = new PacketPlayOutEntityMetadata(item.getId(), item.getDataWatcher(), true); playerConnection.sendPacket(itemMetaDataPacket); PacketPlayOutAttachEntity attachEntityPacket = new PacketPlayOutAttachEntity(0, item, (EntityArmorStand) hologram.getArmorStand(0)); playerConnection.sendPacket(attachEntityPacket); } }