use of org.spongepowered.api.command.args.CommandContext in project Skree by Skelril.
the class RegionAddMemberCommand method execute.
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
if (!(src instanceof Player)) {
src.sendMessage(Text.of("You must be a player to use this command (for now ;) )!"));
return CommandResult.empty();
}
Optional<RegionService> optService = Sponge.getServiceManager().provide(RegionService.class);
if (!optService.isPresent()) {
src.sendMessage(Text.of(TextColors.DARK_RED, "The region service is not currently running."));
return CommandResult.empty();
}
RegionService service = optService.get();
Player player = (Player) src;
Optional<Region> optRef = service.getSelectedRegion(player);
if (!optRef.isPresent()) {
player.sendMessage(Text.of(TextColors.RED, "You do not currently have a region selected."));
return CommandResult.empty();
}
Region ref = optRef.get();
if (!ref.getMembers().contains(player.getUniqueId())) {
player.sendMessage(Text.of(TextColors.RED, "You must be a member of the region to modify it!"));
return CommandResult.empty();
}
List<UUID> newMembers = args.<User>getAll("player").stream().map(Identifiable::getUniqueId).filter(a -> !ref.getMembers().contains(a)).collect(Collectors.toList());
ref.addMember(newMembers);
player.sendMessage(Text.of(TextColors.YELLOW, "Added ", newMembers.size(), " players to the region."));
return CommandResult.success();
}
use of org.spongepowered.api.command.args.CommandContext in project Skree by Skelril.
the class RegionListMarkersCommand method execute.
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
if (!(src instanceof Player)) {
src.sendMessage(Text.of("You must be a player to use this command (for now ;) )!"));
return CommandResult.empty();
}
Optional<RegionService> optService = Sponge.getServiceManager().provide(RegionService.class);
if (!optService.isPresent()) {
src.sendMessage(Text.of(TextColors.DARK_RED, "The region service is not currently running."));
return CommandResult.empty();
}
RegionService service = optService.get();
Player player = (Player) src;
Optional<Region> optRef = service.getSelectedRegion(player);
if (!optRef.isPresent()) {
player.sendMessage(Text.of(TextColors.RED, "You do not currently have a region selected."));
return CommandResult.empty();
}
Region ref = optRef.get();
PaginationService pagination = Sponge.getServiceManager().provideUnchecked(PaginationService.class);
List<RegionPoint> points = ref.getPoints();
List<Text> result = ref.getFullPoints().stream().map(a -> Text.of((points.contains(a) ? TextColors.GREEN : TextColors.RED), a.getFloorX(), ", ", a.getFloorY(), ", ", a.getFloorZ())).collect(Collectors.toList());
pagination.builder().contents(result).title(Text.of(TextColors.GOLD, "Region Markers")).padding(Text.of(" ")).sendTo(src);
return CommandResult.success();
}
use of org.spongepowered.api.command.args.CommandContext in project Skree by Skelril.
the class RegionListMembersCommand method execute.
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
if (!(src instanceof Player)) {
src.sendMessage(Text.of("You must be a player to use this command (for now ;) )!"));
return CommandResult.empty();
}
Optional<RegionService> optService = Sponge.getServiceManager().provide(RegionService.class);
if (!optService.isPresent()) {
src.sendMessage(Text.of(TextColors.DARK_RED, "The region service is not currently running."));
return CommandResult.empty();
}
RegionService service = optService.get();
Player player = (Player) src;
Optional<Region> optRef = service.getSelectedRegion(player);
if (!optRef.isPresent()) {
player.sendMessage(Text.of(TextColors.RED, "You do not currently have a region selected."));
return CommandResult.empty();
}
Region ref = optRef.get();
UserStorageService userService = Sponge.getServiceManager().provideUnchecked(UserStorageService.class);
PaginationService pagination = Sponge.getServiceManager().provideUnchecked(PaginationService.class);
List<Text> result = ref.getMembers().stream().map(userService::get).filter(Optional::isPresent).map(Optional::get).sorted((a, b) -> a.getName().compareToIgnoreCase(b.getName())).map(a -> Text.of((a.isOnline() ? TextColors.GREEN : TextColors.RED), a.getName())).collect(Collectors.toList());
pagination.builder().contents(result).title(Text.of(TextColors.GOLD, "Region Members")).padding(Text.of(" ")).sendTo(src);
return CommandResult.success();
}
use of org.spongepowered.api.command.args.CommandContext in project SpongeCommon by SpongePowered.
the class SpongeCommandFactory method sendContainerMeta.
public static void sendContainerMeta(CommandSource src, CommandContext args, String argumentName) {
for (PluginContainer container : args.<PluginContainer>getAll(argumentName)) {
Text.Builder builder = Text.builder().append(title(container.getName()));
container.getVersion().ifPresent(version -> builder.append(Text.of((" v" + version))));
appendPluginMeta(builder, "ID", container.getId());
appendPluginMeta(builder, "Description", container.getDescription());
appendPluginMeta(builder, "URL", container.getUrl().map(url -> {
ClickAction.OpenUrl action = null;
try {
// make the url clickable
action = TextActions.openUrl(new URL(url));
} catch (MalformedURLException e) {
// or not
}
return Text.builder(url).onClick(action);
}));
if (!container.getAuthors().isEmpty()) {
appendPluginMeta(builder, "Authors", String.join(", ", container.getAuthors()));
}
appendPluginMeta(builder, "Main class", container.getInstance().map(instance -> instance.getClass().getCanonicalName()));
src.sendMessage(builder.build());
}
}
use of org.spongepowered.api.command.args.CommandContext in project SpongeAPI by SpongePowered.
the class CommandSpec method process.
@Override
public CommandResult process(CommandSource source, String arguments) throws CommandException {
checkPermission(source);
final CommandArgs args = new CommandArgs(arguments, getInputTokenizer().tokenize(arguments, false));
final CommandContext context = new CommandContext();
this.populateContext(source, args, context);
return getExecutor().execute(source, context);
}
Aggregations