Search in sources :

Example 6 with NodeTree

use of org.spongepowered.api.service.permission.NodeTree in project SpongeCommon by SpongePowered.

the class MemorySubjectData method clearFallbackPermissionValues.

@Override
public CompletableFuture<Boolean> clearFallbackPermissionValues() {
    boolean anyUpdated = false;
    for (final Set<Context> key : this.permissions.keySet()) {
        while (true) {
            final NodeTree oldTree = this.permissions.get(key);
            if (oldTree == null || oldTree.rootValue() == Tristate.UNDEFINED) {
                continue;
            }
            if (this.updateCollection(this.permissions, key, oldTree, oldTree.withRootValue(Tristate.UNDEFINED))) {
                anyUpdated = true;
                break;
            }
        }
    }
    this.onUpdate();
    return CompletableFuture.completedFuture(anyUpdated);
}
Also used : Context(org.spongepowered.api.service.context.Context) NodeTree(org.spongepowered.api.service.permission.NodeTree)

Example 7 with NodeTree

use of org.spongepowered.api.service.permission.NodeTree in project SpongeCommon by SpongePowered.

the class NodeTreeTest method testCreateFromValues.

@Test
public void testCreateFromValues() 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 nodes = NodeTreeTest.FACTORY.ofBooleans(testPermissions, Tristate.UNDEFINED);
    Assertions.assertEquals(Tristate.TRUE, nodes.get("generate.rainbow"));
    Assertions.assertEquals(Tristate.TRUE, nodes.get("generate.rainbow.double"));
    Assertions.assertEquals(Tristate.FALSE, nodes.get("generate.sunset"));
    Assertions.assertEquals(Tristate.FALSE, nodes.get("generate.sunset.east"));
    Assertions.assertEquals(Tristate.TRUE, nodes.get("generate.thunderstorm"));
    Assertions.assertEquals(Tristate.FALSE, nodes.get("generate.thunderstorm.explosive"));
    Assertions.assertEquals(Tristate.UNDEFINED, nodes.get("random.perm"));
}
Also used : HashMap(java.util.HashMap) NodeTree(org.spongepowered.api.service.permission.NodeTree) Test(org.junit.jupiter.api.Test)

Aggregations

NodeTree (org.spongepowered.api.service.permission.NodeTree)7 HashMap (java.util.HashMap)4 Test (org.junit.jupiter.api.Test)4 Context (org.spongepowered.api.service.context.Context)1 Tristate (org.spongepowered.api.util.Tristate)1