Solved Permissions Help

Discussion in 'Plugin Development' started by aTmAggies, Apr 26, 2016.

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

    aTmAggies

    So I've been wondering this for a while, and when I try this it doesn't work! ( I ignores the if player has permission? And executes the first one )

    Code:
    @EventHandler(priority = EventPriority.HIGH)
    public void onPlayerJoin2(final PlayerJoinEvent e)
    {
        if(e.getPlayer().hasPermission("tabrank.owner"))
        {
            e.getPlayer().setPlayerListName("§4" + e.getPlayer().getName());
        }
        else if(e.getPlayer().hasPermission("tabrank.admin"))
        {
            e.getPlayer().setPlayerListName("§c" + e.getPlayer().getName());
        }
        else
        {
            e.getPlayer().setPlayerListName("§f" + e.getPlayer().getName());
        }
    }
    
    "The only dumb answer is no answer at all!"
     
  2. Offline

    maux

    Hey! Because an opped player inherits all the permissions, try doing this instead:
    Code:
    @EventHandler(priority = EventPriority.HIGH)
    public void onPlayerJoin2(final PlayerJoinEvent e) {
     if(e.getPlayer().isOp() && e.getPlayer().hasPermission("tabrank.owner")) {
      e.getPlayer().setPlayerListName("§4" + e.getPlayer().getName());
     } else {
      if(e.getPlayer().hasPermission("tabrank.admin")) {
       e.getPlayer().setPlayerListName("§c" + e.getPlayer().getName());
      }else{
       e.getPlayer().setPlayerListName("§f" + e.getPlayer().getName());
      }
     }
    }
    If that doesn't work, message me
     
  3. Offline

    Zombie_Striker

    @maux
    Thanks captain spoonfeeder! BTW, you have some mistakes in your code like every other post that spoonfeeds:
    1. You don't need to set your priority to high. Doing so just modifies the order the code is read (which does not really matter and just confuses other people)
    2. Adding "2" to a method name to avoid warnings in your IDE is BAD. Never do things just to remove errors. In this case, you should never have more than one of the same event in the entire plugin.
    3. Its bad to use the Paragraph symbol for chatcolors. Use the ChatColor enum instead. There have been dozens of threads that discuss why.
    4. Your formatting is off. You should have multiples of two or three spaces.
    5. You do not need the event to be final. The event is already final.
    With the above being said, this is why you should never spoonfeed code. This is worse, because not only is this bad code, but you did not even explain what you did, nor why it fixes the problem.
     
  4. Offline

    aTmAggies

    Still didn't work,
    1. It was in example of what it was so adding the 2 was okay
    2. § is fine, i've done it multipule of times and it works!
    3. Thanks for trying to help

    That's the same thing I put but you used "else" twice, that doesn't work

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
  5. Offline

    maux

    @Zombie_Striker
    1. I took his code and put else on it instead. I didn't test it. The reason it has all those "errors" is because I wasn't trying to change his entire code, resulting in "spoon-feeding." Smh.
    2. The spacing wasn't working when I clicked preview. Either way, the spacing really is irrelevant. It's the problem he wants fixed, not aesthetics.
    3. The only reason I know of '§' is bad is because when using a decompiler, it shows as '?.' Otherwise, it really is the same.
    However, I do find some of your information decent to this situation. And you're welcome.

    @aTmAggies Try these things:
    • Check if you have any errors on your console when you join the server (because PlayerJoinEvent is the event you are using) or if you start up the server
    • Check if you logged the class the event is in on your onEnable() function
    • Try to refrain from using more than one function containing the same event
    • Remember to put @EventHandler on top of every event (custom or built in)
    • Check to see if your plugin.yml file has the main class logged
    • Take away the final off the PlayerJoinEvent
     
    Last edited by a moderator: Apr 27, 2016
  6. Offline

    elian1203

    I am not sure what the problem is, you haven't really specified. You should also create a player object instead of putting e.getPlayer() every time. As for the code @maux put, he didn't put two else statements. He put an if/else statement in the else block. That works and would be better in your case because if the player has the owner permission they are likely to have the admin as well. Because of this, they would be set with the admin tag as opposed to the owner. By the way, we know the § symbol works, however it is not recommended. For specific reasons, I am not too sure. I know one of them being that Bukkit could change the symbol which is unlikely in my opinion.
     
Thread Status:
Not open for further replies.

Share This Page