/** * Creates a new {@link Builder} to build a pagination list. * * @return The new builder */ static Builder builder() { return Sponge.getServiceManager().provideUnchecked(PaginationService.class).builder(); }
/** * Creates a new {@link Builder} to build a pagination list * * @return The new builder */ static Builder builder() { return Sponge.getServiceManager().provideUnchecked(PaginationService.class).builder(); }
@Override public CommandResult execute(CommandSource src, CommandContext args) throws CommandException { String namespace = args.<String>getOne("namespace").orElse(((Player) src).getUniqueId().toString()); if (!namespace.equals(((Player) src).getUniqueId().toString()) && !area.commandListOtherPermissions.hasPermission(src)) { src.sendMessage(Text.of(TextColors.RED, "You don't have permission to list areas of other namespaces!")); return CommandResult.empty(); } PaginationService paginationService = Sponge.getServiceManager().provide(PaginationService.class).get(); PaginationList.Builder builder = paginationService.builder(); String[] files = new File(new File(CraftBookPlugin.inst().getWorkingDirectory(), "areas"), namespace).list(); List<Text> contents = new ArrayList<>(); for (String file : files) if (file != null) contents.add(Text.of(file)); builder.contents(contents).title(Text.of("Areas")).sendTo(src); return CommandResult.success(); } }
@Override public void msgPaginated(Translatable title, @Nullable Translatable header, final Iterable<Text.Builder> text) { PaginationList.Builder build = pex.getGame().getServiceManager().provide(PaginationService.class).get().builder(); build.title(fmt().hl(fmt().header(fmt().tr(title))).build()); if (header != null) { build.header(fmt().tr(header).color(TextColors.GRAY).build()); } build.contents(Iterables.transform(text, input -> input.color(TextColors.DARK_AQUA).build())) .sendTo(commandSource); } }
private void sendPaginatedMessage(Node node, CommandSource source) { PaginationService paginationService = Sponge.getServiceManager().provide(PaginationService.class).get(); PaginationList.Builder builder = paginationService.builder(); List<Text> contents = node.getSubcategories().stream() .map(category -> Text.builder("> " + category.getName()).color(TextColors.GRAY).onClick(TextActions.executeCallback(commandSource -> { if (commandSource instanceof Player) { sendPaginatedMessage(node.getChild(category), source); } })).build()).collect(Collectors.toList()); for (Package p : node.getPackages()) { contents.add(Text.builder(p.getName()).color(TextColors.WHITE).append(Text.builder(" - ").color(TextColors.GRAY).build()) .append(Text.builder("$x".replace("$", plugin.getServerInformation().getAccount().getCurrency().getSymbol()) .replace("x", "" + p.getEffectivePrice())).color(TextColors.GREEN).build()) .onClick(TextActions.executeCallback(commandSource -> { if (commandSource instanceof Player) { plugin.getPlatform().executeAsync(new SendCheckoutLinkTask(plugin, p.getId(), (Player) commandSource)); } })).build()); } builder.title(Text.builder(plugin.getI18n().get("sponge_listing")).color(TextColors.AQUA).build()).contents(contents).padding(Text.of("-")).sendTo(source); }