From 964de778d9eb943e826ae157594bda59d423aab2 Mon Sep 17 00:00:00 2001 From: Numin Date: Sun, 15 Mar 2020 20:17:50 -0500 Subject: [PATCH] Fix abilities being triggered by dropping items (#1051) ## Fixes * Fixes click abilities being triggered by dropping an item. > * #1048 --- .../projectkorra/projectkorra/PKListener.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/com/projectkorra/projectkorra/PKListener.java b/src/com/projectkorra/projectkorra/PKListener.java index 648046b6..93599d6d 100644 --- a/src/com/projectkorra/projectkorra/PKListener.java +++ b/src/com/projectkorra/projectkorra/PKListener.java @@ -61,6 +61,7 @@ import org.bukkit.event.inventory.InventoryPickupItemEvent; import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.PlayerBucketEmptyEvent; import org.bukkit.event.player.PlayerChangedWorldEvent; +import org.bukkit.event.player.PlayerDropItemEvent; import org.bukkit.event.player.PlayerGameModeChangeEvent; import org.bukkit.event.player.PlayerInteractAtEntityEvent; import org.bukkit.event.player.PlayerInteractEvent; @@ -197,6 +198,7 @@ public class PKListener implements Listener { private static final HashMap BENDING_ENTITY_DEATH = new HashMap<>(); // Entities killed by Bending. private static final HashMap BENDING_PLAYER_DEATH = new HashMap<>(); // Player killed by Bending. private static final List RIGHT_CLICK_INTERACT = new ArrayList(); // Player right click block. + private final List PLAYER_DROPPED_ITEM = new ArrayList<>(); // Player dropped an item. private static final ArrayList TOGGLED_OUT = new ArrayList<>(); // Stands for toggled = false while logging out. private static final Map JUMPS = new HashMap<>(); @@ -1590,6 +1592,21 @@ public class PKListener implements Listener { } } + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onPlayerItemDrop(PlayerDropItemEvent event) { + Player player = event.getPlayer(); + BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(player); + + if (bPlayer == null) + return; + + if (bPlayer.getBoundAbility() == null) + return; + + if (!PLAYER_DROPPED_ITEM.contains(player)) + PLAYER_DROPPED_ITEM.add(player); + } + @EventHandler(priority = EventPriority.NORMAL) public void onPlayerSwing(final PlayerInteractEvent event) { final Player player = event.getPlayer(); @@ -1602,6 +1619,10 @@ public class PKListener implements Listener { if (event.getAction() == Action.LEFT_CLICK_BLOCK && event.isCancelled()) { return; } + if (PLAYER_DROPPED_ITEM.contains(player)) { + PLAYER_DROPPED_ITEM.remove(player); + return; + } final BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(player); if (bPlayer == null) { return;