From ba5d7a39813eac12c0de56de344e634179308ce8 Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Sat, 8 Oct 2011 18:44:47 +0200 Subject: [PATCH] Working on permissions handling --- src/com/massivecraft/factions/Factions.java | 2 +- .../factions/struct/Permission.java | 55 +++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 src/com/massivecraft/factions/struct/Permission.java diff --git a/src/com/massivecraft/factions/Factions.java b/src/com/massivecraft/factions/Factions.java index bd976317..75003195 100644 --- a/src/com/massivecraft/factions/Factions.java +++ b/src/com/massivecraft/factions/Factions.java @@ -56,7 +56,7 @@ public class Factions extends JavaPlugin { private final FactionsEntityListener entityListener = new FactionsEntityListener(); private final FactionsBlockListener blockListener = new FactionsBlockListener(); - private static PermissionHandler Permissions; + public static PermissionHandler Permissions; private static EssentialsChat essChat; // Commands diff --git a/src/com/massivecraft/factions/struct/Permission.java b/src/com/massivecraft/factions/struct/Permission.java new file mode 100644 index 00000000..b8a610fa --- /dev/null +++ b/src/com/massivecraft/factions/struct/Permission.java @@ -0,0 +1,55 @@ +package com.massivecraft.factions.struct; + +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import com.massivecraft.factions.Factions; + +public enum Permission +{ + PARTICIPATE("factions.participate"), + CREATE("factions.create"), + VIEW_ANY_POWER("factions.viewAnyPower"), + PEACEFUL_EXPLOTION_TOGGLE("factions.peacefulExplosionToggle"), + ADMIN_BYPASS("factions.adminBypass"), + CONFIG("factions.config"), + DISBAN("factions.disband"), + LOCK("factions.lock"), + MANAGE_SAFE_ZONE("factions.manageSafeZone"), + MANAGE_WAR_ZONE("factions.manageWarZone"), + OWNERSHIP_BYPASS("factions.ownershipBypass"), + RELOAD("factions.reload"), + SAVE_ALL("factions.saveall"), + SET_PEACEFUL("factions.setPeaceful"), + ; + + public final String node; + + Permission(final String node) + { + this.node = node; + } + + public boolean has(CommandSender sender) + { + //return CreativeGates.p.perm.has(sender, this.node); + } + + public static boolean isCommandDisabled(CommandSender sender, String command) + { + return (hasPerm(sender, "factions.commandDisable."+command) && !hasPerm(sender, "factions.commandDisable.none")); + } + + private static boolean hasPerm(CommandSender sender, String permNode) + { + if (Factions.Permissions == null || ! (sender instanceof Player)) + { + return sender.isOp() || sender.hasPermission(permNode); + } + + Player player = (Player)sender; + return Factions.Permissions.has(player, permNode); + } + + +}