Issues with .isOp()

Discussion in 'Plugin Development' started by mitchb, Jun 13, 2013.

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

    mitchb

    Hello, when running a command with the dependency of the player being op:

    Code:
     }else if(event.getMessage().toLowerCase().contains("helper") && event.getMessage().toLowerCase().contains("me") && event.getMessage().toLowerCase().contains("creative") && Bukkit.getPlayer(Bukkit.getConsoleSender().getName()).isOp()){
    I get an error in the console: http://prntscr.com/19u4pg

    I am unsure both what the error means and how to fix it, though I have tried multiple things, it seems it simply wont work. Any assistance is much appreciated.
     
  2. Offline

    slayr288

    mitchb

    The player you are getting returns null.
    Also, it's better to define the message as a variable instead of getting it multiple times.
     
  3. Offline

    mitchb

    slayr288 How would I get the player, then?
     
  4. Offline

    slayr288

    mitchb

    The problem is not the way you are getting it, but the string you are trying to get a player with is either not online or is invalid. Thus, returning null, thus giving you an NPE.
     
  5. Offline

    Gravity

    The code you're running isn't getting the player anyway. It would always return a static result, if it worked. Just check the CommandSender variable you define in the parameters of your method and check .isOp()

    slayr288
    "the string you are trying to get the player with" is not a player's name. He's using the ConsoleCommandSender every time to check if it's op.
     
  6. Offline

    mitchb

    Could you provide me with an example code please?
     
  7. Offline

    slayr288

    Gravity
    Oh, didn't see he was using ConsoleSender. Just saw getPlayer and came to my conclusion.
     
  8. Offline

    Gravity

    Literally

    Code:
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
        if(sender.isOp()){
            return true;
        }
        return false;
    }
    
     
  9. Offline

    mitchb

    Gravity Though as you can see it isn't a command, this code will still work? Sorry, first time using Chat events.
     
  10. Offline

    Gravity

    event.getPlayer().isOp()
     
Thread Status:
Not open for further replies.

Share This Page