diff options
author | snowleo <schneeleo@gmail.com> | 2012-02-05 18:26:21 +0100 |
---|---|---|
committer | snowleo <schneeleo@gmail.com> | 2012-02-05 18:26:21 +0100 |
commit | f908eee76c9c3ad14a010b9b3898afcdcc5834d0 (patch) | |
tree | 83851a12b4c2f9c64ec72aa6e5c31ddc6b367b5c /EssentialsSigns/src | |
parent | b95c662ed5d68d1644ba99f9002deb5086f9c9d0 (diff) | |
download | Essentials-f908eee76c9c3ad14a010b9b3898afcdcc5834d0.tar Essentials-f908eee76c9c3ad14a010b9b3898afcdcc5834d0.tar.gz Essentials-f908eee76c9c3ad14a010b9b3898afcdcc5834d0.tar.lz Essentials-f908eee76c9c3ad14a010b9b3898afcdcc5834d0.tar.xz Essentials-f908eee76c9c3ad14a010b9b3898afcdcc5834d0.zip |
New permissions for signs
Diffstat (limited to 'EssentialsSigns/src')
7 files changed, 70 insertions, 16 deletions
diff --git a/EssentialsSigns/src/com/earth2me/essentials/signs/EssentialsSign.java b/EssentialsSigns/src/com/earth2me/essentials/signs/EssentialsSign.java index abef8dd25..e5b0f0ba0 100644 --- a/EssentialsSigns/src/com/earth2me/essentials/signs/EssentialsSign.java +++ b/EssentialsSigns/src/com/earth2me/essentials/signs/EssentialsSign.java @@ -32,8 +32,7 @@ public class EssentialsSign { final ISign sign = new EventSign(event); final IUser user = ess.getUser(event.getPlayer()); - if (!(user.isAuthorized("essentials.signs." + signName.toLowerCase(Locale.ENGLISH) + ".create") - || user.isAuthorized("essentials.signs.create." + signName.toLowerCase(Locale.ENGLISH)))) + if (!SignsPermissions.getCreatePermission(signName).isAuthorized(user)) { // Return true, so other plugins can use the same sign title, just hope // they won't change it to §1[Signname] @@ -82,8 +81,7 @@ public class EssentialsSign final IUser user = ess.getUser(player); try { - return (user.isAuthorized("essentials.signs." + signName.toLowerCase(Locale.ENGLISH) + ".use") - || user.isAuthorized("essentials.signs.use." + signName.toLowerCase(Locale.ENGLISH))) + return SignsPermissions.getUsePermission(signName).isAuthorized(user) && onSignInteract(sign, user, getUsername(user), ess); } catch (ChargeException ex) @@ -104,8 +102,7 @@ public class EssentialsSign final IUser user = ess.getUser(player); try { - return (user.isAuthorized("essentials.signs." + signName.toLowerCase(Locale.ENGLISH) + ".break") - || user.isAuthorized("essentials.signs.break." + signName.toLowerCase(Locale.ENGLISH))) + return SignsPermissions.getBreakPermission(signName).isAuthorized(user) && onSignBreak(sign, user, getUsername(user), ess); } catch (SignException ex) diff --git a/EssentialsSigns/src/com/earth2me/essentials/signs/SignBlockListener.java b/EssentialsSigns/src/com/earth2me/essentials/signs/SignBlockListener.java index a072cd038..c143797ea 100644 --- a/EssentialsSigns/src/com/earth2me/essentials/signs/SignBlockListener.java +++ b/EssentialsSigns/src/com/earth2me/essentials/signs/SignBlockListener.java @@ -84,7 +84,7 @@ public class SignBlockListener implements Listener return; } IUser user = ess.getUser(event.getPlayer()); - if (user.isAuthorized("essentials.signs.color")) + if (SignsPermissions.COLOR.isAuthorized(user)) { for (int i = 0; i < 4; i++) { diff --git a/EssentialsSigns/src/com/earth2me/essentials/signs/SignKit.java b/EssentialsSigns/src/com/earth2me/essentials/signs/SignKit.java index 87f9bb118..9964059ef 100644 --- a/EssentialsSigns/src/com/earth2me/essentials/signs/SignKit.java +++ b/EssentialsSigns/src/com/earth2me/essentials/signs/SignKit.java @@ -4,6 +4,7 @@ import com.earth2me.essentials.ChargeException; import com.earth2me.essentials.Trade; import com.earth2me.essentials.api.IEssentials; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.perm.KitPermissions; import com.earth2me.essentials.settings.Kit; import java.util.Locale; @@ -52,7 +53,7 @@ public class SignKit extends EssentialsSign final String kitName = sign.getLine(1).toLowerCase(Locale.ENGLISH); final String group = sign.getLine(2); if ((!group.isEmpty() && ("§2Everyone".equals(group) || player.inGroup(group))) - || (group.isEmpty() && (player.isAuthorized("essentials.kit." + kitName)))) + || (group.isEmpty() && KitPermissions.getPermission(kitName).isAuthorized(player))) { final Trade charge = getTrade(sign, 3, ess); charge.isAffordableFor(player); diff --git a/EssentialsSigns/src/com/earth2me/essentials/signs/SignProtection.java b/EssentialsSigns/src/com/earth2me/essentials/signs/SignProtection.java index 9dc68087e..8bcc5c8bc 100644 --- a/EssentialsSigns/src/com/earth2me/essentials/signs/SignProtection.java +++ b/EssentialsSigns/src/com/earth2me/essentials/signs/SignProtection.java @@ -36,7 +36,7 @@ public class SignProtection extends EssentialsSign { final SignProtectionState state = isBlockProtected(sign.getBlock(), player, username, true); if (state == SignProtectionState.NOSIGN || state == SignProtectionState.OWNER - || player.isAuthorized("essentials.signs.protection.override")) + || SignsPermissions.PROTECTION_OVERRIDE.isAuthorized(player)) { sign.setLine(3, "§1" + username); return true; @@ -143,7 +143,7 @@ public class SignProtection extends EssentialsSign { return SignProtectionState.NOT_ALLOWED; } - if (user.isAuthorized("essentials.signs.protection.override")) + if (SignsPermissions.PROTECTION_OVERRIDE.isAuthorized(user)) { return SignProtectionState.OWNER; } @@ -254,7 +254,7 @@ public class SignProtection extends EssentialsSign final SignProtectionState state = isBlockProtected(adjBlock, player, username, true); if ((state == SignProtectionState.ALLOWED || state == SignProtectionState.NOT_ALLOWED) - && !player.isAuthorized("essentials.signs.protection.override")) + && !SignsPermissions.PROTECTION_OVERRIDE.isAuthorized(player)) { player.sendMessage(_("noPlacePermission", block.getType().toString().toLowerCase(Locale.ENGLISH))); return false; @@ -275,7 +275,7 @@ public class SignProtection extends EssentialsSign } if (state == SignProtectionState.NOT_ALLOWED - && player.isAuthorized("essentials.signs.protection.override")) + && SignsPermissions.PROTECTION_OVERRIDE.isAuthorized(player)) { return true; } @@ -297,7 +297,7 @@ public class SignProtection extends EssentialsSign } if ((state == SignProtectionState.ALLOWED || state == SignProtectionState.NOT_ALLOWED) - && player.isAuthorized("essentials.signs.protection.override")) + && SignsPermissions.PROTECTION_OVERRIDE.isAuthorized(player)) { checkIfSignsAreBroken(block, player, username, ess); return true; diff --git a/EssentialsSigns/src/com/earth2me/essentials/signs/SignTrade.java b/EssentialsSigns/src/com/earth2me/essentials/signs/SignTrade.java index 796d9fdd6..01cbae6b7 100644 --- a/EssentialsSigns/src/com/earth2me/essentials/signs/SignTrade.java +++ b/EssentialsSigns/src/com/earth2me/essentials/signs/SignTrade.java @@ -97,7 +97,7 @@ public class SignTrade extends EssentialsSign protected boolean onSignBreak(final ISign sign, final IUser player, final String username, final IEssentials ess) throws SignException { if ((sign.getLine(3).length() > 3 && sign.getLine(3).substring(2).equalsIgnoreCase(username)) - || player.isAuthorized("essentials.signs.trade.override")) + || SignsPermissions.TRADE_OVERRIDE.isAuthorized(player)) { try { @@ -109,7 +109,7 @@ public class SignTrade extends EssentialsSign } catch (SignException e) { - if (player.isAuthorized("essentials.signs.trade.override")) + if (SignsPermissions.TRADE_OVERRIDE.isAuthorized(player)) { return true; } diff --git a/EssentialsSigns/src/com/earth2me/essentials/signs/SignWarp.java b/EssentialsSigns/src/com/earth2me/essentials/signs/SignWarp.java index 70a4f53c1..bc16cdf9c 100644 --- a/EssentialsSigns/src/com/earth2me/essentials/signs/SignWarp.java +++ b/EssentialsSigns/src/com/earth2me/essentials/signs/SignWarp.java @@ -4,6 +4,7 @@ import com.earth2me.essentials.ChargeException; import com.earth2me.essentials.Trade; import com.earth2me.essentials.api.IEssentials; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.perm.WarpPermissions; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; @@ -51,7 +52,7 @@ public class SignWarp extends EssentialsSign final String group = sign.getLine(2); if ((!group.isEmpty() && ("§2Everyone".equals(group) || player.inGroup(group))) - || (group.isEmpty() && player.isAuthorized("essentials.warp." + warpName))) + || (group.isEmpty() && WarpPermissions.getPermission(warpName).isAuthorized(player))) { final Trade charge = getTrade(sign, 3, ess); try diff --git a/EssentialsSigns/src/com/earth2me/essentials/signs/SignsPermissions.java b/EssentialsSigns/src/com/earth2me/essentials/signs/SignsPermissions.java new file mode 100644 index 000000000..911d12593 --- /dev/null +++ b/EssentialsSigns/src/com/earth2me/essentials/signs/SignsPermissions.java @@ -0,0 +1,55 @@ +package com.earth2me.essentials.signs; + +import com.earth2me.essentials.api.IPermission; +import com.earth2me.essentials.perm.BasePermission; +import java.util.HashMap; +import java.util.Locale; +import java.util.Map; + +public class SignsPermissions { + public static final IPermission COLOR = new BasePermission("essentials.signs.","color"); + + public static final IPermission PROTECTION_OVERRIDE = new BasePermission("essentials.signs.protection.", "override"); + + public static final IPermission TRADE_OVERRIDE = new BasePermission("essentials.signs.trade.", "override"); + + + private static Map<String, IPermission> createpermissions = new HashMap<String, IPermission>(); + + public static IPermission getCreatePermission(final String signName) + { + IPermission perm = createpermissions.get(signName); + if (perm == null) + { + perm = new BasePermission("essentials.signs.create.",signName.toLowerCase(Locale.ENGLISH)); + createpermissions.put(signName, perm); + } + return perm; + } + + private static Map<String, IPermission> usepermissions = new HashMap<String, IPermission>(); + + public static IPermission getUsePermission(final String signName) + { + IPermission perm = usepermissions.get(signName); + if (perm == null) + { + perm = new BasePermission("essentials.signs.create.",signName.toLowerCase(Locale.ENGLISH)); + usepermissions.put(signName, perm); + } + return perm; + } + + private static Map<String, IPermission> breakpermissions = new HashMap<String, IPermission>(); + + public static IPermission getBreakPermission(final String signName) + { + IPermission perm = breakpermissions.get(signName); + if (perm == null) + { + perm = new BasePermission("essentials.signs.create.",signName.toLowerCase(Locale.ENGLISH)); + breakpermissions.put(signName, perm); + } + return perm; + } +} |