use of org.spongepowered.api.util.Tristate in project SpongeCommon by SpongePowered.
the class MixinDedicatedPlayerList method onBypassPlayerLimit.
@Inject(method = "bypassesPlayerLimit", at = @At("HEAD"), cancellable = true)
private void onBypassPlayerLimit(GameProfile profile, CallbackInfoReturnable<Boolean> ci) {
final PermissionService permissionService = Sponge.getServiceManager().provideUnchecked(PermissionService.class);
final Subject subject = permissionService.getUserSubjects().getSubject(profile.getId().toString()).orElse(permissionService.getDefaults());
final Tristate tristate = subject.getPermissionValue(SubjectData.GLOBAL_CONTEXT, LoginPermissions.BYPASS_PLAYER_LIMIT_PERMISSION);
// if we are still using the default permission service
if (tristate == Tristate.UNDEFINED && permissionService instanceof SpongePermissionService) {
return;
}
ci.setReturnValue(tristate.asBoolean());
}
use of org.spongepowered.api.util.Tristate in project CmdScheduler by SimonFlash.
the class Config method loadTask.
public static void loadTask(ConfigurationNode node) {
try {
String name = (String) node.getKey();
String command = node.getNode("command").getString("");
Schedule schedule = getSchedule(node.getNode("schedule"));
Tristate async = node.getNode("async").isVirtual() ? Tristate.UNDEFINED : Tristate.fromBoolean(node.getNode("async").getBoolean(false));
tasks.put(name.toLowerCase(), new CommandTask(name, command.startsWith("/") ? command.substring(1) : command, schedule, async));
} catch (IllegalArgumentException e) {
CmdScheduler.get().getLogger().error(e.getMessage());
}
}
use of org.spongepowered.api.util.Tristate in project SpongeAPI by SpongePowered.
the class NodeTree method get.
/**
* Returns the value assigned to a specific node, or the nearest parent
* value in the tree if the node itself is undefined.
*
* @param node The path to get the node value at
* @return The tristate value for the given node
*/
public Tristate get(String node) {
Iterable<String> parts = NODE_SPLITTER.split(node.toLowerCase());
Node currentNode = this.rootNode;
Tristate lastUndefinedVal = Tristate.UNDEFINED;
for (String str : parts) {
if (!currentNode.children.containsKey(str)) {
break;
}
currentNode = currentNode.children.get(str);
if (currentNode.value != Tristate.UNDEFINED) {
lastUndefinedVal = currentNode.value;
}
}
return lastUndefinedVal;
}
use of org.spongepowered.api.util.Tristate in project SpongeCommon by SpongePowered.
the class NodeTreeTest method testWithAll.
@Test
public void testWithAll() throws Exception {
final Map<String, Boolean> testPermissions = new HashMap<>();
testPermissions.put("generate.rainbow", true);
testPermissions.put("generate.sunset", false);
testPermissions.put("generate", true);
testPermissions.put("generate.thunderstorm.explosive", false);
final NodeTree oldTree = NodeTreeTest.FACTORY.ofBooleans(testPermissions, Tristate.UNDEFINED);
final Map<String, Tristate> newPermissions = new HashMap<>();
newPermissions.put("generate.sunset.red", Tristate.TRUE);
newPermissions.put("generate.thunderstorm.explosive", Tristate.UNDEFINED);
newPermissions.put("something.new", Tristate.FALSE);
final NodeTree newTree = oldTree.withAllTristates(newPermissions);
Assertions.assertEquals(Tristate.FALSE, oldTree.get("generate.sunset.red"));
Assertions.assertEquals(Tristate.TRUE, newTree.get("generate.sunset.red"));
Assertions.assertEquals(Tristate.FALSE, oldTree.get("generate.thunderstorm.explosive"));
Assertions.assertEquals(Tristate.UNDEFINED, newTree.get("generate.thunderstorm.explosive"));
Assertions.assertEquals(Tristate.UNDEFINED, oldTree.get("something.new"));
Assertions.assertEquals(Tristate.FALSE, newTree.get("something.new"));
}
use of org.spongepowered.api.util.Tristate in project SpongeCommon by SpongePowered.
the class MixinSubject method hasPermission.
@Override
public boolean hasPermission(Set<Context> contexts, String permission) {
Subject subj = resolveNullable();
if (subj == null) {
return permDefault(permission).asBoolean();
}
// these calls are not directly forwarded to the subject, so we can
// apply permission defaults.
Tristate ret = getPermissionValue(contexts, permission);
switch(ret) {
case UNDEFINED:
return permDefault(permission).asBoolean();
default:
return ret.asBoolean();
}
}
Aggregations