crwdns19709:0crwdne19709:0

crwdns42254:0:doc:crwdnd42254:0:doc:crwdne42254:0

crwdns19710:0crwdne19710:0

crwdns19711:0crwdne19711:0

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

crwdns19712:0crwdne19712:0

  • crwdns19713:0crwdne19713:0

  • crwdns19714:0crwdne19714:0

  • crwdns19715:0crwdne19715:0

  • crwdns19716:0crwdne19716:0

  • crwdns19717:0crwdne19717:0

  • crwdns19718:0crwdne19718:0

crwdns19719:0crwdne19719:0

crwdns37073:0crwdne37073:0

Note

crwdns37074:0crwdne37074:0

crwdns19722:0crwdne19722:0

crwdns19723:0crwdne19723:0

  • crwdns37075:0crwdne37075:0
    • crwdns19725:0crwdne19725:0

  • crwdns37076:0crwdne37076:0
    • crwdns19727:0crwdne19727:0

  • crwdns37077:0crwdne37077:0
    • crwdns42609:0crwdne42609:0

  • crwdns37078:0crwdne37078:0
    • crwdns19731:0crwdne19731:0

  • crwdns37079:0crwdne37079:0
    • crwdns19733:0crwdne19733:0

  • crwdns37080:0crwdne37080:0
    • crwdns19735:0crwdne19735:0

crwdns19736:0crwdne19736:0

crwdns19737:0:javadoc:crwdnd19737:0:javadoc:crwdne19737:0

crwdns19738:0crwdne19738:0

  • crwdns19739:0crwdne19739:0

  • crwdns19740:0crwdne19740:0

  • crwdns19741:0crwdne19741:0

  • crwdns19742:0crwdne19742:0

crwdns19743:0crwdne19743:0

crwdns19744:0crwdne19744: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;

PluginContainer plugin = ...;
Builder builder = permissionService.newDescriptionBuilder(plugin);

builder.id("myplugin.commands.teleport.execute")
       .description(Text.of("Allows the user to execute the teleport command."))
       .assign(PermissionDescription.ROLE_STAFF, true)
       .register();

crwdns19745:0crwdne19745:0

myplugin.commands.teleport.execute

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

crwdns19746:0crwdne19746:0

myplugin.commands.teleport.worlds.<World>

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

Tip

crwdns37081:0crwdne37081:0

crwdns19748:0crwdne19748:0

crwdns19749:0:javadoc:crwdnd19749:0:javadoc:crwdnd19749:0:javadoc:crwdnd19749:0:javadoc:crwdne19749:0

crwdns19750:0crwdne19750:0

crwdns19751:0crwdne19751: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()));
}

crwdns19719:0crwdne19719:0

crwdns19752:0crwdne19752:0

crwdns19753:0:javadoc:crwdne19753:0

Warning

crwdns42610:0crwdne42610:0

Note

crwdns19755:0crwdne19755:0

crwdns19756:0crwdne19756:0

Note

crwdns19757:0crwdne19757:0

  • crwdns19758:0crwdne19758:0
    • crwdns19759:0crwdne19759:0

    • crwdns19760:0crwdne19760:0

  • crwdns19761:0crwdne19761:0
    • crwdns19759:0crwdne19759:0

    • crwdns19760:0crwdne19760:0

  • crwdns19762:0crwdne19762:0
    • crwdns19760:0crwdne19760:0

    • crwdns19759:0crwdne19759:0

  • crwdns19763:0crwdne19763:0
    • crwdns19760:0crwdne19760:0

    • crwdns19759:0crwdne19759:0

  • crwdns19764:0crwdne19764:0

crwdns19765:0crwdne19765:0

crwdns19766:0crwdne19766:0

  • crwdns19767:0crwdne19767:0
    • crwdns19768:0crwdne19768:0

  • crwdns19769:0crwdne19769:0
    • crwdns19770:0crwdne19770:0

  • crwdns19771:0crwdne19771:0
    • crwdns42611:0crwdne42611:0

  • crwdns19773:0crwdne19773:0
    • crwdns19774:0crwdne19774:0

  • crwdns19775:0crwdne19775:0
    • crwdns19776:0crwdne19776:0

Note

crwdns19777:0crwdne19777:0

crwdns19778:0crwdne19778:0

crwdns19779:0crwdne19779:0

  • crwdns19780:0crwdne19780:0

  • crwdns19781:0crwdne19781:0

crwdns19782:0crwdne19782:0

  • crwdns19783:0crwdne19783:0

  • crwdns19784:0crwdne19784:0

crwdns19785:0crwdne19785:0

crwdns19750:0crwdne19750:0

crwdns43828:0crwdne43828:0

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

public void setPermission(Player player, String permission) {
    if(!player.hasPermission(permission)
        player.getSubjectData().setPermission(SubjectData.GLOBAL_CONTEXT, permission, Tristate.TRUE);
}

Note

crwdns43830:0crwdne43830:0

crwdns19786:0crwdne19786:0

crwdns19787:0crwdne19787:0

crwdns19788:0crwdne19788:0

crwdns19789:0:javadoc:crwdne19789:0

crwdns19790:0crwdne19790:0

crwdns19791:0crwdne19791:0

crwdns19792:0:javadoc:crwdne19792:0

crwdns19793:0crwdne19793:0

Note

crwdns42282:0crwdne42282:0

Warning

crwdns42612:0crwdne42612:0

crwdns19750:0crwdne19750:0

crwdns19795:0crwdne19795: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.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;

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 ConcurrentHashMap<>();

    @Override
    public void accumulateContexts(Subject subject, Set<Context> accumulator) {
        CommandSource commandSource = subject.getCommandSource().orElse(null);

        if (commandSource instanceof Player) {
            UUID uuid = ((Player) commandSource).getUniqueId();

            String arena = this.playerArenas.get(uuid);
            if (arena != null) {
                accumulator.add(IN_ANY_ARENA);
                accumulator.add(new Context(ARENA_KEY, arena));
            } else {
                accumulator.add(NOT_ANY_ARENA);
            }
        }
    }

    @Override
    public boolean matches(Context context, Subject subject) {
        CommandSource commandSource = subject.getCommandSource().orElse(null);

        if (commandSource instanceof Player) {
            UUID uuid = ((Player) commandSource).getUniqueId();

            if (context.equals(IN_ANY_ARENA)) {
                return this.playerArenas.containsKey(uuid);
            } else if (context.equals(NOT_ANY_ARENA)) {
                return !this.playerArenas.containsKey(uuid);
            } else if (context.getKey().equals(ARENA_KEY)) {
                return context.getValue().equals(this.playerArenas.get(uuid));
            }
        }

        return false;
    }

}

crwdns19796:0crwdne19796:0

permissionService.registerContextCalculator(contextCalculator);

crwdns37094:0crwdne37094:0

crwdns37095:0crwdne37095:0

crwdns37096:0crwdne37096:0

crwdns19750:0crwdne19750:0

public class AwesomeBlock extends Block {
    @Override
    public boolean onBlockActivated(World world, BlockPos pos, IBlockState state,
            EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
        if (player.canUseCommand(4, "examplemod.awesomeblock.interact")) {
            // Do cool stuff
            return true;
        }
        return false;
    }
}

crwdns37097:0crwdne37097:0

Note

crwdns37098:0crwdne37098:0