crwdns149525:0crwdne149525:0
crwdns149527:0crwdne149527:0
crwdns149529:0crwdne149529:0
<PluginID>.<MainGroup>.<Subgroup1>...
crwdns149531:0crwdne149531:0
crwdns149533:0crwdne149533:0
crwdns149535:0crwdne149535:0
crwdns149537:0crwdne149537:0
crwdns149539:0crwdne149539:0
crwdns149541:0crwdne149541:0
crwdns149543:0crwdne149543:0
crwdns149545:0crwdne149545:0
crwdns149547:0crwdne149547:0
Note
crwdns149549:0crwdne149549:0
crwdns149551:0crwdne149551:0
crwdns149553:0crwdne149553:0
- crwdns149555:0crwdne149555:0
crwdns149557:0crwdne149557:0
- crwdns149559:0crwdne149559:0
crwdns149561:0crwdne149561:0
- crwdns149563:0crwdne149563:0
crwdns149565:0crwdne149565:0
- crwdns149567:0crwdne149567:0
crwdns149569:0crwdne149569:0
- crwdns149571:0crwdne149571:0
crwdns149573:0crwdne149573:0
- crwdns149575:0crwdne149575:0
crwdns149577:0crwdne149577:0
crwdns149579:0crwdne149579:0
crwdns149581:0:javadoc:crwdnd149581:0:javadoc:crwdne149581:0
crwdns149583:0crwdne149583:0
crwdns149585:0crwdne149585:0
crwdns149587:0crwdne149587:0
crwdns149589:0crwdne149589:0
crwdns149591:0crwdne149591:0
crwdns149593:0crwdne149593:0
crwdns149595:0crwdne149595: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();
}
crwdns149597:0crwdne149597:0
myplugin.commands.teleport.execute
Description: Allows the user to execute the teleport command.
Role: user
Owner: MyPlugin v1.2.3
crwdns149599:0crwdne149599:0
myplugin.commands.teleport.worlds.<World>
Description: Allows the user to teleport to the world <World>.
Role: staff
Owner: MyPlugin v1.2.3
Tip
crwdns149601:0crwdne149601:0
crwdns149603:0crwdne149603:0
crwdns149605:0:javadoc:crwdnd149605:0:javadoc:crwdnd149605:0:javadoc:crwdnd149605:0:javadoc:crwdne149605:0
crwdns149607:0crwdne149607:0
crwdns149609:0crwdne149609: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()));
}
crwdns149545:0crwdne149545:0
crwdns149611:0crwdne149611:0
crwdns149613:0:javadoc:crwdne149613:0
Warning
crwdns149615:0crwdne149615:0
Note
crwdns149617:0crwdne149617:0
crwdns149619:0crwdne149619:0
Note
crwdns149621:0crwdne149621:0
- crwdns149623:0crwdne149623:0
crwdns149625:0crwdne149625:0
crwdns149627:0crwdne149627:0
- crwdns149629:0crwdne149629:0
crwdns149625:0crwdne149625:0
crwdns149627:0crwdne149627:0
- crwdns149631:0crwdne149631:0
crwdns149627:0crwdne149627:0
crwdns149625:0crwdne149625:0
- crwdns149633:0crwdne149633:0
crwdns149627:0crwdne149627:0
crwdns149625:0crwdne149625:0
crwdns149635:0crwdne149635:0
crwdns149637:0crwdne149637:0
crwdns149639:0crwdne149639:0
- crwdns149641:0crwdne149641:0
crwdns149643:0crwdne149643:0
- crwdns149645:0crwdne149645:0
crwdns149647:0crwdne149647:0
- crwdns149649:0crwdne149649:0
crwdns149651:0crwdne149651:0
- crwdns149653:0crwdne149653:0
crwdns149655:0crwdne149655:0
- crwdns149657:0crwdne149657:0
crwdns149659:0crwdne149659:0
Note
crwdns149661:0crwdne149661:0
crwdns149663:0crwdne149663:0
crwdns149665:0crwdne149665:0
crwdns149667:0crwdne149667:0
crwdns149669:0crwdne149669:0
crwdns149671:0crwdne149671:0
crwdns149673:0crwdne149673:0
crwdns149675:0crwdne149675:0
crwdns149677:0crwdne149677:0
crwdns149679:0crwdne149679:0
crwdns149681:0crwdne149681:0
crwdns149683:0crwdne149683:0
crwdns149685:0:javadoc:crwdne149685:0
crwdns149687:0crwdne149687:0
crwdns149689:0crwdne149689:0
crwdns149691:0:javadoc:crwdne149691:0
crwdns149693:0crwdne149693:0
Note
crwdns149695:0crwdne149695:0
crwdns149607:0crwdne149607:0
crwdns149697:0crwdne149697: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;
}
}
crwdns149699:0crwdne149699:0
permissionService.registerContextCalculator(contextCalculator);
crwdns149701:0crwdne149701:0
crwdns149703:0crwdne149703:0
crwdns149705:0crwdne149705:0
crwdns149607:0crwdne149607:0
public class AwesomeBlock extends Block {
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumFacing side, float hitX, float hitY, float hitZ) {
if (player.canCommandSenderUseCommand(4, "examplemod.awesomeblock.interact")) {
// Do cool stuff
return true;
}
return false;
}
}
crwdns149707:0crwdne149707:0
Note
crwdns149709:0crwdne149709:0