use of com.loohp.interactionvisualizer.objectholders.ValuePairs in project InteractionVisualizer by LOOHP.
the class ServerPacketSender method updateArmorStand.
public static void updateArmorStand(Collection<Player> players, ArmorStand entity) {
PacketContainer packet1 = protocolManager.createPacket(PacketType.Play.Server.ENTITY_TELEPORT);
packet1.getIntegers().write(0, entity.getEntityId());
packet1.getDoubles().write(0, entity.getLocation().getX());
packet1.getDoubles().write(1, entity.getLocation().getY());
packet1.getDoubles().write(2, entity.getLocation().getZ());
packet1.getBytes().write(0, (byte) (int) (entity.getLocation().getYaw() * 256.0F / 360.0F));
packet1.getBytes().write(1, (byte) (int) (entity.getLocation().getPitch() * 256.0F / 360.0F));
PacketContainer packet2 = protocolManager.createPacket(PacketType.Play.Server.ENTITY_METADATA);
packet2.getIntegers().write(0, entity.getEntityId());
WrappedDataWatcher wpw = entity.updateAndGetWrappedDataWatcher();
packet2.getWatchableCollectionModifier().write(0, wpw.getWatchableObjects());
List<ValuePairs<EquipmentSlot, ItemStack>> equipments = new ArrayList<>();
equipments.add(new ValuePairs<>(EquipmentSlot.HAND, entity.getItemInMainHand()));
equipments.add(new ValuePairs<>(EquipmentSlot.HEAD, entity.getHelmet()));
PacketContainer[] packet3 = nms.createEntityEquipmentPacket(entity.getEntityId(), equipments);
if (!plugin.isEnabled()) {
return;
}
Bukkit.getScheduler().runTask(plugin, () -> {
try {
for (Player player : players) {
protocolManager.sendServerPacket(player, packet1);
protocolManager.sendServerPacket(player, packet2);
for (PacketContainer packet : packet3) {
protocolManager.sendServerPacket(player, packet);
}
}
} catch (InvocationTargetException | IllegalArgumentException e) {
}
});
}
use of com.loohp.interactionvisualizer.objectholders.ValuePairs in project InteractionVisualizer by LOOHP.
the class ServerPacketSender method spawnArmorStand.
public static void spawnArmorStand(Collection<Player> players, ArmorStand entity) {
PacketContainer packet1 = protocolManager.createPacket(PacketType.Play.Server.SPAWN_ENTITY_LIVING);
packet1.getIntegers().write(0, entity.getEntityId());
if (packet1.getUUIDs().size() > 0) {
packet1.getUUIDs().write(0, entity.getUniqueId());
}
packet1.getIntegers().write(1, version.isLegacy() ? 30 : 1);
packet1.getIntegers().write(2, (int) (entity.getVelocity().getX() * 8000));
packet1.getIntegers().write(3, (int) (entity.getVelocity().getY() * 8000));
packet1.getIntegers().write(4, (int) (entity.getVelocity().getZ() * 8000));
packet1.getDoubles().write(0, entity.getLocation().getX());
packet1.getDoubles().write(1, entity.getLocation().getY());
packet1.getDoubles().write(2, entity.getLocation().getZ());
// Yaw
packet1.getBytes().write(0, (byte) (int) (entity.getLocation().getYaw() * 256.0F / 360.0F));
// Pitch
packet1.getBytes().write(1, (byte) (int) (entity.getLocation().getPitch() * 256.0F / 360.0F));
// Head
packet1.getBytes().write(2, (byte) (int) (entity.getLocation().getYaw() * 256.0F / 360.0F));
PacketContainer packet2 = protocolManager.createPacket(PacketType.Play.Server.ENTITY_METADATA);
packet2.getIntegers().write(0, entity.getEntityId());
WrappedDataWatcher wpw = entity.updateAndGetWrappedDataWatcher();
packet2.getWatchableCollectionModifier().write(0, wpw.getWatchableObjects());
List<ValuePairs<EquipmentSlot, ItemStack>> equipments = new ArrayList<>();
equipments.add(new ValuePairs<>(EquipmentSlot.HAND, entity.getItemInMainHand()));
equipments.add(new ValuePairs<>(EquipmentSlot.HEAD, entity.getHelmet()));
PacketContainer[] packet3 = nms.createEntityEquipmentPacket(entity.getEntityId(), equipments);
if (!plugin.isEnabled()) {
return;
}
Bukkit.getScheduler().runTask(plugin, () -> {
try {
for (Player player : players) {
protocolManager.sendServerPacket(player, packet1);
protocolManager.sendServerPacket(player, packet2);
for (PacketContainer packet : packet3) {
protocolManager.sendServerPacket(player, packet);
}
}
} catch (InvocationTargetException | IllegalArgumentException e) {
}
});
}
Aggregations