Skip to content

Commit

Permalink
Fix interaction cooldown message is sent twice
Browse files Browse the repository at this point in the history
  • Loading branch information
OliverSchlueter committed Oct 21, 2024
1 parent aef5a43 commit b364fdd
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 3 deletions.
4 changes: 4 additions & 0 deletions api/src/main/java/de/oliver/fancynpcs/api/Npc.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down

0 comments on commit b364fdd

Please sign in to comment.