crwdns35127:0crwdne35127:0

crwdns35128:0crwdne35128:0

crwdns35129:0crwdne35129:0

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

crwdns35130:0crwdne35130:0

  • crwdns35131:0crwdne35131:0
  • crwdns35132:0crwdne35132:0
  • crwdns35133:0crwdne35133:0
  • crwdns35134:0crwdne35134:0
  • crwdns35135:0crwdne35135:0
  • crwdns35136:0crwdne35136:0

crwdns35137:0crwdne35137:0

crwdns35138:0crwdne35138:0

Note

crwdns35139:0crwdne35139:0

crwdns35140:0crwdne35140:0

crwdns35141:0crwdne35141:0

  • crwdns35142:0crwdne35142:0
    • crwdns35143:0crwdne35143:0
  • crwdns35144:0crwdne35144:0
    • crwdns35145:0crwdne35145:0
  • crwdns35146:0crwdne35146:0
    • crwdns35147:0crwdne35147:0
  • crwdns35148:0crwdne35148:0
    • crwdns35149:0crwdne35149:0
  • crwdns35150:0crwdne35150:0
    • crwdns35151:0crwdne35151:0
  • crwdns35152:0crwdne35152:0
    • crwdns35153:0crwdne35153:0

crwdns35154:0crwdne35154:0

crwdns35155:0:javadoc:crwdnd35155:0:javadoc:crwdne35155:0

crwdns35156:0crwdne35156:0

  • crwdns35157:0crwdne35157:0
  • crwdns35158:0crwdne35158:0
  • crwdns35159:0crwdne35159:0
  • crwdns35160:0crwdne35160:0

crwdns35161:0crwdne35161:0

crwdns35162:0crwdne35162: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();
}

crwdns35163:0crwdne35163:0

myPlugin.commands.teleport.execute

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

crwdns35164:0crwdne35164:0

myPlugin.commands.teleport.worlds.<World>

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

Tip

crwdns35165:0crwdne35165:0

crwdns35166:0crwdne35166:0

crwdns35167:0:javadoc:crwdnd35167:0:javadoc:crwdnd35167:0:javadoc:crwdnd35167:0:javadoc:crwdne35167:0

crwdns35168:0crwdne35168:0

crwdns35169:0crwdne35169: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()));
}

crwdns35137:0crwdne35137:0

crwdns35170:0crwdne35170:0

crwdns35171:0:javadoc:crwdne35171:0

Warning

crwdns35172:0crwdne35172:0

Note

crwdns35173:0crwdne35173:0

crwdns35174:0crwdne35174:0

Note

crwdns35175:0crwdne35175:0

  • crwdns35176:0crwdne35176:0
    • crwdns35177:0crwdne35177:0
    • crwdns35178:0crwdne35178:0
  • crwdns35179:0crwdne35179:0
    • crwdns35177:0crwdne35177:0
    • crwdns35178:0crwdne35178:0
  • crwdns35180:0crwdne35180:0
    • crwdns35178:0crwdne35178:0
    • crwdns35177:0crwdne35177:0
  • crwdns35181:0crwdne35181:0
    • crwdns35178:0crwdne35178:0
    • crwdns35177:0crwdne35177:0
  • crwdns35182:0crwdne35182:0

crwdns35183:0crwdne35183:0

crwdns35184:0crwdne35184:0

  • crwdns35185:0crwdne35185:0
    • crwdns35186:0crwdne35186:0
  • crwdns35187:0crwdne35187:0
    • crwdns35188:0crwdne35188:0
  • crwdns35189:0crwdne35189:0
    • crwdns35190:0crwdne35190:0
  • crwdns35191:0crwdne35191:0
    • crwdns35192:0crwdne35192:0
  • crwdns35193:0crwdne35193:0
    • crwdns35194:0crwdne35194:0

Note

crwdns35195:0crwdne35195:0

crwdns35196:0crwdne35196:0

crwdns35197:0crwdne35197:0

  • crwdns35198:0crwdne35198:0
  • crwdns35199:0crwdne35199:0

crwdns35200:0crwdne35200:0

  • crwdns35201:0crwdne35201:0
  • crwdns35202:0crwdne35202:0

crwdns35203:0crwdne35203:0

crwdns35204:0crwdne35204:0

crwdns35205:0crwdne35205:0

crwdns35206:0crwdne35206:0

crwdns35207:0:javadoc:crwdne35207:0

crwdns35208:0crwdne35208:0

crwdns35209:0crwdne35209:0

crwdns35210:0:javadoc:crwdne35210:0

crwdns35211:0crwdne35211:0

Note

crwdns35212:0crwdne35212:0

crwdns35168:0crwdne35168:0

crwdns35213:0crwdne35213: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;
    }
}

crwdns35214:0crwdne35214:0

permissionService.registerContextCalculator(contextCalculator);