From b364fdda4fd6bbe6054cc49239d0c65a5b4fda7b Mon Sep 17 00:00:00 2001 From: OliverSchlueter Date: Mon, 21 Oct 2024 18:42:55 +0200 Subject: [PATCH] Fix interaction cooldown message is sent twice --- api/src/main/java/de/oliver/fancynpcs/api/Npc.java | 4 ++++ .../java/de/oliver/fancynpcs/v1_19_4/PacketReader_1_19_4.java | 1 - .../java/de/oliver/fancynpcs/v1_20/PacketReader_1_20.java | 1 - .../fancynpcs/listeners/PlayerUseUnknownEntityListener.java | 1 - 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/api/src/main/java/de/oliver/fancynpcs/api/Npc.java b/api/src/main/java/de/oliver/fancynpcs/api/Npc.java index 2e0ca140..f1982be9 100644 --- a/api/src/main/java/de/oliver/fancynpcs/api/Npc.java +++ b/api/src/main/java/de/oliver/fancynpcs/api/Npc.java @@ -174,6 +174,10 @@ public void interact(Player player, ActionTrigger actionTrigger) { // actions ActionExecutor.execute(actionTrigger, this, player); + + if (actionTrigger == ActionTrigger.LEFT_CLICK || actionTrigger == ActionTrigger.RIGHT_CLICK) { + ActionExecutor.execute(ActionTrigger.ANY_CLICK, this, player); + } } protected abstract void refreshEntityData(Player serverPlayer); diff --git a/implementation_1_19_4/src/main/java/de/oliver/fancynpcs/v1_19_4/PacketReader_1_19_4.java b/implementation_1_19_4/src/main/java/de/oliver/fancynpcs/v1_19_4/PacketReader_1_19_4.java index a154d118..54cd0e14 100644 --- a/implementation_1_19_4/src/main/java/de/oliver/fancynpcs/v1_19_4/PacketReader_1_19_4.java +++ b/implementation_1_19_4/src/main/java/de/oliver/fancynpcs/v1_19_4/PacketReader_1_19_4.java @@ -66,7 +66,6 @@ public void onPacketReceived(final PacketReceivedEvent event) { if (hand == EquipmentSlot.HAND) { // This packet can be sent multiple times for interactions that are NOT attacks, making sure to run logic only ONCE. if (isAttack || !isInteract || npc.getData().getType() == EntityType.ARMOR_STAND) { - npc.interact(event.getPlayer(), ActionTrigger.ANY_CLICK); npc.interact(event.getPlayer(), isAttack ? ActionTrigger.LEFT_CLICK : ActionTrigger.RIGHT_CLICK); } } diff --git a/implementation_1_20/src/main/java/de/oliver/fancynpcs/v1_20/PacketReader_1_20.java b/implementation_1_20/src/main/java/de/oliver/fancynpcs/v1_20/PacketReader_1_20.java index 79282740..f2cb1819 100644 --- a/implementation_1_20/src/main/java/de/oliver/fancynpcs/v1_20/PacketReader_1_20.java +++ b/implementation_1_20/src/main/java/de/oliver/fancynpcs/v1_20/PacketReader_1_20.java @@ -68,7 +68,6 @@ public void onPacketReceived(final PacketReceivedEvent event) { if (hand == EquipmentSlot.HAND) { // This packet can be sent multiple times for interactions that are NOT attacks, making sure to run logic only ONCE. if (isAttack || !isInteract || npc.getData().getType() == EntityType.ARMOR_STAND) { - npc.interact(event.getPlayer(), ActionTrigger.ANY_CLICK); npc.interact(event.getPlayer(), isAttack ? ActionTrigger.LEFT_CLICK : ActionTrigger.RIGHT_CLICK); } } diff --git a/src/main/java/de/oliver/fancynpcs/listeners/PlayerUseUnknownEntityListener.java b/src/main/java/de/oliver/fancynpcs/listeners/PlayerUseUnknownEntityListener.java index 40b61d5b..d66efcfc 100644 --- a/src/main/java/de/oliver/fancynpcs/listeners/PlayerUseUnknownEntityListener.java +++ b/src/main/java/de/oliver/fancynpcs/listeners/PlayerUseUnknownEntityListener.java @@ -21,7 +21,6 @@ public void onPlayerUseUnknownEntity(final PlayerUseUnknownEntityEvent event) { if (event.getHand() == EquipmentSlot.HAND) { // PlayerUseUnknownEntityEvent can be called multiple times for interactions that are NOT attacks, making sure to run logic only ONCE. if (event.isAttack() || event.getClickedRelativePosition() == null || npc.getData().getType() == EntityType.ARMOR_STAND) { - npc.interact(event.getPlayer(), ActionTrigger.ANY_CLICK); npc.interact(event.getPlayer(), event.isAttack() ? ActionTrigger.LEFT_CLICK : ActionTrigger.RIGHT_CLICK); } }