Adding Permissions during an OnPlayerJoinEvent

Discussion in 'Plugin Development' started by Xerfox, Jan 23, 2014.

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

    Xerfox

    Just wondering if it's possible to add a permission to a player at all through bukkit, without coding up a permissions plugin, and how I could do it through an OnPlayerJoinEvent(). Thanks I appreciate all the help I can get!
     
  2. Offline

    Kevin35

    Here's how you test if a player has permission:
    //(We'll pretend like p has been defined as a Player and we have a permission called something.whatever)
    p.hasPermission("something.whatever")
    //^That returns a boolean value. Here's how you might apply it:
    if(p.hasPermission("something.whatever"))
    {
    //do stuff
    }
     
  3. Offline

    Xerfox

    That's not what I was asking. I don't want to check if the player has a permission, I already know how to do that. I want to make it so that when a player joins it checks if they don't have a certain permission, and if they don't, then ADD a permission. How can I give e.getPlayer(), a permission when they join.
     
  4. Offline

    random_username

    I think he meant to add/give a permission to a player, not to check if the player had a permission :p

    Edit: Ninja'd
     
  5. Offline

    Kevin35

    There's probably a better way to do this but a last resort would be to send a command from the console automatically giving them the permission if you really don't want to make a simple permissions plugin.
    Code:java
    1. @EventHandler
    2. public void onPlayerJoin(PlayerJoinEvent event)
    3. {
    4. String cmd;
    5. //^Whatever command you want to use
    6. if(!event.getPlayer().hasPermission("something.whatever"))
    7. {
    8. Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), cmd);
    9. }
    10. }
     
  6. Offline

    random_username

    Xerfox and jboy44 like this.
  7. Offline

    Xerfox

    Thanks I figured it out from there! Thanks man I really do appreciate it!
     
Thread Status:
Not open for further replies.

Share This Page