Permissions Access

Discussion in 'Plugin Development' started by Bubby4j, Mar 11, 2011.

Thread Status:
Not open for further replies.
  1. Offline

    Bubby4j

    How can I access the permissions plugin and ask it if user x has permission for y? I can't seem to find any documentation on it.
     
  2. Offline

    saturnine_nl

  3. Offline

    Bubby4j

    Thanks!
    Code:
            if (!(SuperJump).Permissions.has(player, "superjump.use")) {
                  return;
              }
    When I try to reference my plugin's main, eclipse says it doesn't exist, any ideas? Do I need to make a new main in my Player Listener?
     
  4. Offline

    darknesschaos

    I will give you a gift. For all of my permissions needs I make a single class that I access statically for everything, works like a charm, and you could add support for other permissions plugs as well.
    Code:
    package Your.Package;
    
    import org.bukkit.block.Sign;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.Plugin;
    
    import com.nijiko.permissions.PermissionHandler;
    import com.nijikokun.bukkit.Permissions.Permissions;
    
    
    public class PermissionsHandler {
    
        private static PermissionHandler permissions = null;
        public static final String permissionErr = "You don't have permission to use that.";
    
        private static boolean permissionsEnabled = false;
    
        public static void setupPermissions(SignTrader plugin) {
            Plugin test = plugin.getServer().getPluginManager().getPlugin("Permissions");
            if (test != null) {
                permissions = ((Permissions)test).getHandler();
                plugin.log.info("["+plugin.name+"] Permission found, using Permissions from TheYeti");
                permissionsEnabled = true;
                return;
            }
    
            plugin.log.info("["+plugin.name+"] Permission system not enabled. Using default.");
        }
    
        private static boolean checkNode(Player p, String node){
            if(permissions!= null){
                if(!Permissions.Security.permission(p, node))
                    return false;
                else
                    return true;
            }
            return false;
        }
    
        public static boolean canSetGlobalSign(Player p){
            //Checks to see if the player can set signs that get and give global values (aka not tied to an account)
            if (!permissionsEnabled)
                return p.isOp();
            else
                return checkNode(p, "signtrader.makeGlobalSign");
        }
    
        public static  boolean canSetPersonalSign(Player p){
            //Checks to see if the player has permission to make trading signs
            if (permissionsEnabled)
                return checkNode(p, "signtrader.makePersonalSign");
    
            return true;
        }
    
        public static boolean canBreakSign(Sign s, Player p, SignTrader plugin){
            //This checks to see if player p is the allowed to break the sign in SignLocs
            if (isSignOwner(s,p,plugin))
                return true;
    
            if (permissionsEnabled)
                return checkNode(p, "signtrader.admin.breakAnySign");
    
            return p.isOp();
        }
    
        public static boolean isSignOwner(Sign s, Player p, SignTrader plugin){
            String LText = s.getLine(0);
            if (LText.compareToIgnoreCase("Global")==0 && canSetGlobalSign(p))
                return true;
    
            String location = s.getBlock().getX() + ":"
                            + s.getBlock().getY() + ":"
                            + s.getBlock().getZ() + ":"
                            + s.getBlock().getWorld().getName();
    
            if(!plugin.signLocs.containsKey(location))
                return true;
    
            if(plugin.signLocs.get(location).compareToIgnoreCase(p.getName()) == 0)
                return true;
    
            return false;
        }
    
        public static boolean canUseSign(Player p){
            //Checks to see if the player can use signs.
            if (permissionsEnabled)
                return checkNode(p, "signtrader.use");
    
            return true;
        }
    
    }
     
  5. Offline

    Bubby4j

    Thanks!
     
Thread Status:
Not open for further replies.

Share This Page