Improved chest-sign protection.

This commit is contained in:
sk89q 2011-05-04 01:24:38 -07:00
parent b58e04707d
commit b23e35cf26
3 changed files with 41 additions and 5 deletions

View File

@ -46,6 +46,10 @@ public boolean isProtected(Block block, Player player) {
} }
} }
public boolean isProtectedPlacement(Block block, Player player) {
return isProtectedSignAround(block, player);
}
private boolean isProtectedSignAround(Block searchBlock, Player player) { private boolean isProtectedSignAround(Block searchBlock, Player player) {
Block side; Block side;
Boolean res; Boolean res;

View File

@ -347,4 +347,14 @@ public boolean isChestProtected(Block block) {
return chestProtection.isProtected(block, null); return chestProtection.isProtected(block, null);
} }
public boolean isChestProtectedPlacement(Block block, Player player) {
if (!signChestProtection) {
return false;
}
if (plugin.hasPermission(player, "worldguard.chest-protection.override")) {
return false;
}
return chestProtection.isProtectedPlacement(block, player);
}
} }

View File

@ -365,6 +365,7 @@ public void onBlockBurn(BlockBurnEvent event) {
} }
} }
if (wcfg.isChestProtected(event.getBlock())) { event.setCancelled(true); return; }
if (wcfg.useRegions) { if (wcfg.useRegions) {
Block block = event.getBlock(); Block block = event.getBlock();
Vector pt = toVector(block); Vector pt = toVector(block);
@ -512,6 +513,13 @@ public void onSignChange(SignChangeEvent event) {
if (wcfg.signChestProtection) { if (wcfg.signChestProtection) {
if (event.getLine(0).equalsIgnoreCase("[Lock]")) { if (event.getLine(0).equalsIgnoreCase("[Lock]")) {
if (wcfg.isChestProtectedPlacement(event.getBlock(), player)) {
player.sendMessage(ChatColor.DARK_RED + "You do not own the adjacent chest.");
dropSign(event.getBlock());
event.setCancelled(true);
return;
}
if (event.getBlock().getType() != Material.SIGN_POST) { if (event.getBlock().getType() != Material.SIGN_POST) {
player.sendMessage(ChatColor.RED player.sendMessage(ChatColor.RED
+ "The [Lock] sign must be a sign post, not a wall sign."); + "The [Lock] sign must be a sign post, not a wall sign.");
@ -519,18 +527,32 @@ public void onSignChange(SignChangeEvent event) {
dropSign(event.getBlock()); dropSign(event.getBlock());
event.setCancelled(true); event.setCancelled(true);
return; return;
} else if (!event.getLine(1).equalsIgnoreCase(player.getName())) { }
if (!event.getLine(1).equalsIgnoreCase(player.getName())) {
player.sendMessage(ChatColor.RED player.sendMessage(ChatColor.RED
+ "The first owner line must be your name."); + "The first owner line must be your name.");
dropSign(event.getBlock()); dropSign(event.getBlock());
event.setCancelled(true); event.setCancelled(true);
return; return;
} else {
event.setLine(0, "[Lock]");
player.sendMessage(ChatColor.YELLOW
+ "A chest or double chest above is now protected.");
} }
Material below = event.getBlock().getRelative(0, -1, 0).getType();
if (below == Material.TNT || below == Material.SAND
|| below == Material.GRAVEL || below == Material.SIGN_POST) {
player.sendMessage(ChatColor.RED
+ "That is not a safe block that you're putting this sign on.");
dropSign(event.getBlock());
event.setCancelled(true);
return;
}
event.setLine(0, "[Lock]");
player.sendMessage(ChatColor.YELLOW
+ "A chest or double chest above is now protected.");
} }
} else { } else {
if (event.getLine(0).equalsIgnoreCase("[Lock]")) { if (event.getLine(0).equalsIgnoreCase("[Lock]")) {