diff --git a/api/src/main/java/lol/pyr/znpcsplus/api/npc/Npc.java b/api/src/main/java/lol/pyr/znpcsplus/api/npc/Npc.java index 1c25a8d..540cd05 100644 --- a/api/src/main/java/lol/pyr/znpcsplus/api/npc/Npc.java +++ b/api/src/main/java/lol/pyr/znpcsplus/api/npc/Npc.java @@ -124,4 +124,10 @@ public interface Npc extends PropertyHolder { * @return The set of players that can currently see this npc */ Set getViewers(); + + /** + * Swings the entity's hand + * @param offHand Should the hand be the offhand + */ + void swingHand(boolean offHand); } diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/PacketEntity.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/PacketEntity.java index e198779..97ef4de 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/PacketEntity.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/PacketEntity.java @@ -73,6 +73,10 @@ public class PacketEntity implements PropertyHolder { packetFactory.sendAllMetadata(player, this, properties); } + public void swingHand(Player player, boolean offhand) { + packetFactory.sendHandSwing(player, this, offhand); + } + private static int reserveEntityID() { if (PacketEvents.getAPI().getServerManager().getVersion().isNewerThanOrEquals(ServerVersion.V_1_14)) { return Reflections.ATOMIC_ENTITY_ID_FIELD.get().incrementAndGet(); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcImpl.java index 3b17eee..fcc563d 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/npc/NpcImpl.java @@ -214,4 +214,8 @@ public class NpcImpl extends Viewable implements Npc { delete(); this.worldName = world.getName(); } + + public void swingHand(boolean offHand) { + for (Player viewer : getViewers()) entity.swingHand(viewer, offHand); + } } diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/packets/PacketFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/packets/PacketFactory.java index 6fe3fde..98cc382 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/packets/PacketFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/packets/PacketFactory.java @@ -23,4 +23,5 @@ public interface PacketFactory { void sendEquipment(Player player, PacketEntity entity, Equipment equipment); void sendMetadata(Player player, PacketEntity entity, List data); void sendHeadRotation(Player player, PacketEntity entity, float yaw, float pitch); + void sendHandSwing(Player player, PacketEntity entity, boolean offHand); } diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_8PacketFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_8PacketFactory.java index 4fd6874..74490ce 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_8PacketFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_8PacketFactory.java @@ -175,4 +175,11 @@ public class V1_8PacketFactory implements PacketFactory { protected void add(Map map, EntityData data) { map.put(data.getIndex(), data); } + + @Override + public void sendHandSwing(Player player, PacketEntity entity, boolean offHand) { + sendPacket(player, new WrapperPlayServerEntityAnimation(entity.getEntityId(), offHand ? + WrapperPlayServerEntityAnimation.EntityAnimationType.SWING_OFF_HAND : + WrapperPlayServerEntityAnimation.EntityAnimationType.SWING_MAIN_ARM)); + } }