diff --git a/src/main/java/com/sk89q/worldguard/bukkit/SignChestProtection.java b/src/main/java/com/sk89q/worldguard/bukkit/SignChestProtection.java index 9e3e869f..c5e1c819 100644 --- a/src/main/java/com/sk89q/worldguard/bukkit/SignChestProtection.java +++ b/src/main/java/com/sk89q/worldguard/bukkit/SignChestProtection.java @@ -56,23 +56,23 @@ private boolean isProtectedSignAround(Block searchBlock, Player player) { side = searchBlock; res = isProtectedSign(side, player); - if (res != null) return res; + if (res != null && res == true) return res; side = searchBlock.getRelative(-1, 0, 0); res = isProtectedSignAndChest(side, player); - if (res != null) return res; + if (res != null && res == true) return res; side = searchBlock.getRelative(1, 0, 0); res = isProtectedSignAndChest(side, player); - if (res != null) return res; + if (res != null && res == true) return res; side = searchBlock.getRelative(0, 0, -1); res = isProtectedSignAndChest(side, player); - if (res != null) return res; + if (res != null && res == true) return res; side = searchBlock.getRelative(0, 0, 1); res = isProtectedSignAndChest(side, player); - if (res != null) return res; + if (res != null && res == true) return res; return false; } @@ -120,10 +120,37 @@ private boolean isProtectedSignAndChestBinary(Block block, Player player) { return true; } - private boolean isChest(Material material) { + public boolean isChest(Material material) { return material == Material.CHEST || material == Material.DISPENSER || material == Material.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; + } } diff --git a/src/main/java/com/sk89q/worldguard/bukkit/WorldConfiguration.java b/src/main/java/com/sk89q/worldguard/bukkit/WorldConfiguration.java index a7a645d8..6869e6cb 100644 --- a/src/main/java/com/sk89q/worldguard/bukkit/WorldConfiguration.java +++ b/src/main/java/com/sk89q/worldguard/bukkit/WorldConfiguration.java @@ -357,4 +357,18 @@ public boolean isChestProtectedPlacement(Block block, Player 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; + } + } diff --git a/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardBlockListener.java b/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardBlockListener.java index 1f5986b3..a9aa6db9 100644 --- a/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardBlockListener.java +++ b/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardBlockListener.java @@ -448,6 +448,14 @@ public void onBlockPlace(BlockPlaceEvent event) { return; } } + + 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.redstoneSponges && blockPlaced.isBlockIndirectlyPowered()) {