cutting down of crops and sugar cane are now prevented if you are in another faction's territory

This commit is contained in:
Brettflan 2011-03-17 18:04:45 -05:00
parent d5308bc75d
commit 2f4e487cb6
2 changed files with 16 additions and 3 deletions

View File

@ -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<Integer> 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);
}

View File

@ -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<Integer> badItems = new HashSet(Arrays.asList(
new Integer[] {331, 323, 259, 355, 325, 326, 327, 356}
));