Solved hasPermission() problems

Discussion in 'Plugin Development' started by MrLarssonJr, Aug 23, 2013.

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

    MrLarssonJr

    Hi!

    Been working on a plugin where i need to check if the player has a permission or not. Easy enough I thought since I've been able to get it to work multiple times before.

    I do this check in a PlayerLoginEvent listener method. The check is done with nothing more fancy then a if-statment with the player.hasPermission(insertPermissionHere) as argument.

    Code:java
    1. @EventHandler
    2. public void onPlayerLoginEvent(PlayerLoginEvent event) { //Check if player is supposed to have infinite potion, if so add player to task
    3. Player player = event.getPlayer(); //Extract player from event for ease of use
    4. plugin.getLogger().info(player.getName() + " loggad in"); //Debug
    5.  
    6. if(player.hasPermission("abilities.trait.speed1")) { //If player has permission, then add to speed1
    7. plugin.getLogger().info("s1"); //Debug
    8. speed1.addPlayer(player); //Add player
    9. }
    10. else if(player.hasPermission("abilities.trait.speed2")) { //If player has permission, then add to speed2
    11. plugin.getLogger().info("s1"); //Debug
    12. speed1.addPlayer(player); //Add player
    13. }
    14. else if(player.hasPermission("abilities.trait.speed3")) { //If player has permission, then add to speed3
    15. plugin.getLogger().info("s1"); //Debug
    16. speed1.addPlayer(player); //Add player
    17. }
    18.  
    19. if(player.hasPermission("abilities.trait.jump1")) { //If player has permission, then add to jump1
    20. plugin.getLogger().info("s1"); //Debug
    21. jump1.addPlayer(player); //Add player
    22. }
    23. else if(player.hasPermission("abilities.trait.jump2")) { //If player has permission, then add to jump2
    24. plugin.getLogger().info("s1"); //Debug
    25. jump2.addPlayer(player); //Add player
    26. }
    27. else if(player.hasPermission("abilities.trait.jump3")) { //If player has permission, then add to jump3
    28. plugin.getLogger().info("s1"); //Debug
    29. jump3.addPlayer(player); //Add player
    30. }
    31. }


    My problem is that no matter what I try, no hasPermission() seems to return true.

    I tried to set my test player to Op, and then it works. (But obviously no control over the permissions then.) That makes me think I misspelled the permissions strings, which does not seem to be the problem.

    Code:
    users:
        MrLarssonJr:
            permissions:
                abilities.trait.jump3: true
    If anyone has a idea what's wrong I would be very interested to listen to it! :)

    Have a good day!
     
  2. Offline

    hubeb

    Im shooting in the dark here, but you can try a switch statement
     
  3. Offline

    MrLarssonJr

    An idea that just poped in to my head.
    PlayerLoginEvent event triggers when a player tries to login to let plugin have a say in the matter before the player is actually online. Because of this the players permission might not be loaded?

    And thanks for the suggestion! Shall try it right away!
     
  4. Offline

    Dippoakabob

    Switch is only numbers, so you may need to switch some things around (no pun intended) and it may work.
     
    _Dashy likes this.
  5. Offline

    Cirno

    You can switch(Object) in JRE 7 now.

    Try scheduling something; you can look up "bukkit schedular"
     
  6. Offline

    hubeb

    Dippoakabob
    Switch can be for anything, you can switch entities and strings as well
    Code:java
    1. EntityType eName = event.getEntityType();
    2. switch(eName){
    3. case ZOMBIE:
    4. break;
    5. case SKELETON:
    6. break;
    7. case SPIDER:
    8. break;
    9. case CAVE_SPIDER:
    10. break;
    11. case CREEPER:
    12. break;
    13. }
     
  7. Offline

    MrLarssonJr

    Think I shall try to schedule the code to be executed x seconds after the plugin get event as @Cirni suggested. But that will have to be tomorrow since it's getting late.
     
  8. Offline

    Dippoakabob

    Sorry, should have known better. You can. I was taught in Java 6 and I had forgotten that implementation in Java 7
     
    _Dashy likes this.
  9. Offline

    MrLarssonJr

    Solved it as Cirno suggested, which leaves me to believe my thesis about permissions not being loaded being true.

    Thanks for all help!
     
  10. Offline

    dunbaratu

    This is a side-subject: but the plugin tutorials explicitly tell people to compile plugins for java 1.6 and not 1.7 yet. The docs claim the craftbukkit server is supposed to able to run on systems that are still on 1.6. Maybe that information is out of date now, but because I'd read that I was explicitly avoiding 1.7.
     
Thread Status:
Not open for further replies.

Share This Page