use of com.sk89q.minecraft.util.commands.Command in project FastAsyncWorldEdit by IntellectualSites.
the class CommandsManagerRegistration method registerAll.
public boolean registerAll(List<Command> registered) {
List<CommandInfo> toRegister = new ArrayList<>();
for (Command command : registered) {
List<String> permissions = null;
Method cmdMethod = commands.getMethods().get(null).get(command.aliases()[0]);
Map<String, Method> childMethods = commands.getMethods().get(cmdMethod);
if (cmdMethod != null && cmdMethod.isAnnotationPresent(CommandPermissions.class)) {
permissions = Arrays.asList(cmdMethod.getAnnotation(CommandPermissions.class).value());
} else if (cmdMethod != null && childMethods != null && !childMethods.isEmpty()) {
permissions = new ArrayList<>();
for (Method m : childMethods.values()) {
if (m.isAnnotationPresent(CommandPermissions.class)) {
permissions.addAll(Arrays.asList(m.getAnnotation(CommandPermissions.class).value()));
}
}
}
toRegister.add(new CommandInfo(command.usage(), command.desc(), command.aliases(), commands, permissions == null ? null : permissions.toArray(new String[permissions.size()])));
}
return register(toRegister);
}
use of com.sk89q.minecraft.util.commands.Command in project WorldGuard by EngineHub.
the class MemberCommands method removeMember.
@Command(aliases = { "removemember", "remmember", "removemem", "remmem", "rm" }, usage = "<id> <owners...>", flags = "naw:", desc = "Remove an owner to a region", min = 1)
public void removeMember(CommandContext args, Actor sender) throws CommandException {
warnAboutSaveFailures(sender);
// Get the world
World world = checkWorld(args, sender, 'w');
String id = args.getString(0);
RegionManager manager = checkRegionManager(world);
ProtectedRegion region = checkExistingRegion(manager, id, true);
// Check permissions
if (!getPermissionModel(sender).mayRemoveMembers(region)) {
throw new CommandPermissionsException();
}
Callable<DefaultDomain> callable;
if (args.hasFlag('a')) {
callable = region::getMembers;
} else {
if (args.argsLength() < 2) {
throw new CommandException("List some names to remove, or use -a to remove all.");
}
// Resolve members asynchronously
DomainInputResolver resolver = new DomainInputResolver(WorldGuard.getInstance().getProfileService(), args.getParsedPaddedSlice(1, 0));
resolver.setLocatorPolicy(args.hasFlag('n') ? UserLocatorPolicy.NAME_ONLY : UserLocatorPolicy.UUID_AND_NAME);
callable = resolver;
}
final String description = String.format("Removing members from the region '%s' on '%s'", region.getId(), world.getName());
AsyncCommandBuilder.wrap(callable, sender).registerWithSupervisor(worldGuard.getSupervisor(), description).sendMessageAfterDelay("(Please wait... querying player names...)").onSuccess(String.format("Region '%s' updated with members removed.", region.getId()), region.getMembers()::removeAll).onFailure("Failed to remove members", worldGuard.getExceptionConverter()).buildAndExec(worldGuard.getExecutorService());
}
use of com.sk89q.minecraft.util.commands.Command in project WorldGuard by EngineHub.
the class MemberCommands method addMember.
@Command(aliases = { "addmember", "addmember", "addmem", "am" }, usage = "<id> <members...>", flags = "nw:", desc = "Add a member to a region", min = 2)
public void addMember(CommandContext args, Actor sender) throws CommandException {
warnAboutSaveFailures(sender);
// Get the world
World world = checkWorld(args, sender, 'w');
String id = args.getString(0);
RegionManager manager = checkRegionManager(world);
ProtectedRegion region = checkExistingRegion(manager, id, true);
// Check permissions
if (!getPermissionModel(sender).mayAddMembers(region)) {
throw new CommandPermissionsException();
}
// Resolve members asynchronously
DomainInputResolver resolver = new DomainInputResolver(WorldGuard.getInstance().getProfileService(), args.getParsedPaddedSlice(1, 0));
resolver.setLocatorPolicy(args.hasFlag('n') ? UserLocatorPolicy.NAME_ONLY : UserLocatorPolicy.UUID_ONLY);
final String description = String.format("Adding members to the region '%s' on '%s'", region.getId(), world.getName());
AsyncCommandBuilder.wrap(resolver, sender).registerWithSupervisor(worldGuard.getSupervisor(), description).onSuccess(String.format("Region '%s' updated with new members.", region.getId()), region.getMembers()::addAll).onFailure("Failed to add new members", worldGuard.getExceptionConverter()).buildAndExec(worldGuard.getExecutorService());
}
use of com.sk89q.minecraft.util.commands.Command in project WorldGuard by EngineHub.
the class MemberCommands method addOwner.
@Command(aliases = { "addowner", "addowner", "ao" }, usage = "<id> <owners...>", flags = "nw:", desc = "Add an owner to a region", min = 2)
public void addOwner(CommandContext args, Actor sender) throws CommandException {
warnAboutSaveFailures(sender);
// Get the world
World world = checkWorld(args, sender, 'w');
String id = args.getString(0);
RegionManager manager = checkRegionManager(world);
ProtectedRegion region = checkExistingRegion(manager, id, true);
// Check permissions
if (!getPermissionModel(sender).mayAddOwners(region)) {
throw new CommandPermissionsException();
}
// Resolve owners asynchronously
DomainInputResolver resolver = new DomainInputResolver(WorldGuard.getInstance().getProfileService(), args.getParsedPaddedSlice(1, 0));
resolver.setLocatorPolicy(args.hasFlag('n') ? UserLocatorPolicy.NAME_ONLY : UserLocatorPolicy.UUID_ONLY);
final String description = String.format("Adding owners to the region '%s' on '%s'", region.getId(), world.getName());
AsyncCommandBuilder.wrap(checkedAddOwners(sender, manager, region, world, resolver), sender).registerWithSupervisor(worldGuard.getSupervisor(), description).onSuccess(String.format("Region '%s' updated with new owners.", region.getId()), region.getOwners()::addAll).onFailure("Failed to add new owners", worldGuard.getExceptionConverter()).buildAndExec(worldGuard.getExecutorService());
}
use of com.sk89q.minecraft.util.commands.Command in project WorldGuard by EngineHub.
the class RegionCommands method list.
/**
* List regions.
*
* @param args the arguments
* @param sender the sender
* @throws CommandException any error
*/
@Command(aliases = { "list" }, usage = "[-w world] [-p owner [-n]] [-s] [-i filter] [page]", desc = "Get a list of regions", flags = "np:w:i:s", max = 1)
public void list(CommandContext args, Actor sender) throws CommandException {
warnAboutSaveFailures(sender);
// Get the world
World world = checkWorld(args, sender, 'w');
String ownedBy;
// Get page
int page = args.getInteger(0, 1);
if (page < 1) {
page = 1;
}
// -p flag to lookup a player's regions
if (args.hasFlag('p')) {
ownedBy = args.getFlag('p');
} else {
// List all regions
ownedBy = null;
}
// Check permissions
if (!getPermissionModel(sender).mayList(ownedBy)) {
// assume they only want their own
ownedBy = sender.getName();
if (!getPermissionModel(sender).mayList(ownedBy)) {
throw new CommandPermissionsException();
}
}
RegionManager manager = checkRegionManager(world);
RegionLister task = new RegionLister(manager, sender, world.getName());
task.setPage(page);
if (ownedBy != null) {
task.filterOwnedByName(ownedBy, args.hasFlag('n'));
}
if (args.hasFlag('s')) {
ProtectedRegion existing = checkRegionFromSelection(sender, "tmp");
task.filterByIntersecting(existing);
}
// -i string is in region id
if (args.hasFlag('i')) {
task.filterIdByMatch(args.getFlag('i'));
}
AsyncCommandBuilder.wrap(task, sender).registerWithSupervisor(WorldGuard.getInstance().getSupervisor(), "Getting region list").sendMessageAfterDelay("(Please wait... fetching region list...)").onFailure("Failed to fetch region list", WorldGuard.getInstance().getExceptionConverter()).buildAndExec(WorldGuard.getInstance().getExecutorService());
}
Aggregations