Adding a permission if a condition is met

Discussion in 'Spigot Plugin Development' started by Mariozgr8, Jun 4, 2017.

  1. Hi, the question is in the title how can i add a permission to a player if a certain condition is net ??
    or run a command if this same condition is met ?
    Thanks for advance <3
  2. Mas


    • Like Like x 2
    • Like Like x 1
  3. Thanks for helping :)
  4. Mas


    No problem, just try and remember to search next time :p
  5. Code (Text):
    HashMap<UUID, PermissionAttachment> perms =  new HashMap<UUID, PermissionAttachment>();
    Player p = (Player) e.getWhoClicked();
    PermissionAttachment attachment = p.addAttachment(/* Class that extends java plugin*/);
    Just i need a little more help, when i try and add the class Which is named MainClass, i get an error
    Can anyone help me ?
  6. If you want to add a permission, use that: PermissionAttachment pperms = perms.get(player.getUniqueId());
    pperms.setPermission("", true);
  7. yeah thats the rest of the code, but i didn't copy it :p but there is this method addAttachement that need a class. I just donno how to add the class :)
  8. I'm confused on what he is asking? What is the "condition" that needs to be met? Like a player statistic?
    Also, why not just make a method in your main class and use this and referencing it instead of making it in that class.
  9. Why not copy it, i mean it's just a tutorial. It's easy to understand how it works.

    Also could you show us any screenshot or more details?

    HashMap<UUID, PermissionAttachment> perms = new HashMap<UUID, PermissionAttachment>();
    this is just a hashmap
  10. so the condition is that the plugin open a gui, when a player click on an item it checks if the player has this item in hos inventory and if he do, it take out the item and then add a certain permission or execute a certain command
  11. Okay good, so you should set the permission like i told you.
  12. HashMap<UUID, PermissionAttachment> perms = new HashMap<UUID, PermissionAttachment>();
    Player player = /* Player here */
    PermissionAttachment attachment = player.addAttachment(/* class that extends JavaPlugin here */);
    perms.put(player.getUniqueId(), attachment);
    PermissionAttachment pperms = perms.get(player.getUniqueId());
    pperms.setPermission("", true);
    so this is the code that should be executed when i add a permission according to the tutorial above but i dont understand the arguments that i put in red :p
  13. Set it to PermissionAttachment attachment = player.addAttachment(this);
    or PermissionAttachment attachment = player.addAttachment(plugin); if the gui is in other class but if plugin doesnt work you have to take an instance from your main class to your gui class.
  14. This is your main class that extends JavaPlugin. Get an instance of it by passing it through the constructor of your class.

    Sent from my iPhone using Tapatalk
  15. Thanks for helping guys :)
    • Like Like x 1
  16. I hope you understood what we just explained to you. You're welcome.