/** * Gets the currently loaded warps, paginates them into pages of size WARPS_PER_PAGE, and sends * the warp names in a message to the player * * @param source * @param args * @return * @throws CommandException */ @Override public CommandResult execute(CommandSource source, CommandContext args) throws CommandException { if (this.plugin.getWarpManager().getPayload().isEmpty()) { source.sendMessage(Constants.NO_WARPS_MSG); return CommandResult.success(); } List<Text> warpNames = new ArrayList<Text>(); for (Warp w : this.plugin.getWarpManager().getPayload()) { if (this.plugin.getUtil().hasPermission(source, w)) { warpNames.add(Texts.of(Util.warpText(w), TextColors.WHITE, " - ", Util.deleteWarpText(w))); } } PaginationService paginationService = this.plugin.getGame().getServiceManager().provide(PaginationService.class).get(); paginationService .builder() .contents(warpNames) .title(Texts.of(TextColors.BLUE, "Warps")) .paddingString("-") .sendTo(source); return CommandResult.success(); }
@Override public CommandResult executeCommand(final CommandSource src, CommandContext args) throws Exception { if (service == null) { service = Sponge.getServiceManager().provideUnchecked(NucleusWarpService.class); } PaginationService ps = Sponge.getServiceManager().provideUnchecked(PaginationService.class); // Get the warp list. Set<String> ws = service.getWarpNames(); if (ws.isEmpty()) { src.sendMessage(Util.getTextMessageWithFormat("command.warps.list.nowarps")); return CommandResult.empty(); } List<Text> lt = ws.stream() .filter(s -> canView(src, s.toLowerCase())) .map( s -> { if (service.getWarp(s).isPresent()) { return Text.builder(s) .color(TextColors.GREEN) .style(TextStyles.UNDERLINE) .onClick(TextActions.runCommand("/warp " + s)) .onHover( TextActions.showText( Util.getTextMessageWithFormat("command.warps.warpprompt", s))) .build(); } else { return Text.builder(s) .color(TextColors.RED) .onHover( TextActions.showText( Util.getTextMessageWithFormat("command.warps.unavailable"))) .build(); } }) .collect(Collectors.toList()); PaginationList.Builder pb = ps.builder() .title(Util.getTextMessageWithFormat("command.warps.list.header")) .padding(Text.of(TextColors.GREEN, "-")) .contents(lt); if (!(src instanceof Player)) { pb.linesPerPage(-1); } pb.sendTo(src); return CommandResult.success(); }