org.spongepowered.api.service.pagination.PaginationService Java Examples
The following examples show how to use
org.spongepowered.api.service.pagination.PaginationService.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WarplistCommand.java From UltimateCore with MIT License | 6 votes |
@Override public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException { checkPermission(sender, WarpPermissions.UC_WARP_WARPLIST_BASE); //Send the player a paginated list of all warps List<Warp> warps = GlobalData.get(WarpKeys.WARPS).get(); List<Text> texts = new ArrayList<>(); //Add entry to texts for every warp for (Warp warp : warps) { if (!sender.hasPermission("uc.warp.warp." + warp.getName().toLowerCase())) { continue; } texts.add(Messages.getFormatted("warp.command.warplist.entry", "%warp%", warp.getName(), "%description%", warp.getDescription()).toBuilder().onHover(TextActions.showText(Messages.getFormatted("warp.command.warplist.hoverentry", "%warp%", warp.getName()))).onClick(TextActions.runCommand("/warp " + warp.getName())).build()); } //If empty send message if (texts.isEmpty()) { throw new ErrorMessageException(Messages.getFormatted(sender, "warp.command.warplist.empty")); } //Sort alphabetically Collections.sort(texts); //Send page PaginationService paginationService = Sponge.getServiceManager().provide(PaginationService.class).get(); PaginationList paginationList = paginationService.builder().contents(texts).title(Messages.getFormatted("warp.command.warplist.header").toBuilder().color(TextColors.DARK_GREEN).build()).build(); paginationList.sendTo(sender); return CommandResult.success(); }
Example #2
Source File: JaillistCommand.java From UltimateCore with MIT License | 6 votes |
@Override public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException { checkPermission(sender, JailPermissions.UC_JAIL_JAILLIST_BASE); List<Jail> jails = GlobalData.get(JailKeys.JAILS).get(); List<Text> texts = new ArrayList<>(); //Add entry to texts for every jail for (Jail jail : jails) { texts.add(Messages.getFormatted("jail.command.jaillist.entry", "%jail%", jail.getName(), "%description%", jail.getDescription()).toBuilder().onHover(TextActions.showText(Messages.getFormatted("jail.command.jaillist.hoverentry", "%jail%", jail.getName()))).onClick(TextActions.runCommand("/jailtp " + jail.getName())).build()); } //If empty send message if (texts.isEmpty()) { throw new ErrorMessageException(Messages.getFormatted(sender, "jail.command.jaillist.empty")); } //Sort alphabetically Collections.sort(texts); //Send page PaginationService paginationService = Sponge.getServiceManager().provide(PaginationService.class).get(); PaginationList paginationList = paginationService.builder().contents(texts).title(Messages.getFormatted("jail.command.jaillist.header").toBuilder().color(TextColors.DARK_GREEN).build()).build(); paginationList.sendTo(sender); return CommandResult.success(); }
Example #3
Source File: RuleExecutor.java From EssentialCmds with MIT License | 6 votes |
@Override public void executeAsync(CommandSource src, CommandContext ctx) { ArrayList<String> rules = Utils.getRules(); List<Text> ruleText = Lists.newArrayList(); if (rules.isEmpty()) { src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "The rules for this server are not defined.")); return; } for (String rule : rules) { ruleText.add(Text.of(TextColors.GRAY, (rules.indexOf(rule) + 1) + ". ", TextColors.GOLD, rule)); } PaginationService paginationService = Sponge.getServiceManager().provide(PaginationService.class).get(); PaginationList.Builder paginationBuilder = paginationService.builder().contents(ruleText).title(Text.of(TextColors.GOLD, "Rules")).padding(Text.of("-")); paginationBuilder.sendTo(src); }
Example #4
Source File: WorldsBase.java From EssentialCmds with MIT License | 6 votes |
@Override public void executeAsync(CommandSource src, CommandContext ctx) { ArrayList<String> worlds = EssentialCmds.getEssentialCmds().getGame().getServer().getWorlds().stream().filter(world -> world.getProperties().isEnabled()).map(World::getName).collect(Collectors.toCollection(ArrayList::new)); PaginationService paginationService = Sponge.getServiceManager().provide(PaginationService.class).get(); ArrayList<Text> worldText = Lists.newArrayList(); for (String name : worlds) { Text item = Text.builder(name) .onClick(TextActions.runCommand("/tpworld " + name)) .onHover(TextActions.showText(Text.of(TextColors.WHITE, "Teleport to world ", TextColors.GOLD, name))) .color(TextColors.DARK_AQUA) .style(TextStyles.UNDERLINE) .build(); worldText.add(item); } PaginationList.Builder paginationBuilder = paginationService.builder().contents(worldText).title(Text.of(TextColors.GREEN, "Showing Worlds")).padding(Text.of("-")); paginationBuilder.sendTo(src); }
Example #5
Source File: ListCommand.java From EagleFactions with MIT License | 5 votes |
@Override public CommandResult execute(final CommandSource source, final CommandContext context) throws CommandException { CompletableFuture.runAsync(() ->{ Set<Faction> factionsList = new HashSet<>(super.getPlugin().getFactionLogic().getFactions().values()); List<Text> helpList = new ArrayList<>(); Text tagPrefix = getPlugin().getConfiguration().getChatConfig().getFactionStartPrefix(); Text tagSuffix = getPlugin().getConfiguration().getChatConfig().getFactionEndPrefix(); for(final Faction faction : factionsList) { Text tag = Text.builder().append(tagPrefix).append(faction.getTag()).append(tagSuffix, Text.of(" ")).build(); Text factionHelp = Text.builder() .append(Text.builder() .append(Text.of(TextColors.AQUA, "- ")).append(tag).append(Text.of(faction.getName(), " (", getPlugin().getPowerManager().getFactionPower(faction), "/", getPlugin().getPowerManager().getFactionMaxPower(faction), ")")) .build()) .onClick(TextActions.runCommand("/f info " + faction.getName())) .onHover(TextActions.showText(Text.of(TextStyles.ITALIC, TextColors.BLUE, "Click", TextColors.RESET, " for more info..."))) .build(); helpList.add(factionHelp); } PaginationService paginationService = Sponge.getServiceManager().provide(PaginationService.class).get(); PaginationList.Builder paginationBuilder = paginationService.builder().title(Text.of(TextColors.GREEN, Messages.FACTIONS_LIST)).padding(Text.of("-")).contents(helpList); paginationBuilder.sendTo(source); }); return CommandResult.success(); }
Example #6
Source File: HelpSubCommand.java From UltimateCore with MIT License | 5 votes |
@Override public CommandResult execute(CommandSource src, CommandContext args) throws CommandException { List<Text> texts = new ArrayList<>(); //Add entries to texts texts.add(Messages.getFormatted(src, "core.help.module", "%module%", this.cmd.getModule().getIdentifier())); texts.add(Text.of()); texts.add(Messages.getFormatted(src, "core.help.description", "%description%", this.cmd.getLongDescription(src))); texts.add(Text.of()); texts.add(Messages.getFormatted(src, "core.help.usage", "%usages%", getUsages(src))); //Send page PaginationService paginationService = Sponge.getServiceManager().provide(PaginationService.class).get(); PaginationList paginationList = paginationService.builder().contents(texts).title(Messages.getFormatted(src, "core.help.header", "%command%", this.cmd.getFullIdentifier()).toBuilder().color(TextColors.DARK_GREEN).build()).build(); paginationList.sendTo(src); return CommandResult.success(); }
Example #7
Source File: KitlistCommand.java From UltimateCore with MIT License | 5 votes |
@Override public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException { //Permissions checkPermission(sender, KitPermissions.UC_KIT_KITLIST_BASE); //Get all kits List<Kit> kits = GlobalData.get(KitKeys.KITS).get(); List<Text> texts = new ArrayList<>(); //Add entry to texts for every kit for (Kit kit : kits) { if (!sender.hasPermission("uc.kit.kit." + kit.getId().toLowerCase())) { continue; } texts.add(Messages.getFormatted("kit.command.kitlist.entry", "%kit%", kit.getId(), "%description%", kit.getDescription()).toBuilder().onHover(TextActions.showText(Messages.getFormatted("kit.command.kitlist.hoverentry", "%kit%", kit))).onClick(TextActions.runCommand("/kit " + kit)).build()); } //If empty send message if (texts.isEmpty()) { Messages.send(sender, "kit.command.kitlist.empty"); return CommandResult.empty(); } //Sort alphabetically Collections.sort(texts); PaginationService paginationService = Sponge.getServiceManager().provide(PaginationService.class).get(); PaginationList paginationList = paginationService.builder().contents(texts).title(Messages.getFormatted("kit.command.kitlist.header").toBuilder().format(Messages.getFormatted("kit.command.kitlist.char").getFormat()).build()).padding(Messages.getFormatted("kit.command.kitlist.char")).build(); paginationList.sendTo(sender); return CommandResult.success(); }
Example #8
Source File: HomelistCommand.java From UltimateCore with MIT License | 5 votes |
@Override public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException { checkIfPlayer(sender); checkPermission(sender, HomePermissions.UC_HOME_HOME_BASE); Player p = (Player) sender; UltimateUser user = UltimateCore.get().getUserService().getUser(p); List<Home> homes = user.get(HomeKeys.HOMES).orElse(new ArrayList<>()); if (homes.isEmpty()) { throw new ErrorMessageException(Messages.getFormatted(sender, "home.command.homelist.empty")); } List<Text> entries = new ArrayList<>(); for (Home home : homes) { entries.add(Messages.getFormatted("home.command.homelist.entry", "%home%", home.getName()).toBuilder().onHover(TextActions.showText(Messages.getFormatted("home.command.homelist.hoverentry", "%home%", home.getName()))).onClick(TextActions.runCommand("/home " + home.getName())).build()); } Collections.sort(entries); Text footer; if (!p.hasPermission(HomePermissions.UC_HOME_SETHOME_UNLIMITED.get())) { String shomecount = HomePermissions.UC_HOME_HOMECOUNT.getFor(sender); if (!ArgumentUtil.isInteger(shomecount)) { throw new ErrorMessageException(Messages.getFormatted(sender, "home.command.sethome.invalidhomecount", "%homecount%", shomecount)); } Integer homecount = Integer.parseInt(shomecount); footer = Messages.getFormatted("home.command.homelist.footer", "%current%", homes.size(), "%max%", homecount); } else { footer = Messages.getFormatted("home.command.homelist.footer.unlimited"); } PaginationService paginationService = Sponge.getServiceManager().provide(PaginationService.class).get(); PaginationList paginationList = paginationService.builder().contents(entries).title(Messages.getFormatted("home.command.homelist.header").toBuilder().format(Messages.getFormatted("home.command.homelist.char").getFormat()).build()).footer(footer).padding(Messages.getFormatted("home.command.homelist.char")).build(); paginationList.sendTo(sender); return CommandResult.success(); }
Example #9
Source File: ListWorldCommand.java From UltimateCore with MIT License | 5 votes |
@Override public CommandResult execute(CommandSource src, CommandContext args) throws CommandException { List<Text> texts = new ArrayList<>(); //Add entry to texts for every warp for (World world : Sponge.getServer().getWorlds()) { texts.add(Messages.getFormatted(src, "world.command.world.info.list.entry", "%world%", world.getName()).toBuilder().onClick(TextActions.runCommand("/world info " + world.getName())).build()); } //Sort alphabetically Collections.sort(texts); //Send page PaginationService paginationService = Sponge.getServiceManager().provide(PaginationService.class).get(); PaginationList paginationList = paginationService.builder().contents(texts).title(Messages.getFormatted("world.command.world.info.list.header").toBuilder().color(TextColors.DARK_GREEN).build()).build(); paginationList.sendTo(src); return CommandResult.success(); }
Example #10
Source File: MailListExecutor.java From EssentialCmds with MIT License | 5 votes |
@Override public void executeAsync(CommandSource src, CommandContext ctx) { if (src instanceof Player) { Player player = (Player) src; List<Mail> mail = Utils.getMail(player); if (mail.isEmpty()) { player.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You have no new mail!")); return; } PaginationService paginationService = Sponge.getServiceManager().provide(PaginationService.class).get(); List<Text> mailText = Lists.newArrayList(); for (Mail newM : mail) { String name = "New mail from " + newM.getSenderName(); Text item = Text.builder(name).onClick(TextActions.runCommand("/readmail " + (mail.indexOf(newM)))).onHover(TextActions.showText(Text.of(TextColors.WHITE, "Read mail from ", TextColors.GOLD, newM.getSenderName()))).color(TextColors.DARK_AQUA).style(TextStyles.UNDERLINE).build(); mailText.add(item); } PaginationList.Builder paginationBuilder = paginationService.builder().contents(mailText).title(Text.of(TextColors.GREEN, "Showing Mail")).padding(Text.of("-")); paginationBuilder.sendTo(src); } else { src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Must be an in-game player to use /mailist!")); } }
Example #11
Source File: BlacklistBase.java From EssentialCmds with MIT License | 5 votes |
@Override public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException { List<String> blacklistItems = Utils.getBlacklistItems(); if (blacklistItems.size() == 0) { src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "There are no blacklisted items!")); return CommandResult.success(); } PaginationService paginationService = Sponge.getServiceManager().provide(PaginationService.class).get(); List<Text> blacklistText = Lists.newArrayList(); for (String name : blacklistItems) { Text item = Text.builder(name) .color(TextColors.DARK_AQUA) .style(TextStyles.UNDERLINE) .build(); blacklistText.add(item); } PaginationList.Builder paginationBuilder = paginationService.builder().contents(blacklistText).title(Text.of(TextColors.GREEN, "Showing Blacklist")).padding(Text.of("-")); paginationBuilder.sendTo(src); return CommandResult.success(); }
Example #12
Source File: ListHomeExecutor.java From EssentialCmds with MIT License | 5 votes |
@Override public void executeAsync(CommandSource src, CommandContext ctx) { if (src instanceof Player) { Player player = (Player) src; Set<Object> homes = Utils.getHomes(player.getUniqueId()); if (homes.size() == 0) { player.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You must first set a home to list your homes!")); return; } PaginationService paginationService = Sponge.getServiceManager().provide(PaginationService.class).get(); List<Text> homeText = Lists.newArrayList(); for (Object home : homes) { String name = String.valueOf(home); Text item = Text.builder(name) .onClick(TextActions.runCommand("/home " + name)) .onHover(TextActions.showText(Text.of(TextColors.WHITE, "Teleport to home ", TextColors.GOLD, name))) .color(TextColors.DARK_AQUA) .style(TextStyles.UNDERLINE) .build(); homeText.add(item); } PaginationList.Builder paginationBuilder = paginationService.builder().contents(homeText).title(Text.of(TextColors.GREEN, "Showing Homes")).padding(Text.of("-")); paginationBuilder.sendTo(src); } else { src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Must be an in-game player to use /homes!")); } }
Example #13
Source File: CommandClaimInfo.java From GriefPrevention with MIT License | 5 votes |
public static Consumer<CommandSource> createSettingsConsumer(CommandSource src, Claim claim, List<Text> textList, ClaimType type) { return settings -> { String name = type == ClaimType.TOWN ? "Town Settings" : "Admin Settings"; PaginationService paginationService = Sponge.getServiceManager().provide(PaginationService.class).get(); PaginationList.Builder paginationBuilder = paginationService.builder() .title(Text.of(TextColors.AQUA, name)).padding(Text.of(TextStyles.STRIKETHROUGH, "-")).contents(textList); paginationBuilder.sendTo(src); }; }
Example #14
Source File: CoordsCommand.java From EagleFactions with MIT License | 5 votes |
private CommandResult showCoordsList(final CommandSource commandSource, final List<Text> teamCoords) throws CommandException { final PaginationService paginationService = Sponge.getServiceManager().provide(PaginationService.class).get(); final PaginationList.Builder paginationBuilder = paginationService.builder().title(Text.of(TextColors.GREEN, Messages.TEAM_COORDS)).contents(teamCoords); paginationBuilder.sendTo(commandSource); return CommandResult.success(); }
Example #15
Source File: ChatUI.java From ChatUI with MIT License | 5 votes |
@Listener(order = Order.POST) public void onPostInit(GamePostInitializationEvent event) { Optional<ProviderRegistration<PaginationService>> optService = Sponge.getGame().getServiceManager().getRegistration(PaginationService.class); if (optService.isPresent()) { PaginationService service = optService.get().getProvider(); Sponge.getGame().getServiceManager().setProvider(this, PaginationService.class, new TabbedPaginationService(service)); } this.features.load(); }
Example #16
Source File: CommandHelper.java From GriefPrevention with MIT License | 5 votes |
public static Consumer<CommandSource> showChildrenList(List<Text> childrenTextList, CommandSource src, Consumer<CommandSource> returnCommand, GPClaim parent) { return consumer -> { Text claimListReturnCommand = Text.builder().append(Text.of( TextColors.WHITE, "\n[", TextColors.AQUA, "Return to claimslist", TextColors.WHITE, "]\n")) .onClick(TextActions.executeCallback(returnCommand)).build(); List<Text> textList = new ArrayList<>(); textList.add(claimListReturnCommand); textList.addAll(childrenTextList); PaginationService paginationService = Sponge.getServiceManager().provide(PaginationService.class).get(); PaginationList.Builder paginationBuilder = paginationService.builder() .title(Text.of(parent.getName().orElse(parent.getFriendlyNameType()), " Child Claims")).padding(Text.of(TextStyles.STRIKETHROUGH, "-")).contents(textList); paginationBuilder.sendTo(src); }; }
Example #17
Source File: CommandHelper.java From GriefPrevention with MIT License | 5 votes |
public static void showClaims(CommandSource src, Set<Claim> claims, int height, boolean visualizeClaims, boolean overlap) { final String worldName = src instanceof Player ? ((Player) src).getWorld().getName() : Sponge.getServer().getDefaultWorldName(); final boolean canListOthers = src.hasPermission(GPPermissions.LIST_OTHER_CLAIMS); List<Text> claimsTextList = generateClaimTextList(new ArrayList<Text>(), claims, worldName, null, src, createShowClaimsConsumer(src, claims, height, visualizeClaims), canListOthers, false, overlap); if (visualizeClaims && src instanceof Player) { Player player = (Player) src; final GPPlayerData playerData = GriefPreventionPlugin.instance.dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId()); if (claims.size() > 1) { if (height != 0) { height = playerData.lastValidInspectLocation != null ? playerData.lastValidInspectLocation.getBlockY() : player.getProperty(EyeLocationProperty.class).get().getValue().getFloorY(); } Visualization visualization = Visualization.fromClaims(claims, playerData.optionClaimCreateMode == 1 ? height : player.getProperty(EyeLocationProperty.class).get().getValue().getFloorY(), player.getLocation(), playerData, null); visualization.apply(player); } else { for (Claim claim : claims) { final GPClaim gpClaim = (GPClaim) claim; gpClaim.getVisualizer().createClaimBlockVisuals(height, player.getLocation(), playerData); gpClaim.getVisualizer().apply(player); } } } PaginationService paginationService = Sponge.getServiceManager().provide(PaginationService.class).get(); PaginationList.Builder paginationBuilder = paginationService.builder() .title(Text.of(TextColors.RED,"Claim list")).padding(Text.of(TextStyles.STRIKETHROUGH, "-")).contents(claimsTextList); paginationBuilder.sendTo(src); }
Example #18
Source File: CommandHelper.java From GriefPrevention with MIT License | 5 votes |
public static Consumer<CommandSource> createBankTransactionsConsumer(CommandSource src, GPClaim claim, boolean checkTown, boolean returnToClaimInfo) { return settings -> { final String name = "Bank Transactions"; List<String> bankTransactions = new ArrayList<>(claim.getData().getEconomyData().getBankTransactionLog()); Collections.reverse(bankTransactions); List<Text> textList = new ArrayList<>(); textList.add(Text.builder().append(Text.of( TextColors.WHITE, "\n[", TextColors.AQUA, "Return to bank info", TextColors.WHITE, "]\n")) .onClick(TextActions.executeCallback(consumer -> { displayClaimBankInfo(src, claim, checkTown, returnToClaimInfo); })).build()); Gson gson = new Gson(); for (String transaction : bankTransactions) { GPBankTransaction bankTransaction = gson.fromJson(transaction, GPBankTransaction.class); final Duration duration = Duration.between(bankTransaction.timestamp, Instant.now().truncatedTo(ChronoUnit.SECONDS)) ; final long s = duration.getSeconds(); final User user = GriefPreventionPlugin.getOrCreateUser(bankTransaction.source); final String timeLeft = String.format("%dh %02dm %02ds", s / 3600, (s % 3600) / 60, (s % 60)) + " ago"; textList.add(Text.of(getTransactionColor(bankTransaction.type), bankTransaction.type.name(), TextColors.BLUE, " | ", TextColors.WHITE, bankTransaction.amount, TextColors.BLUE, " | ", TextColors.GRAY, timeLeft, user == null ? "" : Text.of(TextColors.BLUE, " | ", TextColors.LIGHT_PURPLE, user.getName()))); } textList.add(Text.builder().append(Text.of( TextColors.WHITE, "\n[", TextColors.AQUA, "Return to bank info", TextColors.WHITE, "]\n")) .onClick(TextActions.executeCallback(CommandHelper.createCommandConsumer(src, "claimbank", ""))).build()); PaginationService paginationService = Sponge.getServiceManager().provide(PaginationService.class).get(); PaginationList.Builder paginationBuilder = paginationService.builder() .title(Text.of(TextColors.AQUA, name)).padding(Text.of(TextStyles.STRIKETHROUGH, "-")).contents(textList); paginationBuilder.sendTo(src); }; }
Example #19
Source File: ImplementationPagination.java From ChatUI with MIT License | 5 votes |
public static void modify(PaginationService service, CommandSource oldSource, CommandSource newSource) { if (Sponge.getPlatform().asMap().get("CommonName").equals("Sponge")) { if (service instanceof SpongePaginationService) { SpongePaginationAccessor.replaceActivePagination((SpongePaginationService) service, oldSource, newSource); } } }
Example #20
Source File: TabbedPaginationBuilder.java From ChatUI with MIT License | 5 votes |
public TabbedPaginationBuilder(PaginationService service) { this.builder = service.builder(); this.service = service; // This cannot be obtained without a Window object this.removedHeight = 2; this.builder.linesPerPage(PlayerSettings.DEFAULT_BUFFER_HEIGHT_LINES - this.removedHeight); }
Example #21
Source File: CommandClaimOptionPlayer.java From GriefPrevention with MIT License | 4 votes |
@Override public CommandResult execute(CommandSource src, CommandContext args) throws CommandException { Player player; try { player = GriefPreventionPlugin.checkPlayer(src); } catch (CommandException e) { src.sendMessage(e.getText()); return CommandResult.success(); } String option = args.<String>getOne("option").orElse(null); if (option != null && !option.startsWith("griefprevention.")) { option = "griefprevention." + option; } Double value = args.<Double>getOne("value").orElse(null); final User user = args.<User>getOne("user").orElse(null); final boolean isGlobalOption = GPOptions.GLOBAL_OPTIONS.contains(option); // Check if global option if (isGlobalOption && !player.hasPermission(GPPermissions.MANAGE_GLOBAL_OPTIONS)) { GriefPreventionPlugin.sendMessage(src, GriefPreventionPlugin.instance.messageData.permissionGlobalOption.toText()); return CommandResult.success(); } Set<Context> contexts = new HashSet<>(); if (!isGlobalOption) { final GPPlayerData playerData = GriefPreventionPlugin.instance.dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId()); final GPClaim claim = GriefPreventionPlugin.instance.dataStore.getClaimAtPlayer(playerData, player.getLocation()); if (claim.isSubdivision()) { GriefPreventionPlugin.sendMessage(src, GriefPreventionPlugin.instance.messageData.commandOptionInvalidClaim.toText()); return CommandResult.success(); } if (!playerData.canManageOption(player, claim, false)) { GriefPreventionPlugin.sendMessage(src, GriefPreventionPlugin.instance.messageData.permissionPlayerOption.toText()); return CommandResult.success(); } final Text message = GriefPreventionPlugin.instance.messageData.permissionClaimManage .apply(ImmutableMap.of( "type", claim.getType().name())).build(); if (claim.isWilderness() && !player.hasPermission(GPPermissions.MANAGE_WILDERNESS)) { GriefPreventionPlugin.sendMessage(src, message); return CommandResult.success(); } else if (claim.isAdminClaim() && !player.hasPermission(GPPermissions.COMMAND_ADMIN_CLAIMS)) { GriefPreventionPlugin.sendMessage(src, message); return CommandResult.success(); } if (option != null && value != null) { // Validate new value against admin set value Double tempValue = GPOptionHandler.getClaimOptionDouble(user, claim, option, playerData); if (tempValue != value) { final Text message2 = GriefPreventionPlugin.instance.messageData.commandOptionExceedsAdmin .apply(ImmutableMap.of( "original_value", value, "admin_value", tempValue)).build(); GriefPreventionPlugin.sendMessage(src, message2); return CommandResult.success(); } contexts.add(claim.getContext()); } } if (option == null || value == null) { // display current options for user List<Object[]> optionList = Lists.newArrayList(); Map<String, String> options = user.getSubjectData().getOptions(contexts); for (Map.Entry<String, String> optionEntry : options.entrySet()) { String optionValue = optionEntry.getValue(); Object[] optionText = new Object[] { TextColors.GREEN, optionEntry.getKey(), " ", TextColors.GOLD, optionValue }; optionList.add(optionText); } List<Text> finalTexts = CommandHelper.stripeText(optionList); PaginationService paginationService = Sponge.getServiceManager().provide(PaginationService.class).get(); PaginationList.Builder paginationBuilder = paginationService.builder() .title(Text.of(TextColors.AQUA, user.getName() + " Claim Options")).padding(Text.of(TextStyles.STRIKETHROUGH, "-")).contents(finalTexts); paginationBuilder.sendTo(src); return CommandResult.success(); } final String flagOption = option; final Double newOptionValue = value; user.getSubjectData().setOption(contexts, option, newOptionValue.toString()) .thenAccept(consumer -> { if (consumer.booleanValue()) { GriefPreventionPlugin.sendMessage(src, Text.of("Set option ", TextColors.AQUA, flagOption, TextColors.WHITE, " to ", TextColors.GREEN, newOptionValue, TextColors.WHITE, " on user ", TextColors.GOLD, user.getName(), TextColors.WHITE, ".")); } else { GriefPreventionPlugin.sendMessage(src, Text.of(TextColors.RED, "The permission plugin failed to set the option.")); } }); return CommandResult.success(); }
Example #22
Source File: InfoCommand.java From EagleFactions with MIT License | 4 votes |
private void showFactionInfo(final CommandSource source, final Faction faction) { final List<Text> factionInfo = new ArrayList<>(); String leaderName = ""; if(faction.getLeader() != null && !faction.getLeader().equals(new UUID(0,0))) { final Optional<FactionPlayer> optionalFactionPlayer = super.getPlugin().getPlayerManager().getFactionPlayer(faction.getLeader()); if (optionalFactionPlayer.isPresent()) leaderName = optionalFactionPlayer.get().getName(); } String recruitList = ""; if(!faction.getRecruits().isEmpty()) { recruitList = faction.getRecruits().stream() .map(recruit -> getPlugin().getPlayerManager().getFactionPlayer(recruit)) .filter(Optional::isPresent).map(Optional::get) .map(FactionPlayer::getName) .collect(Collectors.joining(", ")); } String membersList = ""; if(!faction.getMembers().isEmpty()) { membersList = faction.getMembers().stream() .map(member -> getPlugin().getPlayerManager().getFactionPlayer(member)) .filter(Optional::isPresent).map(Optional::get) .map(FactionPlayer::getName) .collect(Collectors.joining(", ")); } String officersList = ""; if(!faction.getOfficers().isEmpty()) { officersList = faction.getOfficers().stream() .map(officer -> getPlugin().getPlayerManager().getPlayer(officer)) .filter(Optional::isPresent).map(Optional::get) .map(Player::getName) .collect(Collectors.joining(", ")); } String trucesList = ""; if(!faction.getTruces().isEmpty()) { trucesList = String.join(", ", faction.getTruces()); } String alliancesList = ""; if(!faction.getAlliances().isEmpty()) { alliancesList = String.join(", ", faction.getAlliances()); } String enemiesList = ""; if(!faction.getEnemies().isEmpty()) { enemiesList = String.join(", ", faction.getEnemies()); } Text info = Text.builder() .append(Text.of(TextColors.AQUA, Messages.NAME + ": ", TextColors.GOLD, faction.getName() + "\n")) .append(Text.of(TextColors.AQUA, Messages.TAG + ": "), faction.getTag().toBuilder().color(TextColors.GOLD).build(), Text.of("\n")) .append(Text.of(TextColors.AQUA, Messages.LAST_ONLINE + ": "), lastOnline(faction), Text.of("\n")) .append(Text.of(TextColors.AQUA, Messages.DESCRIPTION + ": ", TextColors.GOLD, faction.getDescription() + "\n")) .append(Text.of(TextColors.AQUA, Messages.MOTD + ": ", TextColors.GOLD, faction.getMessageOfTheDay() + "\n")) .append(Text.of(TextColors.AQUA, Messages.PUBLIC + ": ", TextColors.GOLD, faction.isPublic() + "\n")) .append(Text.of(TextColors.AQUA, Messages.LEADER + ": ", TextColors.GOLD, leaderName + "\n")) .append(Text.of(TextColors.AQUA, Messages.OFFICERS + ": ", TextColors.GOLD, officersList + "\n")) .append(Text.of(TextColors.AQUA, Messages.TRUCES + ": ", TextColors.GOLD, trucesList + "\n")) .append(Text.of(TextColors.AQUA, Messages.ALLIANCES + ": ", TextColors.BLUE, alliancesList + "\n")) .append(Text.of(TextColors.AQUA, Messages.ENEMIES + ": ", TextColors.RED, enemiesList + "\n")) .append(Text.of(TextColors.AQUA, Messages.MEMBERS + ": ", TextColors.GREEN, membersList + "\n")) .append(Text.of(TextColors.AQUA, Messages.RECRUITS + ": ", TextColors.GREEN, recruitList + "\n")) .append(Text.of(TextColors.AQUA, Messages.POWER + ": ", TextColors.GOLD, super.getPlugin().getPowerManager().getFactionPower(faction) + "/" + super.getPlugin().getPowerManager().getFactionMaxPower(faction) + "\n")) .append(Text.of(TextColors.AQUA, Messages.CLAIMS + ": ", TextColors.GOLD, faction.getClaims().size() + "/" + super.getPlugin().getPowerManager().getFactionMaxClaims(faction))) .build(); factionInfo.add(info); PaginationService paginationService = Sponge.getServiceManager().provide(PaginationService.class).get(); PaginationList.Builder paginationBuilder = paginationService.builder().title(Text.of(TextColors.GREEN, Messages.FACTION_INFO)).contents(factionInfo); paginationBuilder.sendTo(source); }
Example #23
Source File: TopCommand.java From EagleFactions with MIT License | 4 votes |
@Override public CommandResult execute(CommandSource source, CommandContext context) throws CommandException { CompletableFuture.runAsync(() -> { final List<Faction> factionsList = new ArrayList<>(getPlugin().getFactionLogic().getFactions().values()); final List<Text> helpList = new ArrayList<>(); int index = 0; final Text tagPrefix = getPlugin().getConfiguration().getChatConfig().getFactionStartPrefix(); final Text tagSuffix = getPlugin().getConfiguration().getChatConfig().getFactionEndPrefix(); factionsList.sort((o1, o2) -> { final float firstFactionPower = super.getPlugin().getPowerManager().getFactionPower(o1); final float secondFactionPower = super.getPlugin().getPowerManager().getFactionPower(o2); return Float.compare(secondFactionPower, firstFactionPower); }); //This should show only top 10 factions on the server. for(final Faction faction : factionsList) { if(faction.isSafeZone() || faction.isWarZone()) continue; if(index == 11) break; index++; final Text tag = Text.builder().append(tagPrefix).append(faction.getTag()).append(tagSuffix, Text.of(" ")).build(); final Text factionHelp = Text.builder() .append(Text.builder() .append(Text.of(TextColors.AQUA, "- ")).append(tag).append(Text.of(faction.getName(), " (", getPlugin().getPowerManager().getFactionPower(faction), "/", getPlugin().getPowerManager().getFactionMaxPower(faction), ")")) .build()) .build(); helpList.add(factionHelp); } final PaginationService paginationService = Sponge.getServiceManager().provide(PaginationService.class).get(); final PaginationList.Builder paginationBuilder = paginationService.builder().title(Text.of(TextColors.GREEN, Messages.FACTIONS_LIST)).padding(Text.of("-")).contents(helpList); paginationBuilder.sendTo(source); }); return CommandResult.success(); }
Example #24
Source File: TabbedPaginationService.java From ChatUI with MIT License | 4 votes |
public TabbedPaginationService(PaginationService service) { this.service = service; }
Example #25
Source File: TabbedPaginationList.java From ChatUI with MIT License | 4 votes |
public TabbedPaginationList(PaginationList list, PaginationService service) { this.list = list; this.service = service; }
Example #26
Source File: ListWarpExecutor.java From EssentialCmds with MIT License | 4 votes |
@Override public void executeAsync(CommandSource src, CommandContext ctx) { if (src instanceof Player) { Player player = (Player) src; Set<Object> warps = Utils.getWarps(); if (warps.size() == 0) { player.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "No warps set!")); return; } if (warps.size() > 0) { PaginationService paginationService = Sponge.getServiceManager().provide(PaginationService.class).get(); List<Text> warpText = Lists.newArrayList(); for (Object name : warps) { if (player.hasPermission("essentialcmds.warp.use." + String.valueOf(name))) { Text item = Text.builder(String.valueOf(name)) .onClick(TextActions.runCommand("/warp " + String.valueOf(name))) .onHover(TextActions.showText(Text.of(TextColors.WHITE, "Warp to ", TextColors.GOLD, String.valueOf(name)))) .color(TextColors.DARK_AQUA) .style(TextStyles.UNDERLINE) .build(); warpText.add(item); } } PaginationList.Builder paginationBuilder = paginationService.builder().contents(warpText).title(Text.of(TextColors.GREEN, "Showing Warps")).padding(Text.of("-")); paginationBuilder.sendTo(src); } else { src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "No warps set!")); } } else if (src instanceof ConsoleSource) { src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Must be an in-game player to use /warps!")); } else if (src instanceof CommandBlockSource) { src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Must be an in-game player to use /warps!")); } }
Example #27
Source File: WorldsBase.java From EssentialCmds with MIT License | 4 votes |
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException { Optional<String> worldName = ctx.<String> getOne("world"); World world; if (worldName.isPresent()) { if (Sponge.getServer().getWorld(worldName.get()).isPresent()) { world = Sponge.getServer().getWorld(worldName.get()).get(); } else { src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "World not found!")); return CommandResult.empty(); } } else { if (src instanceof Player) { Player player = (Player) src; world = player.getWorld(); } else { src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You must be an in-game player to use /world difficulty!")); return CommandResult.empty(); } } PaginationService paginationService = Sponge.getServiceManager().provide(PaginationService.class).get(); ArrayList<Text> gameruleText = Lists.newArrayList(); for (Entry<String, String> gamerule : world.getGameRules().entrySet()) { Text item = Text.builder(gamerule.getKey()) .onHover(TextActions.showText(Text.of(TextColors.WHITE, "Value ", TextColors.GOLD, gamerule.getValue()))) .color(TextColors.DARK_AQUA) .style(TextStyles.UNDERLINE) .build(); gameruleText.add(item); } PaginationList.Builder paginationBuilder = paginationService.builder().contents(gameruleText).title(Text.of(TextColors.GREEN, "Showing Gamerules")).padding(Text.of("-")); paginationBuilder.sendTo(src); return CommandResult.success(); }
Example #28
Source File: CommandClaimInfo.java From GriefPrevention with MIT License | 4 votes |
private static void executeAdminSettings(CommandSource src, GPClaim claim) { PaginationService paginationService = Sponge.getServiceManager().provide(PaginationService.class).get(); PaginationList.Builder paginationBuilder = paginationService.builder() .title(Text.of(TextColors.AQUA, "Admin Settings")).padding(Text.of(TextStyles.STRIKETHROUGH, "-")).contents(generateAdminSettings(src, claim)); paginationBuilder.sendTo(src); }
Example #29
Source File: CommandHelper.java From GriefPrevention with MIT License | 4 votes |
public static void displayClaimBankInfo(CommandSource src, GPClaim claim, boolean checkTown, boolean returnToClaimInfo) { final EconomyService economyService = GriefPreventionPlugin.instance.economyService.orElse(null); if (economyService == null) { GriefPreventionPlugin.sendMessage(src, GriefPreventionPlugin.instance.messageData.economyNotInstalled.toText()); return; } if (checkTown && !claim.isInTown()) { GriefPreventionPlugin.sendMessage(src, GriefPreventionPlugin.instance.messageData.townNotIn.toText()); return; } if (!checkTown && (claim.isSubdivision() || claim.isAdminClaim())) { return; } final GPClaim town = claim.getTownClaim(); Account bankAccount = checkTown ? town.getEconomyAccount().orElse(null) : claim.getEconomyAccount().orElse(null); if (bankAccount == null) { GriefPreventionPlugin.sendMessage(src, GriefPreventionPlugin.instance.messageData.economyVirtualNotSupported.toText()); return; } final GPPlayerData playerData = GriefPreventionPlugin.instance.dataStore.getPlayerData(claim.getWorld(), claim.getOwnerUniqueId()); final double claimBalance = bankAccount.getBalance(economyService.getDefaultCurrency()).doubleValue(); double taxOwed = -1; final double playerTaxRate = GPOptionHandler.getClaimOptionDouble(playerData.getPlayerSubject(), claim, GPOptions.Type.TAX_RATE, playerData); if (checkTown) { if (!town.getOwnerUniqueId().equals(playerData.playerID)) { for (Claim playerClaim : playerData.getInternalClaims()) { GPClaim playerTown = (GPClaim) playerClaim.getTown().orElse(null); if (!playerClaim.isTown() && playerTown != null && playerTown.getUniqueId().equals(claim.getUniqueId())) { taxOwed += playerTown.getClaimBlocks() * playerTaxRate; } } } else { taxOwed = town.getClaimBlocks() * playerTaxRate; } } else { taxOwed = claim.getClaimBlocks() * playerTaxRate; } final GriefPreventionConfig<?> activeConfig = GriefPreventionPlugin.getActiveConfig(claim.getWorld().getProperties()); final ZonedDateTime withdrawDate = TaskUtils.getNextTargetZoneDate(activeConfig.getConfig().claim.taxApplyHour, 0, 0); Duration duration = Duration.between(Instant.now().truncatedTo(ChronoUnit.SECONDS), withdrawDate.toInstant()) ; final long s = duration.getSeconds(); final String timeLeft = String.format("%d:%02d:%02d", s / 3600, (s % 3600) / 60, (s % 60)); final Text message = GriefPreventionPlugin.instance.messageData.claimBankInfo .apply(ImmutableMap.of( "balance", claimBalance, "amount", taxOwed, "time_remaining", timeLeft, "tax_balance", claim.getData().getEconomyData().getTaxBalance())).build(); Text transactions = Text.builder() .append(Text.of(TextStyles.ITALIC, TextColors.AQUA, "Bank Transactions")) .onClick(TextActions.executeCallback(createBankTransactionsConsumer(src, claim, checkTown, returnToClaimInfo))) .onHover(TextActions.showText(Text.of("Click here to view bank transactions"))) .build(); List<Text> textList = new ArrayList<>(); if (returnToClaimInfo) { textList.add(Text.builder().append(Text.of( TextColors.WHITE, "\n[", TextColors.AQUA, "Return to claim info", TextColors.WHITE, "]\n")) .onClick(TextActions.executeCallback(CommandHelper.createCommandConsumer(src, "claiminfo", ""))).build()); } textList.add(message); textList.add(transactions); PaginationService paginationService = Sponge.getServiceManager().provide(PaginationService.class).get(); PaginationList.Builder paginationBuilder = paginationService.builder() .title(Text.of(TextColors.AQUA, "Bank Info")).padding(Text.of(TextStyles.STRIKETHROUGH, "-")).contents(textList); paginationBuilder.sendTo(src); }
Example #30
Source File: CommandClaimPermissionPlayer.java From GriefPrevention with MIT License | 4 votes |
@Override public CommandResult execute(CommandSource src, CommandContext args) throws CommandException { Player player; try { player = GriefPreventionPlugin.checkPlayer(src); } catch (CommandException e) { src.sendMessage(e.getText()); return CommandResult.success(); } final String permission = args.<String>getOne("permission").orElse(null); if (permission != null && !player.hasPermission(permission)) { GriefPreventionPlugin.sendMessage(src, GriefPreventionPlugin.instance.messageData.permissionAssignWithoutHaving.toText()); return CommandResult.success(); } final User user = args.<User>getOne("user").orElse(null); final String value = args.<String>getOne("value").orElse(null); final GPPlayerData playerData = GriefPreventionPlugin.instance.dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId()); final GPClaim claim = GriefPreventionPlugin.instance.dataStore.getClaimAtPlayer(playerData, player.getLocation()); final Text message = GriefPreventionPlugin.instance.messageData.permissionClaimManage .apply(ImmutableMap.of( "type", claim.getType().name())).build(); if (claim.isWilderness() && !playerData.canManageWilderness) { GriefPreventionPlugin.sendMessage(src, message); return CommandResult.success(); } else if (claim.isAdminClaim() && !playerData.canManageAdminClaims) { GriefPreventionPlugin.sendMessage(src, message); return CommandResult.success(); } Set<Context> contexts = new HashSet<>(); contexts.add(claim.getContext()); if (permission == null || value == null) { // display current permissions for user List<Object[]> permList = Lists.newArrayList(); Map<String, Boolean> permissions = user.getSubjectData().getPermissions(contexts); for (Map.Entry<String, Boolean> permissionEntry : permissions.entrySet()) { Boolean permValue = permissionEntry.getValue(); Object[] permText = new Object[] { TextColors.GREEN, permissionEntry.getKey(), " ", TextColors.GOLD, permValue.toString() }; permList.add(permText); } List<Text> finalTexts = CommandHelper.stripeText(permList); PaginationService paginationService = Sponge.getServiceManager().provide(PaginationService.class).get(); PaginationList.Builder paginationBuilder = paginationService.builder() .title(Text.of(TextColors.AQUA, user.getName() + " Permissions")).padding(Text.of(TextStyles.STRIKETHROUGH, "-")).contents(finalTexts); paginationBuilder.sendTo(src); return CommandResult.success(); } Tristate tristateValue = PlayerUtils.getTristateFromString(value); if (tristateValue == null) { GriefPreventionPlugin.sendMessage(src, Text.of(TextColors.RED, "Invalid value entered. '" + value + "' is not a valid value. Valid values are : true, false, undefined, 1, -1, or 0.")); return CommandResult.success(); } user.getSubjectData().setPermission(contexts, permission, tristateValue); GriefPreventionPlugin.sendMessage(src, Text.of("Set permission ", TextColors.AQUA, permission, TextColors.WHITE, " to ", TextColors.GREEN, tristateValue, TextColors.WHITE, " on user ", TextColors.GOLD, user.getName(), TextColors.WHITE, ".")); return CommandResult.success(); }