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; package com.bukkit.mcteam.factions.listeners;
import java.util.*;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockDamageLevel; import org.bukkit.block.BlockDamageLevel;
@ -28,13 +30,19 @@ public class FactionsBlockListener extends BlockListener {
event.setCancelled(true); event.setCancelled(true);
} }
} }
//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 @Override
public void onBlockDamage(BlockDamageEvent event) { public void onBlockDamage(BlockDamageEvent event) {
if (event.isCancelled()) { if (event.isCancelled()) {
return; // Alright. lets listen to that. 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); event.setCancelled(true);
} }
} }