use of org.spongepowered.api.command.args.CommandContext in project Nucleus by NucleusPowered.
the class KitEditCommand method executeCommand.
@Override
public CommandResult executeCommand(Player src, CommandContext args) throws Exception {
final Kit kitInfo = args.<Kit>getOne(KIT_PARAMETER).get();
if (KIT_HANDLER.isOpen(kitInfo.getName())) {
throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.kit.edit.current", kitInfo.getName()));
}
Inventory inventory = Util.getKitInventoryBuilder().property(InventoryTitle.PROPERTY_NAME, InventoryTitle.of(plugin.getMessageProvider().getTextMessageWithFormat("command.kit.edit.title", kitInfo.getName()))).build(plugin);
kitInfo.getStacks().stream().filter(x -> !x.getType().equals(ItemTypes.NONE)).forEach(x -> inventory.offer(x.createStack()));
Optional<Container> openedInventory = src.openInventory(inventory);
if (openedInventory.isPresent()) {
KIT_HANDLER.addKitInventoryToListener(Tuple.of(kitInfo, inventory), openedInventory.get());
return CommandResult.success();
}
throw ReturnMessageException.fromKey("command.kit.edit.cantopen", kitInfo.getName());
}
use of org.spongepowered.api.command.args.CommandContext in project Nucleus by NucleusPowered.
the class CheckJailedCommand method executeCommand.
@Override
protected CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
// Using the cache, tell us who is jailed.
MessageProvider provider = plugin.getMessageProvider();
Optional<NamedLocation> jail = args.getOne(jailNameKey);
List<UUID> usersInJail = jail.map(x -> plugin.getUserCacheService().getJailedIn(x.getName())).orElseGet(() -> plugin.getUserCacheService().getJailed());
String jailName = jail.map(NamedLocation::getName).orElseGet(() -> provider.getMessageWithFormat("standard.alljails"));
if (usersInJail.isEmpty()) {
src.sendMessage(provider.getTextMessageWithFormat("command.checkjailed.none", jailName));
return CommandResult.success();
}
// Get the users in this jail, or all jails
Util.getPaginationBuilder(src).title(provider.getTextMessageWithFormat("command.checkjailed.header", jailName)).contents(usersInJail.stream().map(x -> {
Text name = plugin.getNameUtil().getName(x).orElseGet(() -> Text.of("unknown: ", x.toString()));
return name.toBuilder().onHover(TextActions.showText(provider.getTextMessageWithFormat("command.checkjailed.hover"))).onClick(TextActions.runCommand("/nucleus:checkjail " + x.toString())).build();
}).collect(Collectors.toList())).sendTo(src);
return CommandResult.success();
}
use of org.spongepowered.api.command.args.CommandContext in project Nucleus by NucleusPowered.
the class KitEditCommandCommand method executeCommand.
@Override
protected CommandResult executeCommand(Player src, CommandContext args) throws Exception {
final Kit kitInfo = args.<Kit>getOne(KIT_PARAMETER).get();
List<String> commands = kitInfo.getCommands();
if (commands.size() > 9 * 6) {
throw ReturnMessageException.fromKey("command.kit.command.edit.toomany", kitInfo.getName());
}
// Create an inventory with signed books.
Random r = new Random();
List<ItemStack> books = commands.stream().map(x -> {
ItemStack stack = ItemStack.of(ItemTypes.WRITTEN_BOOK, 1);
Text command = Text.of(x);
stack.offer(Keys.DISPLAY_NAME, command);
stack.offer(Keys.BOOK_PAGES, Lists.newArrayList(command));
// So books don't stack.
stack.offer(Keys.BOOK_AUTHOR, Text.of(kitInfo.getName(), "-", r.nextInt()));
return stack;
}).collect(Collectors.toList());
// Create Inventory GUI.
final InventoryTitle title = InventoryTitle.of(Text.of("Kit Commands: ", kitInfo.getName()));
final Inventory inventory = Inventory.builder().of(InventoryArchetypes.DOUBLE_CHEST).property(InventoryTitle.PROPERTY_NAME, title).build(plugin);
books.forEach(inventory::offer);
src.openInventory(inventory).ifPresent(x -> KIT_HANDLER.addKitCommandInventoryToListener(Tuple.of(kitInfo, inventory), x));
return CommandResult.success();
}
use of org.spongepowered.api.command.args.CommandContext in project Nucleus by NucleusPowered.
the class ListPowertoolCommand method executeCommand.
@Override
public CommandResult executeCommand(Player src, CommandContext args) throws Exception {
PowertoolUserDataModule inu = Nucleus.getNucleus().getUserDataManager().getUnchecked(src).get(PowertoolUserDataModule.class);
boolean toggle = inu.isPowertoolToggled();
Map<String, List<String>> powertools = inu.getPowertools();
if (powertools.isEmpty()) {
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.powertool.list.none"));
return CommandResult.success();
}
// Generate powertools.
List<Text> mesl = powertools.entrySet().stream().sorted((a, b) -> a.getKey().compareToIgnoreCase(b.getKey())).map(k -> from(inu, src, k.getKey(), k.getValue())).collect(Collectors.toList());
// Paginate the tools.
Util.getPaginationBuilder(src).title(plugin.getMessageProvider().getTextMessageWithFormat("command.powertool.list.header", toggle ? "&aenabled" : "&cdisabled")).padding(Text.of(TextColors.YELLOW, "-")).contents(mesl).sendTo(src);
return CommandResult.success();
}
use of org.spongepowered.api.command.args.CommandContext in project Skree by Skelril.
the class MarketListCommand method execute.
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
Optional<MarketService> optService = Sponge.getServiceManager().provide(MarketService.class);
if (!optService.isPresent()) {
src.sendMessage(Text.of(TextColors.DARK_RED, "The market service is not currently running."));
return CommandResult.empty();
}
MarketService service = optService.get();
PaginationService pagination = Sponge.getServiceManager().provideUnchecked(PaginationService.class);
Optional<String> optFilter = args.getOne("name");
String filter = optFilter.isPresent() ? optFilter.get() : "";
if (!filter.matches(MarketService.VALID_ALIAS_REGEX)) {
src.sendMessage(Text.of(TextColors.RED, "Invalid filter supplied."));
return CommandResult.empty();
}
List<ItemDescriptor> prices = filter.isEmpty() ? service.getPrices() : service.getPrices(filter + "%");
if (prices.isEmpty()) {
src.sendMessage(Text.of(TextColors.YELLOW, "No items matched."));
return CommandResult.success();
}
List<Text> result = prices.stream().filter(a -> filter.isEmpty() || a.getName().startsWith(filter)).sorted(Comparator.comparing(ItemDescriptor::getCurrentValue)).map(a -> createLine(a, service)).collect(Collectors.toList());
pagination.builder().contents(result).title(Text.of(TextColors.GOLD, "Item List")).padding(Text.of(" ")).sendTo(src);
return CommandResult.success();
}
Aggregations