Cleanup some of the Sponge permission holder implementation code

This commit is contained in:
Luck
2019-02-07 15:35:09 +00:00
Unverified
parent 215031a1f3
commit dae64fc8c4
10 changed files with 120 additions and 83 deletions
@@ -298,7 +298,7 @@ public final class ArgumentPermissions {
throw new IllegalStateException("Unable to get a User for " + sender.getUuid() + " - " + sender.getName());
}
PermissionCache permissionData = user.getCachedData().getPermissionData(Contexts.of(contextSet, Contexts.global().getSettings()));
PermissionCache permissionData = user.getCachedData().getPermissionData(Contexts.global().setContexts(contextSet));
return !permissionData.getPermissionValue(NodeFactory.groupNode(targetGroupName), PermissionCheckEvent.Origin.INTERNAL).result().asBoolean();
}
@@ -107,7 +107,7 @@ public class MetaSetChatMeta extends SharedSubCommand {
// determine the priority to set at
if (priority == Integer.MIN_VALUE) {
MetaAccumulator metaAccumulator = holder.accumulateMeta(null, Contexts.of(context, Contexts.global().getSettings()));
MetaAccumulator metaAccumulator = holder.accumulateMeta(null, Contexts.global().setContexts(context));
metaAccumulator.complete();
priority = metaAccumulator.getChatMeta(this.type).keySet().stream().mapToInt(e -> e).max().orElse(0) + 1;
@@ -116,7 +116,7 @@ public class MetaSetTempChatMeta extends SharedSubCommand {
// determine the priority to set at
if (priority == Integer.MIN_VALUE) {
MetaAccumulator metaAccumulator = holder.accumulateMeta(null, Contexts.of(context, Contexts.global().getSettings()));
MetaAccumulator metaAccumulator = holder.accumulateMeta(null, Contexts.global().setContexts(context));
metaAccumulator.complete();
priority = metaAccumulator.getChatMeta(this.type).keySet().stream().mapToInt(e -> e).max().orElse(0) + 1;
@@ -29,26 +29,34 @@ import java.util.function.Supplier;
public enum NodeMapType {
ENDURING,
TRANSIENT;
ENDURING {
@Override
public void run(Runnable enduringTask, Runnable transientTask) {
enduringTask.run();
}
@Override
public <T> T supply(Supplier<T> enduringSupplier, Supplier<T> transientSupplier) {
return enduringSupplier.get();
}
},
TRANSIENT {
@Override
public void run(Runnable enduringTask, Runnable transientTask) {
transientTask.run();
}
@Override
public <T> T supply(Supplier<T> enduringSupplier, Supplier<T> transientSupplier) {
return transientSupplier.get();
}
};
// useful methods for fluent/conditional execution
public void run(Runnable ifEnduring, Runnable ifTransient) {
if (this == ENDURING) {
ifEnduring.run();
} else {
ifTransient.run();
}
}
public abstract void run(Runnable enduringTask, Runnable transientTask);
public <T> T supply(Supplier<T> ifEnduring, Supplier<T> ifTransient) {
if (this == ENDURING) {
return ifEnduring.get();
} else {
return ifTransient.get();
}
}
public abstract <T> T supply(Supplier<T> enduringSupplier, Supplier<T> transientSupplier);
}