LuckPerms

LuckPerms

41.4k Downloads

CachedData does not support transient lookups

bloodmc opened this issue ยท 5 comments

commented

LP LuckPerms-Bukkit-4.3.90
Paper 1.13.2

There doesn't seem to be a way to grab transient permissions from CachedData.

https://github.com/lucko/LuckPerms/blob/master/api/src/main/java/me/lucko/luckperms/api/caching/CachedData.java

If I attempt to simply grab all cached data with contexts, I have no way of knowing if the results I am getting back are from transient or persisted.

commented

Which methods in particular? I'm happy to port some of them to the API, but I don't really want to expose the whole PermissionService implementation to all platforms.

commented

I would need the following methods in a common interface to function the same

SubjectProxy

SubjectData getSubjectData()
SubjectData getTransientSubjectData()
Tristate getPermissionValue(@NonNull Set<Context> contexts, @NonNull String permission)
Optional<String> getOption(@NonNull Set<Context> contexts, @NonNull String key)
Set<Context> getActiveContexts()
boolean hasPermission(@NonNull String permission)
boolean hasPermission(@NonNull Set<Context> contexts, @NonNull String permission)

SubjectDataProxy

Map<String, String> getOptions(@NonNull Set<Context> contexts)
Map<String, Boolean> getPermissions(@NonNull Set<Context> contexts)
Map<Set<Context>, Map<String, String>> getAllOptions()
Map<Set<Context>, Map<String, Boolean>> getAllPermissions()
CompletableFuture<Boolean> setOption(@NonNull Set<Context> contexts, @NonNull String key, @Nullable String value)
CompletableFuture<Boolean> setPermission(@NonNull Set<Context> contexts, @NonNull String permission, @NonNull Tristate value)
CompletableFuture<Boolean> clearPermissions(@NonNull Set<Context> contexts)
CompletableFuture<Boolean> clearOptions(@NonNull Set<Context> contexts)

Here are a few of my use cases

https://github.com/MinecraftPortCentral/GriefPrevention/blob/master/src/main/java/me/ryanhamshire/griefprevention/permission/GPPermissionHandler.java#L318

https://github.com/MinecraftPortCentral/GriefPrevention/blob/master/src/main/java/me/ryanhamshire/griefprevention/migrator/GPPermissionMigrator.java#L48-L72

https://github.com/MinecraftPortCentral/GriefPrevention/blob/master/src/main/java/me/ryanhamshire/griefprevention/util/PermissionUtils.java#L83-L96

https://github.com/MinecraftPortCentral/GriefPrevention/blob/master/src/main/java/me/ryanhamshire/griefprevention/DataStore.java#L686-L736

https://github.com/MinecraftPortCentral/GriefPrevention/blob/master/src/main/java/me/ryanhamshire/griefprevention/command/ClaimFlagBase.java#L168-L171

https://github.com/MinecraftPortCentral/GriefPrevention/blob/master/src/main/java/me/ryanhamshire/griefprevention/GPPlayerData.java#L271-L309

commented

All of the data you need to implement those methods is already exposed in the API - it's just in a slightly different format.

You can see how the Sponge implementations are made here:

https://github.com/lucko/LuckPerms/blob/master/sponge/src/main/java/me/lucko/luckperms/sponge/service/model/permissionholder/PermissionHolderSubject.java
https://github.com/lucko/LuckPerms/blob/master/sponge/src/main/java/me/lucko/luckperms/sponge/service/model/permissionholder/PermissionHolderSubjectData.java

All of the methods in your "SubjectProxy" list above have equivalents in the CachedData API interface, and the methods in "SubjectDataProxy" can be implemented using the methods in the PermissionHolder interface.

commented

All of the lookups from within CachedData take account of both enduring (non-transient) and transient permissions.

If you only want to query transient, or only enduring, you can't use CachedData.

commented

If I can't use CachedData nor PermissionHolder, I would have to construct all these methods myself to handle permissions/contexts like Sponge proxies do.

For example, https://github.com/lucko/LuckPerms/tree/master/sponge/sponge-service-api7/src/main/java/me/lucko/luckperms/sponge/service/proxy/api7

These proxies contain all the required functionality that I will need for Bukkit. If this proxy could be moved to a common interface where I could make the same permission calls as Sponge then I would have no issues.