check for special block destruction cases which previously were incorrectly allowed in other faction's territory: torch, redstone torch (on & off), repeater (on & off), redstonewire, sapling

Paintings still can't be prevented from destruction, sadly
This commit is contained in:
Brettflan 2011-03-08 06:42:48 -06:00
parent a7fede9c13
commit 5ab5ef6724

View File

@ -1,5 +1,7 @@
package com.bukkit.mcteam.factions.listeners;
import java.util.*;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockDamageLevel;
@ -29,12 +31,18 @@ public class FactionsBlockListener extends BlockListener {
}
}
//special cases, check for destruction of: torch, redstone torch (on & off), repeater (on & off), redstonewire, sapling
private static Set<Integer> specialBlocks = new HashSet(Arrays.asList(
new Integer[] {50, 75, 76, 93, 94, 55, 6}
));
@Override
public void onBlockDamage(BlockDamageEvent event) {
if (event.isCancelled()) {
return; // Alright. lets listen to that.
}
if (event.getDamageLevel() == BlockDamageLevel.STOPPED && ! this.playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock(), "destroy")) {
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);
}
}