sender.hasPermission()

Discussion in 'Plugin Development' started by the_merciless, Oct 28, 2012.

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

    the_merciless

    Will a command work from the console if you make this check:

    Code:
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
         
            if (cmd.getName().equalsIgnoreCase("plotz")){
             
                if (args[0].equalsIgnoreCase("give")){
                   if (sender.hasPermission("plotz.give"){
     
                    Player p = Bukkit.getPlayer(args[1]);
                    int toadd = Integer.parseInt(args[2]);
                    plugin.setMaxPlots(p, toadd);
                    sender.sendMessage("You have been given "+toadd+" more homes!");
             
                    int newmaxplots = plugin.getMaxPlots(p);
                    p.sendMessage("You now have " + newmaxplots + " available plots.");
             
                    return true;
                    }
                }
            }
            return false;
        }
     
    }
    This command isnt finished i just need to know if this line will work for player or console,
     
  2. Offline

    hawkfalcon

    If(sender instanceof player)
    Makes it only work for players. So no.
     
  3. Offline

    the_merciless

    sorry posted wrong code, edited now, pls look again
     
  4. Offline

    Royal_Soda

    the_merciless
    Pretty sure the command will be executed, since console inherits all permissions. (To my knowledge.)
     
  5. consoles also have permisions, so you can just use the permissions checks on them, they also have setOp() and isOp(), but mostly setOp() throws an exception
     
    com. BOY likes this.
  6. Offline

    the_merciless

    So does the console have all permissions by default or do i need to give them somehow?
     
  7. a console mostly have all the permissions a server operator also has
     
    com. BOY likes this.
  8. Offline

    the_merciless

    Final question, how can u check if an argument is a player?
     
Thread Status:
Not open for further replies.

Share This Page