From 03a802365c6fd8d6700401ff51a2528aac001e55 Mon Sep 17 00:00:00 2001 From: ryanhamshire Date: Sun, 20 Mar 2016 13:50:49 -0700 Subject: [PATCH] Bug fix. --- src/me/ryanhamshire/GriefPrevention/GriefPrevention.java | 7 +++++++ .../ryanhamshire/GriefPrevention/PlayerEventHandler.java | 7 ++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/me/ryanhamshire/GriefPrevention/GriefPrevention.java b/src/me/ryanhamshire/GriefPrevention/GriefPrevention.java index b52c4b1..5a3e510 100644 --- a/src/me/ryanhamshire/GriefPrevention/GriefPrevention.java +++ b/src/me/ryanhamshire/GriefPrevention/GriefPrevention.java @@ -55,6 +55,7 @@ import org.bukkit.command.*; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; +import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; import org.bukkit.plugin.PluginManager; @@ -3402,4 +3403,10 @@ public class GriefPrevention extends JavaPlugin } } } + + public ItemStack getItemInHand(Player player, EquipmentSlot hand) + { + if(hand == EquipmentSlot.OFF_HAND) return player.getInventory().getItemInOffHand(); + return player.getInventory().getItemInMainHand(); + } } \ No newline at end of file diff --git a/src/me/ryanhamshire/GriefPrevention/PlayerEventHandler.java b/src/me/ryanhamshire/GriefPrevention/PlayerEventHandler.java index 98a2a88..237bce7 100644 --- a/src/me/ryanhamshire/GriefPrevention/PlayerEventHandler.java +++ b/src/me/ryanhamshire/GriefPrevention/PlayerEventHandler.java @@ -1344,7 +1344,7 @@ class PlayerEventHandler implements Listener } //if preventing theft, prevent leashing claimed creatures - if(GriefPrevention.instance.config_claims_preventTheft && entity instanceof Creature && player.getItemInHand().getType() == Material.LEASH) + if(GriefPrevention.instance.config_claims_preventTheft && entity instanceof Creature && GriefPrevention.instance.getItemInHand(player, event.getHand()).getType() == Material.LEASH) { Claim claim = this.dataStore.getClaimAt(entity.getLocation(), false, playerData.lastClaim); if(claim != null) @@ -1571,9 +1571,6 @@ class PlayerEventHandler implements Listener if(action == Action.LEFT_CLICK_AIR) return; if(action == Action.PHYSICAL) return; - //not interested in offhand clicks - if(event.getHand() == EquipmentSlot.OFF_HAND) return; - Player player = event.getPlayer(); Block clickedBlock = event.getClickedBlock(); //null returned here means interacting with air @@ -1786,7 +1783,7 @@ class PlayerEventHandler implements Listener if(action != Action.RIGHT_CLICK_BLOCK && action != Action.RIGHT_CLICK_AIR) return; //what's the player holding? - ItemStack itemInHand = player.getItemInHand(); + ItemStack itemInHand = GriefPrevention.instance.getItemInHand(player, event.getHand()); Material materialInHand = itemInHand.getType(); //if it's bonemeal or armor stand or spawn egg, check for build permission (ink sac == bone meal, must be a Bukkit bug?)