Search in sources :

Example 1 with Tristate

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());
}
Also used : SpongePermissionService(org.spongepowered.common.service.permission.SpongePermissionService) PermissionService(org.spongepowered.api.service.permission.PermissionService) Tristate(org.spongepowered.api.util.Tristate) SpongePermissionService(org.spongepowered.common.service.permission.SpongePermissionService) Subject(org.spongepowered.api.service.permission.Subject) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 2 with Tristate

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());
    }
}
Also used : CommandTask(com.mcsimonflash.sponge.cmdscheduler.task.CommandTask) Tristate(org.spongepowered.api.util.Tristate)

Example 3 with Tristate

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;
}
Also used : Tristate(org.spongepowered.api.util.Tristate)

Example 4 with Tristate

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"));
}
Also used : HashMap(java.util.HashMap) Tristate(org.spongepowered.api.util.Tristate) NodeTree(org.spongepowered.api.service.permission.NodeTree) Test(org.junit.jupiter.api.Test)

Example 5 with Tristate

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();
    }
}
Also used : Tristate(org.spongepowered.api.util.Tristate) Subject(org.spongepowered.api.service.permission.Subject) IMixinSubject(org.spongepowered.common.interfaces.IMixinSubject)

Aggregations

Tristate (org.spongepowered.api.util.Tristate)9 Subject (org.spongepowered.api.service.permission.Subject)3 CommandTask (com.mcsimonflash.sponge.cmdscheduler.task.CommandTask)2 PermissionService (org.spongepowered.api.service.permission.PermissionService)2 Inject (org.spongepowered.asm.mixin.injection.Inject)2 HashMap (java.util.HashMap)1 BlockPos (net.minecraft.core.BlockPos)1 InteractionResult (net.minecraft.world.InteractionResult)1 MenuProvider (net.minecraft.world.MenuProvider)1 AbstractContainerMenu (net.minecraft.world.inventory.AbstractContainerMenu)1 ItemStack (net.minecraft.world.item.ItemStack)1 UseOnContext (net.minecraft.world.item.context.UseOnContext)1 BlockState (net.minecraft.world.level.block.state.BlockState)1 Test (org.junit.jupiter.api.Test)1 BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)1 CommandException (org.spongepowered.api.command.CommandException)1 CauseStackManager (org.spongepowered.api.event.CauseStackManager)1 InteractBlockEvent (org.spongepowered.api.event.block.InteractBlockEvent)1 NodeTree (org.spongepowered.api.service.permission.NodeTree)1 ServerLocation (org.spongepowered.api.world.server.ServerLocation)1