mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2025-01-23 16:51:43 +01:00
Reduce new instance creation further in TristateResult.Factory
This commit is contained in:
parent
2dc211a91e
commit
d762a0aaa6
@ -36,7 +36,8 @@ import org.bukkit.permissions.Permission;
|
||||
* Permission Processor for Bukkits "default" permission system.
|
||||
*/
|
||||
public class DefaultsProcessor implements PermissionProcessor {
|
||||
private static final TristateResult.Factory RESULT_FACTORY = new TristateResult.Factory(DefaultsProcessor.class);
|
||||
private static final TristateResult.Factory DEFAULT_PERMISSION_MAP_RESULT_FACTORY = new TristateResult.Factory(DefaultsProcessor.class, "default permission map");
|
||||
private static final TristateResult.Factory PERMISSION_MAP_RESULT_FACTORY = new TristateResult.Factory(DefaultsProcessor.class, "permission map");
|
||||
|
||||
private final LPBukkitPlugin plugin;
|
||||
private final boolean isOp;
|
||||
@ -50,13 +51,13 @@ public class DefaultsProcessor implements PermissionProcessor {
|
||||
public TristateResult hasPermission(String permission) {
|
||||
Tristate t = this.plugin.getDefaultPermissionMap().lookupDefaultPermission(permission, this.isOp);
|
||||
if (t != Tristate.UNDEFINED) {
|
||||
return RESULT_FACTORY.result(t, "default permission map");
|
||||
return DEFAULT_PERMISSION_MAP_RESULT_FACTORY.result(t);
|
||||
}
|
||||
|
||||
Permission defPerm = this.plugin.getPermissionMap().get(permission);
|
||||
if (defPerm == null) {
|
||||
return TristateResult.UNDEFINED;
|
||||
}
|
||||
return RESULT_FACTORY.result(Tristate.fromBoolean(defPerm.getDefault().getValue(this.isOp)), "permission map");
|
||||
return PERMISSION_MAP_RESULT_FACTORY.result(Tristate.fromBoolean(defPerm.getDefault().getValue(this.isOp)));
|
||||
}
|
||||
}
|
||||
|
@ -34,21 +34,11 @@ import me.lucko.luckperms.common.calculator.processor.PermissionProcessor;
|
||||
*/
|
||||
public final class TristateResult {
|
||||
|
||||
private static final Factory NULL_FACTORY = new Factory(null, null);
|
||||
public static final TristateResult UNDEFINED = new TristateResult(Tristate.UNDEFINED, null, null);
|
||||
|
||||
public static TristateResult of(Tristate result, Class<? extends PermissionProcessor> processorClass, String cause) {
|
||||
if (result == Tristate.UNDEFINED) {
|
||||
return UNDEFINED;
|
||||
}
|
||||
return new TristateResult(result, processorClass, cause);
|
||||
}
|
||||
|
||||
public static TristateResult of(Tristate result, Class<? extends PermissionProcessor> processorClass) {
|
||||
return of(result, processorClass, null);
|
||||
}
|
||||
|
||||
public static TristateResult of(Tristate result) {
|
||||
return of(result, null, null);
|
||||
return NULL_FACTORY.result(result);
|
||||
}
|
||||
|
||||
private final Tristate result;
|
||||
@ -87,11 +77,15 @@ public final class TristateResult {
|
||||
private final TristateResult trueResult;
|
||||
private final TristateResult falseResult;
|
||||
|
||||
public Factory(Class<? extends PermissionProcessor> processorClass) {
|
||||
public Factory(Class<? extends PermissionProcessor> processorClass, String defaultCause) {
|
||||
this.processorClass = processorClass;
|
||||
|
||||
this.trueResult = of(Tristate.TRUE, processorClass);
|
||||
this.falseResult = of(Tristate.FALSE, processorClass);
|
||||
this.trueResult = new TristateResult(Tristate.TRUE, processorClass, defaultCause);
|
||||
this.falseResult = new TristateResult(Tristate.FALSE, processorClass, defaultCause);
|
||||
}
|
||||
|
||||
public Factory(Class<? extends PermissionProcessor> processorClass) {
|
||||
this(processorClass, null);
|
||||
}
|
||||
|
||||
public TristateResult result(Tristate result) {
|
||||
@ -108,10 +102,10 @@ public final class TristateResult {
|
||||
}
|
||||
|
||||
public TristateResult result(Tristate result, String cause) {
|
||||
if (cause == null) {
|
||||
return result(result);
|
||||
if (result == Tristate.UNDEFINED) {
|
||||
return UNDEFINED;
|
||||
}
|
||||
return of(result, this.processorClass, cause);
|
||||
return new TristateResult(result, this.processorClass, cause);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -35,7 +35,8 @@ import me.lucko.luckperms.nukkit.inject.PermissionDefault;
|
||||
* Permission Processor for Nukkits "default" permission system.
|
||||
*/
|
||||
public class DefaultsProcessor implements PermissionProcessor {
|
||||
private static final TristateResult.Factory RESULT_FACTORY = new TristateResult.Factory(DefaultsProcessor.class);
|
||||
private static final TristateResult.Factory DEFAULT_PERMISSION_MAP_RESULT_FACTORY = new TristateResult.Factory(DefaultsProcessor.class, "default permission map");
|
||||
private static final TristateResult.Factory PERMISSION_MAP_RESULT_FACTORY = new TristateResult.Factory(DefaultsProcessor.class, "permission map");
|
||||
|
||||
private final LPNukkitPlugin plugin;
|
||||
private final boolean isOp;
|
||||
@ -49,13 +50,13 @@ public class DefaultsProcessor implements PermissionProcessor {
|
||||
public TristateResult hasPermission(String permission) {
|
||||
Tristate t = this.plugin.getDefaultPermissionMap().lookupDefaultPermission(permission, this.isOp);
|
||||
if (t != Tristate.UNDEFINED) {
|
||||
return RESULT_FACTORY.result(t, "default permission map");
|
||||
return DEFAULT_PERMISSION_MAP_RESULT_FACTORY.result(t);
|
||||
}
|
||||
|
||||
PermissionDefault def = PermissionDefault.fromPermission(this.plugin.getPermissionMap().get(permission));
|
||||
if (def == null) {
|
||||
return TristateResult.UNDEFINED;
|
||||
}
|
||||
return RESULT_FACTORY.result(Tristate.fromBoolean(def.getValue(this.isOp)), "permission map");
|
||||
return PERMISSION_MAP_RESULT_FACTORY.result(Tristate.fromBoolean(def.getValue(this.isOp)));
|
||||
}
|
||||
}
|
||||
|
@ -33,7 +33,8 @@ import me.lucko.luckperms.sponge.service.model.LPPermissionService;
|
||||
import me.lucko.luckperms.sponge.service.model.LPSubject;
|
||||
|
||||
public abstract class DefaultsProcessor implements PermissionProcessor {
|
||||
private static final TristateResult.Factory RESULT_FACTORY = new TristateResult.Factory(DefaultsProcessor.class);
|
||||
private static final TristateResult.Factory TYPE_DEFAULTS_RESULT_FACTORY = new TristateResult.Factory(DefaultsProcessor.class, "type defaults");
|
||||
private static final TristateResult.Factory ROOT_DEFAULTS_RESULT_FACTORY = new TristateResult.Factory(DefaultsProcessor.class, "root defaults");
|
||||
|
||||
protected final LPPermissionService service;
|
||||
private final ImmutableContextSet contexts;
|
||||
@ -49,12 +50,12 @@ public abstract class DefaultsProcessor implements PermissionProcessor {
|
||||
public TristateResult hasPermission(String permission) {
|
||||
Tristate t = getTypeDefaults().getPermissionValue(this.contexts, permission);
|
||||
if (t != Tristate.UNDEFINED) {
|
||||
return RESULT_FACTORY.result(t, "type defaults");
|
||||
return TYPE_DEFAULTS_RESULT_FACTORY.result(t);
|
||||
}
|
||||
|
||||
t = this.service.getRootDefaults().getPermissionValue(this.contexts, permission);
|
||||
if (t != Tristate.UNDEFINED) {
|
||||
return RESULT_FACTORY.result(t, "root defaults");
|
||||
return ROOT_DEFAULTS_RESULT_FACTORY.result(t);
|
||||
}
|
||||
|
||||
return TristateResult.UNDEFINED;
|
||||
|
@ -79,7 +79,7 @@ public class MonitoringPermissionCheckListener {
|
||||
|
||||
MonitoredPermissionFunction(PermissionSubject subject, PermissionFunction delegate) {
|
||||
this.delegate = delegate;
|
||||
this.name = determineName(subject);
|
||||
this.name = "internal/" + determineName(subject);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -88,9 +88,8 @@ public class MonitoringPermissionCheckListener {
|
||||
|
||||
// report result
|
||||
Tristate result = CompatibilityUtil.convertTristate(setting);
|
||||
String name = "internal/" + this.name;
|
||||
|
||||
MonitoringPermissionCheckListener.this.plugin.getVerboseHandler().offerPermissionCheckEvent(PermissionCheckEvent.Origin.PLATFORM_LOOKUP_CHECK, name, ContextSet.empty(), permission, TristateResult.of(result));
|
||||
MonitoringPermissionCheckListener.this.plugin.getVerboseHandler().offerPermissionCheckEvent(PermissionCheckEvent.Origin.PLATFORM_LOOKUP_CHECK, this.name, ContextSet.empty(), permission, TristateResult.of(result));
|
||||
MonitoringPermissionCheckListener.this.plugin.getPermissionRegistry().offer(permission);
|
||||
|
||||
return setting;
|
||||
|
Loading…
Reference in New Issue
Block a user