crwdns130271:0crwdne130271:0

crwdns130273:0crwdne130273:0

crwdns130275:0crwdne130275:0

<PluginID>.<MainGroup>.<Subgroup1>...

crwdns130277:0crwdne130277:0

  • crwdns130279:0crwdne130279:0

  • crwdns130281:0crwdne130281:0

  • crwdns130283:0crwdne130283:0

  • crwdns130285:0crwdne130285:0

  • crwdns130287:0crwdne130287:0

  • crwdns130289:0crwdne130289:0

crwdns130291:0crwdne130291:0

crwdns130293:0crwdne130293:0

Note

crwdns130295:0crwdne130295:0

crwdns130297:0crwdne130297:0

crwdns130299:0crwdne130299:0

  • crwdns130301:0crwdne130301:0
    • crwdns130303:0crwdne130303:0

  • crwdns130305:0crwdne130305:0
    • crwdns130307:0crwdne130307:0

  • crwdns130309:0crwdne130309:0
    • crwdns130311:0crwdne130311:0

  • crwdns130313:0crwdne130313:0
    • crwdns130315:0crwdne130315:0

  • crwdns130317:0crwdne130317:0
    • crwdns130319:0crwdne130319:0

  • crwdns130321:0crwdne130321:0
    • crwdns130323:0crwdne130323:0

crwdns130325:0crwdne130325:0

crwdns130327:0:javadoc:crwdnd130327:0:javadoc:crwdne130327:0

crwdns130329:0crwdne130329:0

  • crwdns130331:0crwdne130331:0

  • crwdns130333:0crwdne130333:0

  • crwdns130335:0crwdne130335:0

  • crwdns130337:0crwdne130337:0

crwdns130339:0crwdne130339:0

crwdns130341:0crwdne130341:0

import org.spongepowered.api.service.permission.PermissionDescription;
import org.spongepowered.api.service.permission.PermissionDescription.Builder;
import org.spongepowered.api.service.permission.PermissionService;
import org.spongepowered.api.text.Text;
import java.util.Optional;

Optional<Builder> optBuilder = permissionService.newDescriptionBuilder(myPlugin);
if (optBuilder.isPresent()) {
    Builder builder = optBuilder.get();
    builder.id("myPlugin.commands.teleport.execute")
           .description(Text.of("Allows the user to execute the teleport command."))
           .assign(PermissionDescription.ROLE_STAFF, true)
           .register();
}

crwdns130343:0crwdne130343:0

myPlugin.commands.teleport.execute

Description: Allows the user to execute the teleport command.
Role: user
Owner: MyPlugin v1.2.3

crwdns130345:0crwdne130345:0

myPlugin.commands.teleport.worlds.<World>

Description: Allows the user to teleport to the world <World>.
Role: staff
Owner: MyPlugin v1.2.3

Tip

crwdns130347:0crwdne130347:0

crwdns130349:0crwdne130349:0

crwdns130351:0:javadoc:crwdnd130351:0:javadoc:crwdnd130351:0:javadoc:crwdnd130351:0:javadoc:crwdne130351:0

crwdns130353:0crwdne130353:0

crwdns130355:0crwdne130355:0

import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.world.World;

public boolean canTeleport(Player subject, World targetWorld) {
    return subject.hasPermission("myPlugin.command.teleport.execute")
            && (subject.getWorld() == targetWorld
                    || subject.hasPermission("myPlugin.command.teleport." + targetWorld.getName()));
}

crwdns130291:0crwdne130291:0

crwdns130357:0crwdne130357:0

crwdns130359:0:javadoc:crwdne130359:0

Warning

crwdns130361:0crwdne130361:0

Note

crwdns130363:0crwdne130363:0

crwdns130365:0crwdne130365:0

Note

crwdns130367:0crwdne130367:0

  • crwdns130369:0crwdne130369:0
    • crwdns130371:0crwdne130371:0

    • crwdns130373:0crwdne130373:0

  • crwdns130375:0crwdne130375:0
    • crwdns130371:0crwdne130371:0

    • crwdns130373:0crwdne130373:0

  • crwdns130377:0crwdne130377:0
    • crwdns130373:0crwdne130373:0

    • crwdns130371:0crwdne130371:0

  • crwdns130379:0crwdne130379:0
    • crwdns130373:0crwdne130373:0

    • crwdns130371:0crwdne130371:0

  • crwdns130381:0crwdne130381:0

crwdns130383:0crwdne130383:0

crwdns130385:0crwdne130385:0

  • crwdns130387:0crwdne130387:0
    • crwdns130389:0crwdne130389:0

  • crwdns130391:0crwdne130391:0
    • crwdns130393:0crwdne130393:0

  • crwdns130395:0crwdne130395:0
    • crwdns130397:0crwdne130397:0

  • crwdns130399:0crwdne130399:0
    • crwdns130401:0crwdne130401:0

  • crwdns130403:0crwdne130403:0
    • crwdns130405:0crwdne130405:0

Note

crwdns130407:0crwdne130407:0

crwdns130409:0crwdne130409:0

crwdns130411:0crwdne130411:0

  • crwdns130413:0crwdne130413:0

  • crwdns130415:0crwdne130415:0

crwdns130417:0crwdne130417:0

  • crwdns130419:0crwdne130419:0

  • crwdns130421:0crwdne130421:0

crwdns130423:0crwdne130423:0

crwdns130425:0crwdne130425:0

crwdns130427:0crwdne130427:0

crwdns130429:0crwdne130429:0

crwdns130431:0:javadoc:crwdne130431:0

crwdns130433:0crwdne130433:0

crwdns130435:0crwdne130435:0

crwdns130437:0:javadoc:crwdne130437:0

crwdns130439:0crwdne130439:0

Note

crwdns130441:0crwdne130441:0

crwdns130353:0crwdne130353:0

crwdns130443:0crwdne130443:0

import org.spongepowered.api.command.CommandSource;
import org.spongepowered.api.service.context.Context;
import org.spongepowered.api.service.context.ContextCalculator;
import org.spongepowered.api.service.permission.Subject;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.UUID;

public class ExampleCalculator implements ContextCalculator<Subject> {

    private static final Context IN_ANY_ARENA = new Context("myArenaPlugin-inAnyArena", "true");
    private static final Context NOT_ANY_ARENA = new Context("myArenaPlugin-inAnyArena", "false");
    private static final String ARENA_KEY = "myArenaPlugin-arena";

    private final Map<UUID, String> playerArenas = new HashMap<>();

    @Override
    public void accumulateContexts(Subject calculable, Set<Context> accumulator) {
        final Optional<CommandSource> commandSource = calculable.getCommandSource();

        if (commandSource.isPresent() && commandSource.get() instanceof Player) {
            final Player player = (Player) commandSource.get();

            final UUID uuid = player.getUniqueId();
            if (this.playerArenas.containsKey(uuid)) {
                accumulator.add(IN_ANY_ARENA);
                accumulator.add(new Context(ARENA_KEY, this.playerArenas.get(uuid)));
            } else {
                accumulator.add(NOT_ANY_ARENA);
            }
        }
    }

    @Override
    public boolean matches(Context context, Subject subject) {
        if (!context.equals(IN_ANY_ARENA) && !context.equals(NOT_ANY_ARENA) && !context.getKey().equals(ARENA_KEY)) {
            return false;
        }

        final Optional<CommandSource> commandSource = subject.getCommandSource();
        if (!commandSource.isPresent() || !(commandSource.get() instanceof Player)) {
            return false;
        }

        final Player player = (Player) commandSource.get();

        if (context.equals(IN_ANY_ARENA) && !this.playerArenas.containsKey(player.getUniqueId())) {
            return false;
        }

        if (context.equals(NOT_ANY_ARENA) && this.playerArenas.containsKey(player.getUniqueId())) {
            return false;
        }

        if (context.getKey().equals(ARENA_KEY)) {
            if (!this.playerArenas.containsKey(player.getUniqueId())) {
                return false;
            }

            if (!this.playerArenas.get(player.getUniqueId()).equals(context.getValue())) {
                return false;
            }
        }

        return true;
    }
}

crwdns130445:0crwdne130445:0

permissionService.registerContextCalculator(contextCalculator);