crwdns119501:0crwdne119501:0
crwdns119503:0:doc:crwdnd119503:0:doc:crwdne119503:0
crwdns119505:0crwdne119505:0
crwdns119507:0crwdne119507:0
<PluginID>.<MainGroup>.<Subgroup1>...
crwdns119509:0crwdne119509:0
crwdns119511:0crwdne119511:0
crwdns119513:0crwdne119513:0
crwdns119515:0crwdne119515:0
crwdns119517:0crwdne119517:0
crwdns119519:0crwdne119519:0
crwdns119521:0crwdne119521:0
crwdns119523:0crwdne119523:0
crwdns119525:0crwdne119525:0
Note
crwdns119527:0crwdne119527:0
crwdns119529:0crwdne119529:0
crwdns119531:0crwdne119531:0
- crwdns119533:0crwdne119533:0
crwdns119535:0crwdne119535:0
- crwdns119537:0crwdne119537:0
crwdns119539:0crwdne119539:0
- crwdns119541:0crwdne119541:0
crwdns119543:0crwdne119543:0
- crwdns119545:0crwdne119545:0
crwdns119547:0crwdne119547:0
- crwdns119549:0crwdne119549:0
crwdns119551:0crwdne119551:0
- crwdns119553:0crwdne119553:0
crwdns119555:0crwdne119555:0
crwdns119557:0crwdne119557:0
crwdns119559:0:javadoc:crwdnd119559:0:javadoc:crwdne119559:0
crwdns119561:0crwdne119561:0
crwdns119563:0crwdne119563:0
crwdns119565:0crwdne119565:0
crwdns119567:0crwdne119567:0
crwdns119569:0crwdne119569:0
crwdns119571:0crwdne119571:0
crwdns119573:0crwdne119573: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();
crwdns119575:0crwdne119575:0
myplugin.commands.teleport.execute
Description: Allows the user to execute the teleport command.
Role: user
Owner: MyPlugin v1.2.3
crwdns119577:0crwdne119577:0
myplugin.commands.teleport.worlds.<World>
Description: Allows the user to teleport to the world <World>.
Role: staff
Owner: MyPlugin v1.2.3
Tip
crwdns119579:0crwdne119579:0
crwdns119581:0crwdne119581:0
crwdns119583:0:javadoc:crwdnd119583:0:javadoc:crwdnd119583:0:javadoc:crwdnd119583:0:javadoc:crwdne119583:0
crwdns119585:0crwdne119585:0
crwdns119587:0crwdne119587: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()));
}
crwdns119523:0crwdne119523:0
crwdns119589:0crwdne119589:0
crwdns119591:0:javadoc:crwdne119591:0
Warning
crwdns119593:0crwdne119593:0
Note
crwdns119595:0crwdne119595:0
crwdns119597:0crwdne119597:0
Note
crwdns119599:0crwdne119599:0
- crwdns119601:0crwdne119601:0
crwdns119603:0crwdne119603:0
crwdns119605:0crwdne119605:0
- crwdns119607:0crwdne119607:0
crwdns119603:0crwdne119603:0
crwdns119605:0crwdne119605:0
- crwdns119609:0crwdne119609:0
crwdns119605:0crwdne119605:0
crwdns119603:0crwdne119603:0
- crwdns119611:0crwdne119611:0
crwdns119605:0crwdne119605:0
crwdns119603:0crwdne119603:0
crwdns119613:0crwdne119613:0
crwdns119615:0crwdne119615:0
crwdns119617:0crwdne119617:0
- crwdns119619:0crwdne119619:0
crwdns119621:0crwdne119621:0
- crwdns119623:0crwdne119623:0
crwdns119625:0crwdne119625:0
- crwdns119627:0crwdne119627:0
crwdns119629:0crwdne119629:0
- crwdns119631:0crwdne119631:0
crwdns119633:0crwdne119633:0
- crwdns119635:0crwdne119635:0
crwdns119637:0crwdne119637:0
Note
crwdns119639:0crwdne119639:0
crwdns119641:0crwdne119641:0
crwdns119643:0crwdne119643:0
crwdns119645:0crwdne119645:0
crwdns119647:0crwdne119647:0
crwdns119649:0crwdne119649:0
crwdns119651:0crwdne119651:0
crwdns119653:0crwdne119653:0
crwdns119655:0crwdne119655:0
crwdns119585:0crwdne119585:0
crwdns119657:0crwdne119657: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
crwdns119659:0crwdne119659:0
crwdns119661:0crwdne119661:0
crwdns119663:0crwdne119663:0
crwdns119665:0crwdne119665:0
crwdns119667:0:javadoc:crwdne119667:0
crwdns119669:0crwdne119669:0
crwdns119671:0crwdne119671:0
crwdns119673:0:javadoc:crwdne119673:0
crwdns119675:0crwdne119675:0
Note
crwdns119677:0crwdne119677:0
Warning
crwdns119679:0crwdne119679:0
crwdns119585:0crwdne119585:0
crwdns119681:0crwdne119681: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;
}
}
crwdns119683:0crwdne119683:0
permissionService.registerContextCalculator(contextCalculator);
crwdns119685:0crwdne119685:0
crwdns119687:0crwdne119687:0
crwdns119689:0crwdne119689:0
crwdns119585:0crwdne119585: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;
}
}
crwdns119691:0crwdne119691:0
Note
crwdns119693:0crwdne119693:0