Permissions not detected, how to stop the nodes check

Discussion in 'Plugin Development' started by Randy Schouten, Aug 8, 2011.

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

    Randy Schouten

    I can't find a way to make permissions stop checking when it's disabled.
    It'd throw a null pointer exception at the line where it checks for the permission.

    The only way I'd think this can be done, is make a full copy paste and check if permissions is enabled, then pick either one of them appropriate to if it was found or not.
    But I'm sure there's an easier way, can somebody help me out? :)
     
  2. Offline

    Vynlar

    I'm just brain storming here:

    If(isop)
    {
    If(permissionshandeler != null)
    {
    Permissions check
    }
    Else
    {
    return
    }

    //do stuff here

    }

    I'm on an iPad right now so the formatting and spelling is probably horrible.


    Edit: Agh, move the isop below the permissions stuff, I just thought of that flaw.

    Edit 2: Wait, this won't work. *slaps self*

    Edit3: I thought of a way to do it, I'll type it when i have access to a computer.
     
  3. Offline

    Randy Schouten

    Alright, thanks already :)
     
  4. How to do :p
    main class:
    Code:
    private PermissionHandler handler;
    private boolean usePermissions;
    public void onEnable(){
    Plugin p = getServer().getPluginManager().getPlugin("Permissions");
    if(p != null) {
    log.info("Found permissions");
    usePermissions = true;
    handler = //forget how to set handler :D
    } else{
    log.info("No permissions D:);
    usePermissions = false;
    }
    
    public boolean getUsePermissions() {
    return usePermissions;
    }
    
    onCommand:
    if(usePermissions) {
    // Permissions 2.x - 3.x support
    if(!handler.hasPermissions(player, "My.Permissions){ //Again, may be wrong
    if(!player.hasPermission("My.Permissions"){ // Bukkit perms support
    if(!player.isOp()){ // Check OP
    sender.sendMessage("Y U NO PERMISSION!");
    return true;
    }
    }
    }
    // Do your stuff, player has permission
    }else{
    if(!player.hasPermission("My.Permissions"){ // Bukkit perms support
    if(!player.isOp()){ // Check OP
    sender.sendMessage("Y U NO PERMISSION!");
    return true;
    }
    }
    // Do your stuff, player has permission. You could also check if permissionsHandler != null i guess 
     
  5. Offline

    EdTheLoon

    Make sure you also have a class that extends ServerListener so that your plugin knows when Permissions is being enabled and disabled. This way you can have a global variable that is a boolean and tracks whether permissions is enabled or not...rather than having to check each time. Example here
     
  6. Offline

    Randy Schouten

    I just thought of a way to do it.

    Code:
    if(this.getServer().getPluginManager().getPlugin("Permissions").isEnabled() && permissionHandler.has((Player) sender, "a.custom.node") || !this.getServer().getPluginManager().getPlugin("Permissions").isEnabled()){
    I feel clever now... :p
     
    Vynlar likes this.
  7. Offline

    feildmaster

    o.o That code scared me.
     
  8. Offline

    Randy Schouten

    How so :p
     
  9. Offline

    feildmaster

    I would have gone like so:
    Code:
    Boolean enabled = getServer().getPluginManager().getPlugin("Permissions").isEnabled();
    if(!enabled || enabled && permissions.has((Player)sender, "node")){} 
    not much different, but shortens code... and uses the same variable twice, instead of searching for the variable twice.
     
  10. Offline

    Vynlar

    Thats how I was going to do it, and an enabled variable.
     
Thread Status:
Not open for further replies.

Share This Page