diff options
author | KHobbits <rob@khobbits.co.uk> | 2012-08-19 21:20:55 +0100 |
---|---|---|
committer | KHobbits <rob@khobbits.co.uk> | 2012-08-19 21:20:55 +0100 |
commit | 552d2e9674fcc66b53032d011d08b4b2c4bb4d57 (patch) | |
tree | 3f9a276f8ff09684217113e70efe76d571a36a4c /EssentialsAntiBuild/src/com/earth2me | |
parent | b839fbaf3442079bcf8282f95f15437b0a44cf11 (diff) | |
download | Essentials-552d2e9674fcc66b53032d011d08b4b2c4bb4d57.tar Essentials-552d2e9674fcc66b53032d011d08b4b2c4bb4d57.tar.gz Essentials-552d2e9674fcc66b53032d011d08b4b2c4bb4d57.tar.lz Essentials-552d2e9674fcc66b53032d011d08b4b2c4bb4d57.tar.xz Essentials-552d2e9674fcc66b53032d011d08b4b2c4bb4d57.zip |
Reduce permissions checks in antibuild.
Add a little debug logging for those with it enabled.
Diffstat (limited to 'EssentialsAntiBuild/src/com/earth2me')
-rw-r--r-- | EssentialsAntiBuild/src/com/earth2me/essentials/antibuild/EssentialsAntiBuildListener.java | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/EssentialsAntiBuild/src/com/earth2me/essentials/antibuild/EssentialsAntiBuildListener.java b/EssentialsAntiBuild/src/com/earth2me/essentials/antibuild/EssentialsAntiBuildListener.java index 8832ee630..9ce4f58f6 100644 --- a/EssentialsAntiBuild/src/com/earth2me/essentials/antibuild/EssentialsAntiBuildListener.java +++ b/EssentialsAntiBuild/src/com/earth2me/essentials/antibuild/EssentialsAntiBuildListener.java @@ -3,6 +3,7 @@ package com.earth2me.essentials.antibuild; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.IEssentials; import com.earth2me.essentials.User; +import java.util.logging.Level; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.event.Event.Result; @@ -33,26 +34,25 @@ public class EssentialsAntiBuildListener implements Listener } return metaPermCheck(user, action, block.getTypeId(), block.getData()); } - + private boolean metaPermCheck(User user, String action, int blockId, byte data) { - String blockPerm = "essentials.build." + action + "." + blockId; - String dataPerm = blockPerm + ":" + data; + final String blockPerm = "essentials.build." + action + "." + blockId; + final String dataPerm = blockPerm + ":" + data; - if (user.isAuthorized(dataPerm)) + if (user.isPermissionSet(dataPerm)) { - return true; + return user.isAuthorized(dataPerm); } - - if (user.isAuthorized(blockPerm)) + else { - if (user.isPermissionSet(dataPerm) && !user.isAuthorized(dataPerm)) + if (ess.getSettings().isDebug()) { - return false; + ess.getLogger().log(Level.INFO, "abort checking if " + user.getName() + " has " + dataPerm + " - not directly set"); } - return true; } - return false; + + return user.isAuthorized(blockPerm); } @EventHandler(priority = EventPriority.HIGHEST) @@ -68,6 +68,10 @@ public class EssentialsAntiBuildListener implements Listener if (prot.getSettingBool(AntiBuildConfig.disable_build) && !user.canBuild() && !user.isAuthorized("essentials.build") && !metaPermCheck(user, "place", event.getBlock())) { + if (ess.getSettings().warnOnBuildDisallow()) + { + user.sendMessage(_("buildAlert")); + } event.setCancelled(true); return; } @@ -100,6 +104,10 @@ public class EssentialsAntiBuildListener implements Listener if (prot.getSettingBool(AntiBuildConfig.disable_build) && !user.canBuild() && !user.isAuthorized("essentials.build") && !metaPermCheck(user, "break", event.getBlock())) { + if (ess.getSettings().warnOnBuildDisallow()) + { + user.sendMessage(_("buildAlert")); + } event.setCancelled(true); return; } @@ -190,7 +198,6 @@ public class EssentialsAntiBuildListener implements Listener if (prot.getSettingBool(AntiBuildConfig.disable_use) && !user.canBuild() && !user.isAuthorized("essentials.interact") && !user.isAuthorized("essentials.build")) { - if (!metaPermCheck(user, "interact", event.getClickedBlock())) { event.setUseInteractedBlock(Result.DENY); @@ -203,8 +210,6 @@ public class EssentialsAntiBuildListener implements Listener { event.setUseItemInHand(Result.DENY); } - - } } } |