[Solved] Permissions Questions

Hello Everyone,

I’m learning how to implement permissions to my plugin and noticed that simply adding this like.permission(getPluginContainer().getId()+".dz") to the command I’m registering won’t do the trick. I saw that the documentation provides a way to implement permissions, but now I’m wondering the following:

  1. If I use the PermissionService, would my plugin work with a plugin like LuckyPerms, or does using the default permission service mean I have to use the default Sponge permission system?

  2. If the answer is “no” to the first part of my question above, how is it that other plugin developers are able to do this? I’ve seen source code from other plugin developers and I don’t see any form of adding permissions to their plugins other than adding .permission(pluginName+".something") line to the code that creates their commands.

Any help would be greatly appreciated. Thanks!

What about it doesn’t work? Is the string generated exactly the string you are expecting, and have in your permission system? Try outputting it to be certain there isn’t an extra character you aren’t expecting…
Are you testing and finding that a player doesn’t have permission for the command, or that you are using the command without having given yourself permissions (in which case, ops? default trues?)
Have you given the right permission to the test account for the plugin?

1 Like

Sponge’s service API means that plugins can implement their own functionality with already-known APIs. When you get the PermissionService from the ServiceManager, if no permissions plugin is installed then it returns the op/not op system, but if a permissions plugin is installed, that plugin will provide its own implementation of the PermissionService, which you will get when you ask the ServiceManager for it. When you ask for the PermissionService, you get the object that LuckPerms registered as their implementation of it. So yes, that does work.
And other ways of using permissions include calls to Subject#hasPermission and CommandContext#checkPermission.

1 Like

the string is generated exactly as I expected. I have a test command that prints out what I expected. I found that a player who has been given the permission to a command does not have permission. I gave myself the permission successfully and it is saved as expected in LuckyPerm’s database file.

As @pie_flavor said, you can use something like player.hasPermission( <PERMISSION STRING> ); to check a player’s permissions.

1 Like

The output was true, but LuckyPerms isn’t picking that up and preventing me from using the command I attached the permission to.

What does your command spec look like?

CommandSpec:

	CommandSpec dreadZoneCmd = CommandSpec.builder()
			.description(Text.of("Dread Zone."))
			.permission(getPluginContainer().getId()+".dz")
			.executor(new DZCMD())
			.build();

The getPluginContainer().getId() returns “dreadzone”, as expected. This is how it looks like in the LuckyPerms database:

permissions:
- dreadzone.dz

This line returned true:

player.sendMessage(Text.of(player.hasPermission(Main.Main.getPluginContainer().getId()+".dz")));

I am a fool. I did not enter myself into my own LuckyPerm group. The code is flawless. My apologies everyone. I’ve been coding for too long today. Thank you all for your imput!