Guest User

Permissions Tutorial

a guest
Mar 7th, 2015
4,519
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //C48 / VenomEater552 TUTORIAL
  2.  
  3. //Interested in giving players permissions within your plugin? Have you found out that the bukkit tutorial is too confusing?
  4. //Look no further. I'm going to show you how to give players permissions within your bukkit/spigot plugin.
  5.  
  6. //First, you're going to want to make a HashMap that will store our PermissionAttachments we give to our players.
  7. //This will hold information for the permissions we are going to set.
  8.  
  9. HashMap<UUID, PermissionAttachment> perms = new HashMap<UUID, PermissionAttachment>();
  10.  
  11. //Then, you want to get the player. Obviously, this will be important.
  12.  
  13. Player player = /* Player here */
  14.  
  15. //We then want to make a PermissionAttachment and add the player and their attachment to the hashmap.
  16.  
  17. PermissionAttachment attachment = player.addAttachment(/* class that extends JavaPlugin here */);
  18. perms.put(player.getUniqueId(), attachment);
  19.  
  20. //Now that we have the player and their PermissionAttachment, we can set and unset permissions.
  21.  
  22. PermissionAttachment pperms = perms.get(player.getUniqueId());
  23. pperms.setPermission("permission.here", true);
  24.  
  25. //If you want to remove a permission, do not setPermission to false. This is different from removing the permission. Do as follows.
  26.  
  27. perms.get(player.getUniqueId()).unsetPermission("permission.here");
  28.  
  29. //That should be about it. You can implement this into your code however you want. The best way to store permissions to add for players is generally to add a string list in a config, and get each string from the string list and set it for the player.
  30.  
  31. //Thank you for reading, and I hope this helped anyone who wanted a tutorial on this. :-)
  32.  
  33. http://www.spigotmc.org/threads/tutorial-giving-removing-player-permissions.53840/
RAW Paste Data