Hooking into PermGUI

HOOKING INTO PERMGUI



A Few Starting Notes

Adding this code to your plugin may be slightly tedious, but let's face it, it's probably not any worse than maintaining your plugin. You're also saving your users a lot of time by adding support and taking the time to add this code. Also, I'll love you. A lot.
You need to download this plugin then reference it as a library if you want to get anywhere.



Registering Permissions

You have two options here: unordered or ordered registering. The differences will be explained in each section.

Register Unordered Permissions

Q: Do you not really have a lot of permissions that need to be registered? Or do you not really care what order your permissions may show up in GUI?
A: This is the way you should add your permissions then.

Hooking into PermGUI this way isn't exactly how I'd recommend but I did add it so I'll explain. When you add unordered permissions you're declaring that you don't really care about the order that they appear in the GUI. However they will still appear together. This is because the hashmap you use to send the permissions to the GUI does not guarantee an order of elements.

Include this code in your onEnable method:

initializeGUIPermissions();

Next include this code that outlines adding permissions:

private void initializeGUIPermissions() {
	if(getServer().getPluginManager().isPluginEnabled("PermGUI")) {
		GUIPermissions guiPermissions = getServer().getServicesManager().load(GUIPermissions.class);

		HashMap<String, String> permissions = new HashMap<String, String>();	

		//adding permissions code will go here - described in next code block.

		guiPermissions.addPermissionsUnordered(toString(), permissions);
	}
}

Next comes adding the actual permissions. This is where it can get sort of tedious, you need to declare all of your permissions (or at least the ones you want to show in the GUI.

permissions.put("permissions.number.one", "this is the first example permissions");
permissions.put("permissions.number.two", "this is the second permission");

This obviously isn't what you should actually use, but it should be in this general form:

[hashmap name].put("[permission]", "[description]");


Register Ordered Permissions

I personally suggest this technique. Guarantees (to the best of my abilities) that your permissions will appear together and in the order you register them.

First include this code in your onEnable method:

initializeGUIPermissions();

Next include this code that outlines adding permissions:

private void initializeGUIPermissions(GUIPermissions guiPermissions) {
	if(getServer().getPluginManager().isPluginEnabled("PermGUI")) {
		GUIPermissions guiPermissions = getServer().getServicesManager().load(GUIPermissions.class);

		List<String> permissions = new ArrayList<String>();
		List<String> descriptions = new ArrayList<String>();	

		//adding permissions code will go here - described in next code block.

		guiPermissions.addPermissionsOrdered(toString(), permissions, descriptions);
	}
}

Next comes adding the actual permissions. This is where it can get sort of tedious, you need to declare all of your permissions (or at least the ones you want to show in the GUI.

permissions.add("permissions.number.one");
descriptions.add("this is the first example permissions");
permissions.add("permissons.number.two");
descriptions.add("this is the second permission");

This obviously isn't what you should actually use, but it should be in this general form:

[name of list containing your permissions].add("[permission]");
[name of list containing your descriptions].add("[description]");




Unregistering Permissions

I honestly don't expect any need for this, but it's present to provide completeness. PleasePleasePLEASE ensure that you include all of the permissions you have registered.

Before calling, ensure that PermGUI is loaded:

if (getServer().getPluginManager().isPluginEnabled("PermGUI")) {
	GUIPermissions guiPermissions = getServer().getServicesManager().load(GUIPermissions.class);

	Set<String> permissions = new HashSet<String>(); //Note that you only need to pass in permissions, 
						//appropriate descriptions will be removed with them.

	//removing permissions code will go here - described in next code block.

	guiPermissions.removePermissions(toString(), permissions);
}

Note that you will be adding to a set. This means that you cannot declare multiples of the same permission.

Next comes adding the actual permissions for removal. Boring, boring, I know.

permissions.add("permissions.number.one");
permissions.add("permissons.number.two");

Again, not the actual code you need, but put it in this form:

[name of set].add("[permission]";




Closing Notes

  • All of these methods return booleans based on how well things went. None of the code I've provided here utilizes this. You'll have to generate your own code if you wanted to take advantage of it.
    • addPermissionsUnordered returns:
      • true when everything goes as expected.
      • false if your plugin is already registered.
    • addPermissionsOrdered returns:
      • true when everthying goes as expected.
      • false if your plugin is already registered.
    • removePermissions returns:
      • true when everything goes as expected.
      • false if your plugin is not currently registered.
      • false if one of the permissions requested for removal is not registered. (Nothing at all is done in this case, nothing is removed).
  • A javadoc is included for these methods. In eclipse, if you right click PermGUI under referenced libraries then point the javadoc location to the same jar you downloaded you will be able to see notes when hovering over my public methods.
  • Anymore info you ask for and I think is pertinent will be added here.

Comments

Posts Quoted:
Reply
Clear All Quotes