Plugin Help Permissions question

Discussion in 'Plugin Help/Development/Requests' started by Bobbelty, Mar 31, 2017.

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

    Bobbelty

    EDIT: What is wrong with the <code> ?

    Hi. I need someone to clarify this for me since I don't understand:

    Code:
    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    
    if (cmd.getName().equalsIgnoreCase("broadcast") || cmd.getName().equalsIgnoreCase("bc")) {
    
    if (args[0].equalsIgnoreCase("admin")) {
    
    if (sender.hasPermission("ventacore.broadcast.send.admin")) {
    
    if(args[1] == null) {
    
    sender.sendMessage("Ops, you forgot the message!");
    
    
    
    }
    
    
    }
    
    
    }
    
    
    }
    
    This is just one part of the code. But now, how should I do if the player does not have permissions. Where do I add that line? Or is it just an else statement that is needed?
     
    Last edited by a moderator: Mar 31, 2017
  2. Offline

    timtower Moderator Moderator

    @Bobbelty You posted html, this forum blocks that and uses bbcode.
    You just need an else for the no permission stuff.
    And check the length of the array, don't check if a value is null, it will throw an ArrayOutOfBoundsException
     
  3. Offline

    dNiym

    If(player.hasPermission())
    //do the command
    else {
    player.sendMessage("you do not have permission to use this command. "
    return;
    }

    The return statement will stop further execution in the method


    Sent from my iPhone using Tapatalk
     
Thread Status:
Not open for further replies.

Share This Page