Fixed some chest protection issues.

This commit is contained in:
sk89q 2011-05-19 21:13:07 -07:00
parent b23e35cf26
commit 97bde50708
3 changed files with 55 additions and 6 deletions

View File

@ -56,23 +56,23 @@ private boolean isProtectedSignAround(Block searchBlock, Player player) {
side = searchBlock; side = searchBlock;
res = isProtectedSign(side, player); res = isProtectedSign(side, player);
if (res != null) return res; if (res != null && res == true) return res;
side = searchBlock.getRelative(-1, 0, 0); side = searchBlock.getRelative(-1, 0, 0);
res = isProtectedSignAndChest(side, player); res = isProtectedSignAndChest(side, player);
if (res != null) return res; if (res != null && res == true) return res;
side = searchBlock.getRelative(1, 0, 0); side = searchBlock.getRelative(1, 0, 0);
res = isProtectedSignAndChest(side, player); res = isProtectedSignAndChest(side, player);
if (res != null) return res; if (res != null && res == true) return res;
side = searchBlock.getRelative(0, 0, -1); side = searchBlock.getRelative(0, 0, -1);
res = isProtectedSignAndChest(side, player); res = isProtectedSignAndChest(side, player);
if (res != null) return res; if (res != null && res == true) return res;
side = searchBlock.getRelative(0, 0, 1); side = searchBlock.getRelative(0, 0, 1);
res = isProtectedSignAndChest(side, player); res = isProtectedSignAndChest(side, player);
if (res != null) return res; if (res != null && res == true) return res;
return false; return false;
} }
@ -120,10 +120,37 @@ private boolean isProtectedSignAndChestBinary(Block block, Player player) {
return true; return true;
} }
private boolean isChest(Material material) { public boolean isChest(Material material) {
return material == Material.CHEST return material == Material.CHEST
|| material == Material.DISPENSER || material == Material.DISPENSER
|| material == Material.FURNACE || material == Material.FURNACE
|| material == Material.BURNING_FURNACE; || material == Material.BURNING_FURNACE;
} }
public boolean isAdjacentChestProtected(Block searchBlock, Player player) {
Block side;
Boolean res;
side = searchBlock;
res = isProtected(side, player);
if (res != null && res == true) return res;
side = searchBlock.getRelative(-1, 0, 0);
res = isProtected(side, player);
if (res != null && res == true) return res;
side = searchBlock.getRelative(1, 0, 0);
res = isProtected(side, player);
if (res != null && res == true) return res;
side = searchBlock.getRelative(0, 0, -1);
res = isProtected(side, player);
if (res != null && res == true) return res;
side = searchBlock.getRelative(0, 0, 1);
res = isProtected(side, player);
if (res != null && res == true) return res;
return false;
}
} }

View File

@ -357,4 +357,18 @@ public boolean isChestProtectedPlacement(Block block, Player player) {
return chestProtection.isProtectedPlacement(block, player); return chestProtection.isProtectedPlacement(block, player);
} }
public boolean isAdjacentChestProtected(Block block, Player player) {
if (!signChestProtection) {
return false;
}
if (plugin.hasPermission(player, "worldguard.chest-protection.override")) {
return false;
}
return chestProtection.isAdjacentChestProtected(block, player);
}
public SignChestProtection getChestProtection() {
return chestProtection;
}
} }

View File

@ -449,6 +449,14 @@ public void onBlockPlace(BlockPlaceEvent event) {
} }
} }
if (wcfg.signChestProtection && wcfg.getChestProtection().isChest(blockPlaced.getType())) {
if (wcfg.isAdjacentChestProtected(event.getBlock(), player)) {
player.sendMessage(ChatColor.DARK_RED + "This spot is for a chest that you don't have permission for.");
event.setCancelled(true);
return;
}
}
if (wcfg.simulateSponge && blockPlaced.getTypeId() == 19) { if (wcfg.simulateSponge && blockPlaced.getTypeId() == 19) {
if (wcfg.redstoneSponges && blockPlaced.isBlockIndirectlyPowered()) { if (wcfg.redstoneSponges && blockPlaced.isBlockIndirectlyPowered()) {
return; return;