Reduce the throughput on the contexts cache in ContextManager (#929)
This commit is contained in:
+10
-16
@@ -25,9 +25,9 @@
|
||||
|
||||
package me.lucko.luckperms.nukkit.model.permissible;
|
||||
|
||||
import me.lucko.luckperms.api.Contexts;
|
||||
import me.lucko.luckperms.api.Tristate;
|
||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||
import me.lucko.luckperms.common.contexts.ContextsCache;
|
||||
import me.lucko.luckperms.common.model.User;
|
||||
import me.lucko.luckperms.common.verbose.CheckOrigin;
|
||||
import me.lucko.luckperms.nukkit.LPNukkitPlugin;
|
||||
@@ -73,6 +73,9 @@ public class LPPermissible extends PermissibleBase {
|
||||
// the luckperms plugin instance
|
||||
private final LPNukkitPlugin plugin;
|
||||
|
||||
// caches context lookups for the player
|
||||
private final ContextsCache<Player> contextsCache;
|
||||
|
||||
// the players previous permissible. (the one they had before this one was injected)
|
||||
private PermissibleBase oldPermissible = null;
|
||||
|
||||
@@ -88,6 +91,7 @@ public class LPPermissible extends PermissibleBase {
|
||||
this.user = Objects.requireNonNull(user, "user");
|
||||
this.player = Objects.requireNonNull(player, "player");
|
||||
this.plugin = Objects.requireNonNull(plugin, "plugin");
|
||||
this.contextsCache = plugin.getContextManager().getCacheFor(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -96,7 +100,7 @@ public class LPPermissible extends PermissibleBase {
|
||||
throw new NullPointerException("permission");
|
||||
}
|
||||
|
||||
Tristate ts = this.user.getCachedData().getPermissionData(calculateContexts()).getPermissionValue(permission, CheckOrigin.PLATFORM_LOOKUP_CHECK);
|
||||
Tristate ts = this.user.getCachedData().getPermissionData(this.contextsCache.getContexts()).getPermissionValue(permission, CheckOrigin.PLATFORM_LOOKUP_CHECK);
|
||||
return ts != Tristate.UNDEFINED || PermissionDefault.OP.getValue(isOp());
|
||||
}
|
||||
|
||||
@@ -106,7 +110,7 @@ public class LPPermissible extends PermissibleBase {
|
||||
throw new NullPointerException("permission");
|
||||
}
|
||||
|
||||
Tristate ts = this.user.getCachedData().getPermissionData(calculateContexts()).getPermissionValue(permission.getName(), CheckOrigin.PLATFORM_LOOKUP_CHECK);
|
||||
Tristate ts = this.user.getCachedData().getPermissionData(this.contextsCache.getContexts()).getPermissionValue(permission.getName(), CheckOrigin.PLATFORM_LOOKUP_CHECK);
|
||||
if (ts != Tristate.UNDEFINED) {
|
||||
return true;
|
||||
}
|
||||
@@ -125,7 +129,7 @@ public class LPPermissible extends PermissibleBase {
|
||||
throw new NullPointerException("permission");
|
||||
}
|
||||
|
||||
Tristate ts = this.user.getCachedData().getPermissionData(calculateContexts()).getPermissionValue(permission, CheckOrigin.PLATFORM_PERMISSION_CHECK);
|
||||
Tristate ts = this.user.getCachedData().getPermissionData(this.contextsCache.getContexts()).getPermissionValue(permission, CheckOrigin.PLATFORM_PERMISSION_CHECK);
|
||||
return ts != Tristate.UNDEFINED ? ts.asBoolean() : PermissionDefault.OP.getValue(isOp());
|
||||
}
|
||||
|
||||
@@ -135,7 +139,7 @@ public class LPPermissible extends PermissibleBase {
|
||||
throw new NullPointerException("permission");
|
||||
}
|
||||
|
||||
Tristate ts = this.user.getCachedData().getPermissionData(calculateContexts()).getPermissionValue(permission.getName(), CheckOrigin.PLATFORM_PERMISSION_CHECK);
|
||||
Tristate ts = this.user.getCachedData().getPermissionData(this.contextsCache.getContexts()).getPermissionValue(permission.getName(), CheckOrigin.PLATFORM_PERMISSION_CHECK);
|
||||
if (ts != Tristate.UNDEFINED) {
|
||||
return ts.asBoolean();
|
||||
}
|
||||
@@ -159,16 +163,6 @@ public class LPPermissible extends PermissibleBase {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtains a {@link Contexts} instance for the player.
|
||||
* Values are determined using the plugins ContextManager.
|
||||
*
|
||||
* @return the calculated contexts for the player.
|
||||
*/
|
||||
private Contexts calculateContexts() {
|
||||
return this.plugin.getContextManager().getApplicableContexts(this.player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOp(boolean value) {
|
||||
this.player.setOp(value);
|
||||
@@ -176,7 +170,7 @@ public class LPPermissible extends PermissibleBase {
|
||||
|
||||
@Override
|
||||
public Map<String, PermissionAttachmentInfo> getEffectivePermissions() {
|
||||
Set<Map.Entry<String, Boolean>> permissions = this.user.getCachedData().getPermissionData(calculateContexts()).getImmutableBacking().entrySet();
|
||||
Set<Map.Entry<String, Boolean>> permissions = this.user.getCachedData().getPermissionData(this.contextsCache.getContexts()).getImmutableBacking().entrySet();
|
||||
Map<String, PermissionAttachmentInfo> ret = new HashMap<>(permissions.size());
|
||||
|
||||
for (Map.Entry<String, Boolean> entry : permissions) {
|
||||
|
||||
Reference in New Issue
Block a user