Cache some PermissionProcessor instances

This commit is contained in:
Luck 2020-11-10 15:04:05 +00:00
parent 6564cc89f4
commit 93d0c54687
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
4 changed files with 30 additions and 6 deletions

View File

@ -45,8 +45,14 @@ import net.luckperms.api.query.QueryOptions;
public class BukkitCalculatorFactory implements CalculatorFactory {
private final LPBukkitPlugin plugin;
private final DefaultsProcessor opDefaultsProcessor;
private final DefaultsProcessor nonOpDefaultsProcessor;
public BukkitCalculatorFactory(LPBukkitPlugin plugin) {
this.plugin = plugin;
this.opDefaultsProcessor = new DefaultsProcessor(this.plugin, true);
this.nonOpDefaultsProcessor = new DefaultsProcessor(this.plugin, false);
}
@Override
@ -73,11 +79,11 @@ public class BukkitCalculatorFactory implements CalculatorFactory {
boolean op = queryOptions.option(BukkitContextManager.OP_OPTION).orElse(false);
if (metadata.getHolderType() == HolderType.USER && this.plugin.getConfiguration().get(ConfigKeys.APPLY_BUKKIT_DEFAULT_PERMISSIONS)) {
processors.add(new DefaultsProcessor(this.plugin, op));
processors.add(op ? this.opDefaultsProcessor : this.nonOpDefaultsProcessor);
}
if (op) {
processors.add(new OpProcessor());
processors.add(OpProcessor.INSTANCE);
}
return new PermissionCalculator(this.plugin, metadata, processors.build());

View File

@ -34,9 +34,15 @@ import net.luckperms.api.util.Tristate;
* Permission Processor which is added for opped users, to simply return true if
* no other processors match.
*/
public class OpProcessor implements PermissionProcessor {
public final class OpProcessor implements PermissionProcessor {
private static final TristateResult TRUE_RESULT = new TristateResult.Factory(OpProcessor.class).result(Tristate.TRUE);
public static final OpProcessor INSTANCE = new OpProcessor();
private OpProcessor() {
}
@Override
public TristateResult hasPermission(String permission) {
return TRUE_RESULT;

View File

@ -45,8 +45,14 @@ import net.luckperms.api.query.QueryOptions;
public class NukkitCalculatorFactory implements CalculatorFactory {
private final LPNukkitPlugin plugin;
private final DefaultsProcessor opDefaultsProcessor;
private final DefaultsProcessor nonOpDefaultsProcessor;
public NukkitCalculatorFactory(LPNukkitPlugin plugin) {
this.plugin = plugin;
this.opDefaultsProcessor = new DefaultsProcessor(this.plugin, true);
this.nonOpDefaultsProcessor = new DefaultsProcessor(this.plugin, false);
}
@Override
@ -73,11 +79,11 @@ public class NukkitCalculatorFactory implements CalculatorFactory {
boolean op = queryOptions.option(NukkitContextManager.OP_OPTION).orElse(false);
if (metadata.getHolderType() == HolderType.USER && this.plugin.getConfiguration().get(ConfigKeys.APPLY_NUKKIT_DEFAULT_PERMISSIONS)) {
processors.add(new DefaultsProcessor(this.plugin, op));
processors.add(op ? this.opDefaultsProcessor : this.nonOpDefaultsProcessor);
}
if (op) {
processors.add(new OpProcessor());
processors.add(OpProcessor.INSTANCE);
}
return new PermissionCalculator(this.plugin, metadata, processors.build());

View File

@ -34,9 +34,15 @@ import net.luckperms.api.util.Tristate;
* Permission Processor which is added for opped users, to simply return true if
* no other processors match.
*/
public class OpProcessor implements PermissionProcessor {
public final class OpProcessor implements PermissionProcessor {
private static final TristateResult TRUE_RESULT = new TristateResult.Factory(OpProcessor.class).result(Tristate.TRUE);
public static final OpProcessor INSTANCE = new OpProcessor();
private OpProcessor() {
}
@Override
public TristateResult hasPermission(String permission) {
return TRUE_RESULT;