crwdns139109:0crwdne139109:0
Warning
crwdns139111:0crwdne139111:0
crwdns139113:0:doc:crwdnd139113:0:doc:crwdne139113:0
crwdns139115:0crwdne139115:0
crwdns139117:0crwdne139117:0
<PluginID>.<MainGroup>.<Subgroup1>...
crwdns139119:0crwdne139119:0
crwdns139121:0crwdne139121:0
crwdns139123:0crwdne139123:0
crwdns139125:0crwdne139125:0
crwdns139127:0crwdne139127:0
crwdns139129:0crwdne139129:0
crwdns139131:0crwdne139131:0
crwdns139133:0crwdne139133:0
crwdns139135:0crwdne139135:0
Note
crwdns139137:0crwdne139137:0
crwdns139139:0crwdne139139:0
crwdns139141:0crwdne139141:0
- crwdns139143:0crwdne139143:0
crwdns139145:0crwdne139145:0
- crwdns139147:0crwdne139147:0
crwdns139149:0crwdne139149:0
- crwdns139151:0crwdne139151:0
crwdns139153:0crwdne139153:0
- crwdns139155:0crwdne139155:0
crwdns139157:0crwdne139157:0
- crwdns139159:0crwdne139159:0
crwdns139161:0crwdne139161:0
- crwdns139163:0crwdne139163:0
crwdns139165:0crwdne139165:0
crwdns139167:0crwdne139167:0
crwdns139169:0:javadoc:crwdnd139169:0:javadoc:crwdne139169:0
crwdns139171:0crwdne139171:0
crwdns139173:0crwdne139173:0
crwdns139175:0crwdne139175:0
crwdns139177:0crwdne139177:0
crwdns139179:0crwdne139179:0
crwdns139181:0crwdne139181:0
crwdns139183:0crwdne139183:0
import net.kyori.adventure.text.Component;
import org.spongepowered.api.service.permission.PermissionDescription;
import org.spongepowered.api.service.permission.PermissionDescription.Builder;
import org.spongepowered.api.service.permission.PermissionService;
PluginContainer plugin = ...;
Builder builder = permissionService.newDescriptionBuilder(plugin);
builder.id("myplugin.commands.teleport.execute")
.description(Component.text("Allows the user to execute the teleport command."))
.assign(PermissionDescription.ROLE_STAFF, true)
.register();
crwdns139185:0crwdne139185:0
myplugin.commands.teleport.execute
Description: Allows the user to execute the teleport command.
Role: user
Owner: MyPlugin v1.2.3
crwdns139187:0crwdne139187:0
myplugin.commands.teleport.worlds.<World>
Description: Allows the user to teleport to the world <World>.
Role: staff
Owner: MyPlugin v1.2.3
Tip
crwdns139189:0crwdne139189:0
crwdns139191:0crwdne139191:0
crwdns139193:0:javadoc:crwdnd139193:0:javadoc:crwdnd139193:0:javadoc:crwdnd139193:0:javadoc:crwdne139193:0
crwdns139195:0crwdne139195:0
crwdns139197:0crwdne139197: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()));
}
crwdns139133:0crwdne139133:0
crwdns139199:0crwdne139199:0
crwdns139201:0:javadoc:crwdne139201:0
Warning
crwdns139203:0crwdne139203:0
Note
crwdns139205:0crwdne139205:0
crwdns139207:0crwdne139207:0
Note
crwdns139209:0crwdne139209:0
- crwdns139211:0crwdne139211:0
crwdns139213:0crwdne139213:0
crwdns139215:0crwdne139215:0
- crwdns139217:0crwdne139217:0
crwdns139213:0crwdne139213:0
crwdns139215:0crwdne139215:0
- crwdns139219:0crwdne139219:0
crwdns139215:0crwdne139215:0
crwdns139213:0crwdne139213:0
- crwdns139221:0crwdne139221:0
crwdns139215:0crwdne139215:0
crwdns139213:0crwdne139213:0
crwdns139223:0crwdne139223:0
crwdns139225:0crwdne139225:0
crwdns139227:0crwdne139227:0
- crwdns139229:0crwdne139229:0
crwdns139231:0crwdne139231:0
- crwdns139233:0crwdne139233:0
crwdns139235:0crwdne139235:0
- crwdns139237:0crwdne139237:0
crwdns139239:0crwdne139239:0
- crwdns139241:0crwdne139241:0
crwdns139243:0crwdne139243:0
- crwdns139245:0crwdne139245:0
crwdns139247:0crwdne139247:0
Note
crwdns139249:0crwdne139249:0
crwdns139251:0crwdne139251:0
crwdns139253:0crwdne139253:0
crwdns139255:0crwdne139255:0
crwdns139257:0crwdne139257:0
crwdns139259:0crwdne139259:0
crwdns139261:0crwdne139261:0
crwdns139263:0crwdne139263:0
crwdns139265:0crwdne139265:0
crwdns139195:0crwdne139195:0
crwdns139267:0crwdne139267: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
crwdns139269:0crwdne139269:0
crwdns139271:0crwdne139271:0
crwdns139273:0crwdne139273:0
crwdns139275:0crwdne139275:0
crwdns139277:0:javadoc:crwdne139277:0
crwdns139279:0crwdne139279:0
crwdns139281:0crwdne139281:0
crwdns139283:0:javadoc:crwdne139283:0
crwdns139285:0crwdne139285:0
Note
crwdns139287:0crwdne139287:0
Warning
crwdns139289:0crwdne139289:0
crwdns139195:0crwdne139195:0
crwdns139291:0crwdne139291: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;
}
}
crwdns139293:0crwdne139293:0
permissionService.registerContextCalculator(contextCalculator);
crwdns139295:0crwdne139295:0
crwdns139297:0crwdne139297:0
crwdns139299:0crwdne139299:0
crwdns139195:0crwdne139195: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;
}
}
crwdns139301:0crwdne139301:0
Note
crwdns139303:0crwdne139303:0