hasPermission() question

Discussion in 'Plugin Development' started by Vinceguy1, Jul 20, 2014.

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

    Vinceguy1

    If I were to do if(player.hasPermission())

    meaning I didn't put a string there, would it return true or false?
     
  2. Offline

    LCastr0

    It would not do anything, because the plugin would throw an error. Unless you used "" inside the (), then I'm not sure if it would be true or not. But if you want it to be true, just remove the if part...
     
  3. Offline

    Vinceguy1

    Assuming I put quotes, do you think it would be true or false?
     
  4. Offline

    LCastr0

    I think it would be true
     
  5. Offline

    Gater12

    Vinceguy1
    Depends if the player has the permission node.

    Why would you leave it empty? Mine as well remove it.
     
  6. Offline

    mazentheamazin

    Vinceguy1 Gater12 LCastr0
    Even though this is quite useless I might as well give you the answer; if the player has op this if statement will return true, otherwise it will return false. Let me explain why, if we look at PermissionsBase we will see that on PermissionsBase#hasPermission(String) it has some interesting statements; I'll go through them one by one. It will first check if the permission system has set a value on said permission, if so it will check for said value otherwise it will get the permissions set by plugins through their description files; if it isn't null it will get the value set if said value is null it will end up using the PermissionsDefault#getValue(boolean) which will return dependent if he is op or not. Hope I was able to help you gain some knowledge of the process of checking permissions!
     
  7. Offline

    LCastr0

    Though it throws an IllegalArgumentException, but thanks for the explanation :)
     
  8. Offline

    mazentheamazin

    LCastr0
    The string literal "" is not considered null; if I were to call 'if(player.hasPermission(null))' then it will throw an IllegalArgumentException (I'd still prefer it if they used @NotNull annotations though...)
     
Thread Status:
Not open for further replies.

Share This Page