From 2f4e487cb6982892f4355c05ea497ab9857f8f7b Mon Sep 17 00:00:00 2001 From: Brettflan Date: Thu, 17 Mar 2011 18:04:45 -0500 Subject: [PATCH] cutting down of crops and sugar cane are now prevented if you are in another faction's territory --- .../factions/listeners/FactionsBlockListener.java | 14 ++++++++++++-- .../factions/listeners/FactionsPlayerListener.java | 5 ++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/com/bukkit/mcteam/factions/listeners/FactionsBlockListener.java b/src/com/bukkit/mcteam/factions/listeners/FactionsBlockListener.java index 441e6799..94b28350 100644 --- a/src/com/bukkit/mcteam/factions/listeners/FactionsBlockListener.java +++ b/src/com/bukkit/mcteam/factions/listeners/FactionsBlockListener.java @@ -23,6 +23,9 @@ public class FactionsBlockListener extends BlockListener { @Override public void onBlockPlace(BlockPlaceEvent event) { + // debug + //event.getPlayer().sendMessage("Block placed: " + event.getBlockPlaced().getTypeId() + " Block clicked: " + event.getBlock().getTypeId() + "(" + event.getBlock().getType().toString() + ")"); + if (event.isCancelled()) { return; // Alright. lets listen to that. } @@ -31,16 +34,20 @@ public class FactionsBlockListener extends BlockListener { } } - //special cases, check for destruction of: torch, redstone torch (on & off), repeater (on & off), redstonewire, sapling + //special cases, check for destruction of: torch, redstone torch (on & off), repeater (on & off), redstonewire, sapling, crops, sugar cane private static Set specialBlocks = new HashSet(Arrays.asList( - new Integer[] {50, 75, 76, 93, 94, 55, 6} + new Integer[] {50, 75, 76, 93, 94, 55, 6, 59, 83} )); @Override public void onBlockDamage(BlockDamageEvent event) { + // debug + //event.getPlayer().sendMessage("Block damaged: " + event.getBlock().getTypeId() + " (" + event.getBlock().getType().toString() + ")"); + if (event.isCancelled()) { return; // Alright. lets listen to that. } + boolean badBlock = event.getDamageLevel() == BlockDamageLevel.STOPPED || specialBlocks.contains(new Integer(event.getBlock().getTypeId())); if (badBlock && ! this.playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock(), "destroy")) { event.setCancelled(true); @@ -82,6 +89,9 @@ public class FactionsBlockListener extends BlockListener { Block block = event.getBlock(); Player player = (Player) event.getEntity(); + // debug + //player.sendMessage("Block interacted: " + event.getBlock().getTypeId() + "(" + event.getBlock().getType().toString() + ")"); + if ( ! canPlayerUseRightclickBlock(player, block)) { event.setCancelled(true); } diff --git a/src/com/bukkit/mcteam/factions/listeners/FactionsPlayerListener.java b/src/com/bukkit/mcteam/factions/listeners/FactionsPlayerListener.java index b13ba8e9..7853d707 100644 --- a/src/com/bukkit/mcteam/factions/listeners/FactionsPlayerListener.java +++ b/src/com/bukkit/mcteam/factions/listeners/FactionsPlayerListener.java @@ -150,6 +150,9 @@ public class FactionsPlayerListener extends PlayerListener{ @Override public void onPlayerItem(PlayerItemEvent event) { + // debug + //event.getPlayer().sendMessage("Item in hand: " + event.getItem().getTypeId() + " Block clicked: " + event.getBlockClicked().getTypeId() + "(" + event.getBlockClicked().getType().toString() + ")"); + if (event.isCancelled()) return; @@ -164,7 +167,7 @@ public class FactionsPlayerListener extends PlayerListener{ } - //currently checking placement/use of: redstone, sign, flint&steel, beds (not detected properly by Bukkit yet), buckets (empty, water, lava), repeater + //currently checking placement/use of: redstone, sign, flint&steel, beds (not currently detected by Bukkit), buckets (empty, water, lava), repeater (not currently detected by Bukkit) private static Set badItems = new HashSet(Arrays.asList( new Integer[] {331, 323, 259, 355, 325, 326, 327, 356} ));