Hooked into Permissions, How to Set nodes?

Discussion in 'Plugin Development' started by lpjz2, Mar 27, 2011.

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

    lpjz2

    I wanted to know how to hook into Permissions and set up nodes, i read this guide...

    https://github.com/TheYeti/Permissions/wiki/API-Reference

    and i set it all up, no errors, however when i add the last part...

    Code:
      if (!(MyPlugin).Permissions.has(player, "a.custom.node")) {
          return;
      }
    
    I rename MyPlugin to NewVid (thats the name of the Plugin) and i get a error
    under the NewVid...

    this is my OnCommand...
    Code:
    	public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args, Player player){
    
    
    		if(commandLabel.equalsIgnoreCase("NV")){
    			  if (!(NewVid).Permissions.has(player, "test.test"))
    			getServer().broadcastMessage(ChatColor.AQUA + "Lpjz2 just Uploaded a New VIDEO!");
    		 if (args.length == 1){
    		 if (args[0].equalsIgnoreCase("1")) {
    				getServer().broadcastMessage(ChatColor.RED + "Video is VERY Important, Watch ASAP");
    				return true;
    
     }
      }
       }
    
    		return false;
    
    no errors appart from "if (!(NewVid).Permissions.has"





    also if it matters, im getting 2 yellow errors (like the used error)...


    ____________________________________
    private void setupPermissions() {
    Plugin NewVid = this.getServer().getPluginManager().getPlugin("Permissions");

    if (this.Permissions == null) {
    if (NewVid != null) {
    this.Permissions = ((Permissions)NewVid).getHandler();
    } else {
    log.info("Permission system not detected, defaulting to OP");
    }

    ________________________________________


    any ideas?
     
  2. Offline

    Edward Hand

    What's the red error?
    Could you paste your NewVid code?
     
  3. Offline

    lpjz2

    Yh, the error just tells me to rename it... and this is my whole plugin (just 1 page)

    Code:
    package me.lpjz2.NewVid;
    
    import java.util.logging.Logger;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    ////
    import com.nijiko.permissions.PermissionHandler;
    import com.nijikokun.bukkit.Permissions.Permissions;
    import org.bukkit.plugin.Plugin;
    ////
    
    
    
    public class NewVid extends JavaPlugin {
        private static final Logger log = Logger.getLogger("Minecraft");
        public static PermissionHandler Permissions;
        
    
    
        
        public void onDisable() {
           log.info("NewVid Disabled - Lpjz2");
        }
    
    
        public void onEnable() {
              setupPermissions();
           log.info("NewVid Enabled - Lpjz2");
            
        }
    
    
    
        
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args, Player player){
    
    
            if(commandLabel.equalsIgnoreCase("NV")){
                  if (!(NewVid).Permissions.has(player, "test.test"))
                getServer().broadcastMessage(ChatColor.AQUA + "Lpjz2 just Uploaded a New VIDEO!");
             if (args.length == 1){
             if (args[0].equalsIgnoreCase("1")) {
                    getServer().broadcastMessage(ChatColor.RED + "Video is VERY Important, Watch ASAP");
                    return true;
    
     }
      }
       }
    
            return false;
    
        }
        
        
    
    
          private void setupPermissions() {
              
              Plugin NewVid = this.getServer().getPluginManager().getPlugin("Permissions");
              
              if (this.Permissions == null) {
                  if (NewVid != null) {
                      this.Permissions = ((Permissions)NewVid).getHandler();
                  } else {
                      log.info("Permission system not detected, defaulting to OP");
                  }
              }
          }
          
          
          
          
          
    }
    
    
    and thanks edward, you help me alot =)

    +1 Karma
     
  4. Offline

    Sammy

    Make a method more or less like this :
    Code:
        public boolean casUseTest(Player p) {
            if (UsePermissions) {
                return this.Permissions.has(p, "test.test");
            }
            return p.isOp();
        }
    and than use this on your cmd:
    Code:
    if (plugin.canUseTest(ply)) {
    //your code
       } else {
                    ply.sendMessage(ChatColor.RED + "You don't have permisson to use that command");
                }
     
  5. Offline

    lpjz2

    im not quite understanding it, can you modify the code i gave?

    thanks [cake]
     
  6. Offline

    Sammy

    You're in luck, I'm a nice guy ^^
    Try this:
    Code:
    package me.lpjz2.NewVid;
    
    import java.util.logging.Logger;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    ////
    import com.nijiko.permissions.PermissionHandler;
    import com.nijikokun.bukkit.Permissions.Permissions;
    import org.bukkit.plugin.Plugin;
    ////
    
    public class NewVid extends JavaPlugin {
    
        private static final Logger log = Logger.getLogger("Minecraft");
        public static PermissionHandler Permissions;
        private boolean UsePermissions;
    
        public void onDisable() {
            log.info("NewVid Disabled - Lpjz2");
        }
    
        public void onEnable() {
            setupPermissions();
            log.info("NewVid Enabled - Lpjz2");
    
        }
    
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args, Player player) {
            Player ply = (Player) sender;
            if (commandLabel.equalsIgnoreCase("NV")) {
                if (this.canUseTest(ply)) {
                    {
                        getServer().broadcastMessage(ChatColor.AQUA + "Lpjz2 just Uploaded a New VIDEO!");
                    }
                    if (args.length == 1) {
                        if (args[0].equalsIgnoreCase("1")) {
                            getServer().broadcastMessage(ChatColor.RED + "Video is VERY Important, Watch ASAP");
                            return true;
                        }
                    }
                } else {
                    ply.sendMessage(ChatColor.RED + "You don't have permisson to use that command");
                }
            }
            return false;
        }
    
        private void setupPermissions() {
    
            Plugin NewVid = this.getServer().getPluginManager().getPlugin("Permissions");
    
            if (this.Permissions == null) {
                if (NewVid != null) {
                    UsePermissions = true;
                    this.Permissions = ((Permissions) NewVid).getHandler();
                } else {
                    UsePermissions = false;
                    log.info("Permission system not detected, defaulting to OP");
                }
            }
        }
    
        public boolean canUseTest(Player p) {
            if (UsePermissions) {
                return this.Permissions.has(p, "test.test");
            }
            return p.isOp();
    
    }
    }
    
    EDIT: I forgot to put the else
     
  7. Offline

    lpjz2

    :D LOVE YOU :D
     
  8. Offline

    Sammy

    No problem my friend, we are here to help :D
     
  9. if (!(MyPlugin).Permissions.has(player, "a.custom.node")) { return; }

    It works fine without the !(MyPlugin) aswell :)
     
  10. Offline

    Sammy

    @Adamki11s Undertaker much ? ^^
    Let the dead RIP my friend
     
  11. @Sammy Didn't see that this was posted so long ago, It was still on the first page :p
     
Thread Status:
Not open for further replies.

Share This Page