diff --git a/war/src/main/java/com/tommytony/war/Warzone.java b/war/src/main/java/com/tommytony/war/Warzone.java index 0471adf..f16aab5 100644 --- a/war/src/main/java/com/tommytony/war/Warzone.java +++ b/war/src/main/java/com/tommytony/war/Warzone.java @@ -1826,4 +1826,13 @@ public class Warzone { } return this.getTeleport(); } + + /** + * Check if a player has stolen from a warzone flag, bomb, or cake. + * @param suspect Player to check. + * @return true if suspect has stolen a structure. + */ + public boolean isThief(String suspect) { + return this.isFlagThief(suspect) || this.isBombThief(suspect) || this.isCakeThief(suspect); + } } diff --git a/war/src/main/java/com/tommytony/war/event/WarPlayerListener.java b/war/src/main/java/com/tommytony/war/event/WarPlayerListener.java index 6a79880..bdc2e25 100644 --- a/war/src/main/java/com/tommytony/war/event/WarPlayerListener.java +++ b/war/src/main/java/com/tommytony/war/event/WarPlayerListener.java @@ -17,6 +17,8 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.block.Action; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.inventory.InventoryType; import org.bukkit.event.player.*; import org.bukkit.inventory.ItemStack; import org.getspout.spoutapi.SpoutManager; @@ -882,6 +884,26 @@ public class WarPlayerListener implements Listener { } } + @EventHandler + public void onInventoryClick(final InventoryClickEvent event) { + if (!(event.getWhoClicked() instanceof Player)) { + return; + } + Player player = (Player) event.getWhoClicked(); + Warzone zone = Warzone.getZoneByPlayerName(player.getName()); + if (zone == null) { + return; + } + // Prevent thieves from taking their bomb/wool/cake into a chest, etc. + if (zone.isThief(player.getName()) + // Prevent player from grabbing their block helmet + || event.getSlotType() == InventoryType.SlotType.ARMOR && event.getSlot() == 39 + && zone.getWarzoneConfig().getBoolean(WarzoneConfig.BLOCKHEADS)) { + event.setCancelled(true); + player.playSound(player.getLocation(), Sound.FIZZ, 10, 10); + } + } + public void purgeLatestPositions() { this.latestLocations.clear(); }