Can somebody explain PermissionService

Link: PermissionService API JavaDocs

Under getUserSubjects we can read this phrase:

(This does have dashes. Mojang is stupid).

I would love to know what does this mean :smiley:
Also what is this interface supposed to be for?

It’s referring to UUIDs that contain dashes to separate sections of each UUID. AFAIK Mojang tends to not include dashes in UUIDs, while everyone else does.

As for the PermissionService interface itself, I’d rather let someone else more knowledgeable on the service explain. But if you know what Vault is (from Bukkit), it’s similar to that.

Thanks, I think I am close to understanding this :wink:

Is really PermissionService similar to Vault, I fought it is something more like interface to unify permission system on sponge, but I’ll wait for somebody to explain better.

That’s also what Vault is.

The PermissionService is the service that runs permissions. Every call to Subject#hasPermission routes through it. The default implementation is that of vanilla: players either are or are not operators, and if they are operators then they have every permission, and if they are not operators they have only the permissions that have been marked default. Just like every other service, a plugin can change this behavior to something else, through ServiceManager#setProvider.

If you don’t know what services are, it’s basically an API that plugins can implement. Each service has an interface, such as PermissionService, EconomyService, UserStorageService, etc. They also have an implementation (except for the EconomyService by default), registered with the ServiceManager. When you ask for the PermissionService (or when Sponge does during Subject#hasPermission), it returns whatever is currently implementing it, which may be the operator system, or PEX, or LuckPerms, or any other permission plugin.

So what happens if two plugins are trying to implement the same service?

There’s no concrete definition of ‘trying’. When ServiceManager#setProvider is called, it sets the provider. It is possible that another plugin will come along and set the provider to something else, but given the fact that servers are single-threaded, it’s not possible for two plugins to try to set the provider at exactly the same time.

OK, I think I have got it. Only one service provider is possible and the last provider set will be the actual provider.

1 Like