@Override public void setDistance(Hologram hologram, double distance) { List<EntityArmorStand> armorStands = new ArrayList<EntityArmorStand>(); Location loc = hologram.getLocation(); for (Object as : hologram.getArmorStands()) armorStands.add((EntityArmorStand) as); for (Player p : hologram.getPlayers()) { for (int i = 1; i < armorStands.size(); ++i) { EntityArmorStand beforeAs = armorStands.get(i - 1); EntityArmorStand as = armorStands.get(i); int newX = MathHelper.floor(loc.getX() * 32.0D); int newY = MathHelper.floor((beforeAs.locY - distance) * 32.0D); int newZ = MathHelper.floor(loc.getZ() * 32.0D); PacketPlayOutEntityTeleport packet = new PacketPlayOutEntityTeleport( as.getId(), newX, newY, newZ, (byte) as.yaw, (byte) as.pitch, false); ((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet); as.setLocation(as.locX, beforeAs.locY - distance, as.locZ, as.yaw, as.pitch); } } }
@Override public void removeMessage(Hologram hologram, int index) { EntityArmorStand removeArmorStand = (EntityArmorStand) hologram.getArmorStands().get(index); List<Double> pos = new ArrayList<Double>(); for (Player p : hologram.getPlayers()) { PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(removeArmorStand.getId()); ((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet); } for (int i = index + 1; i < hologram.getArmorStands().size(); ++i) { EntityArmorStand as = (EntityArmorStand) hologram.getArmorStands().get(i); EntityArmorStand oldAs = (EntityArmorStand) hologram.getArmorStands().get(i - 1); int dy = MathHelper.floor(oldAs.locY * 32.0D) - MathHelper.floor(as.locY * 32.0D); for (Player p : hologram.getPlayers()) { if (dy >= -128 && dy < 128) { PacketPlayOutRelEntityMove packet = new PacketPlayOutRelEntityMove(as.getId(), (byte) 0, (byte) dy, (byte) 0, false); ((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet); } else { PacketPlayOutEntityTeleport packet = new PacketPlayOutEntityTeleport( as.getId(), MathHelper.floor(oldAs.locX * 32.0D), MathHelper.floor(oldAs.locY * 32.0D), MathHelper.floor(oldAs.locZ * 32.0D), (byte) as.yaw, (byte) as.pitch, false); ((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet); } } pos.add(oldAs.locY); } // Restore the correct positions int j = 0; for (int i = index + 1; i < hologram.getArmorStands().size(); ++i) { EntityArmorStand as = (EntityArmorStand) hologram.getArmorStands().get(i); as.setLocation(as.locX, pos.get(j), as.locZ, as.yaw, as.pitch); ++j; } }
@Override public void move(Hologram hologram, Location newLocation) { List<EntityArmorStand> armorStands = new ArrayList<EntityArmorStand>(); for (Object as : hologram.getArmorStands()) armorStands.add((EntityArmorStand) as); int newX = MathHelper.floor(newLocation.getX() * 32.0D); int newZ = MathHelper.floor(newLocation.getZ() * 32.0D); for (Player p : hologram.getPlayers()) { for (int i = 0; i < armorStands.size(); ++i) { EntityArmorStand as = armorStands.get(i); double distance = i * hologram.getDistance(); int newY = MathHelper.floor((newLocation.getY() - distance) * 32.0D); PacketPlayOutEntityTeleport packet = new PacketPlayOutEntityTeleport( as.getId(), newX, newY, newZ, (byte) newLocation.getYaw(), (byte) newLocation.getPitch(), false); ((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet); as.setLocation( newLocation.getX(), newLocation.getY() - distance, newLocation.getZ(), newLocation.getYaw(), newLocation.getPitch()); } } }