mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-24 03:25:19 +01:00
Cache some PermissionProcessor instances
This commit is contained in:
parent
6564cc89f4
commit
93d0c54687
@ -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());
|
||||
|
@ -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;
|
||||
|
@ -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());
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user