From c8f00fbb49d6e6ad08f32309f4708bfe5312990e Mon Sep 17 00:00:00 2001 From: LlmDl Date: Fri, 10 Nov 2023 10:56:23 -0600 Subject: [PATCH] Add /res plotlist Command New Permission Node: towny.command.resident.plotlist New Command: /res plotlist {#} New Command: /res plotlist [name] {#} Closes #7075 --- .../bukkit/towny/TownyMessaging.java | 45 +++++++++++++++++++ .../bukkit/towny/command/ResidentCommand.java | 39 ++++++++++++++++ .../towny/permissions/PermissionNodes.java | 1 + Towny/src/main/resources/lang/en-US.yml | 7 ++- Towny/src/main/resources/plugin.yml | 1 + 5 files changed, 92 insertions(+), 1 deletion(-) diff --git a/Towny/src/main/java/com/palmergames/bukkit/towny/TownyMessaging.java b/Towny/src/main/java/com/palmergames/bukkit/towny/TownyMessaging.java index c1ee713003..3043dbdcd4 100644 --- a/Towny/src/main/java/com/palmergames/bukkit/towny/TownyMessaging.java +++ b/Towny/src/main/java/com/palmergames/bukkit/towny/TownyMessaging.java @@ -742,6 +742,51 @@ public static void sendPlotGroupList(CommandSender sender, Town town, int page, audience.sendMessage(pageFooter); } + public static void sendPlotList(CommandSender sender, Resident resident, int page, int totalPages) { + Translator translator = Translator.locale(sender); + int plotCount = resident.getTownBlocks().size(); + int iMax = Math.min(page * 10, plotCount); + List townblocks = new ArrayList<>(resident.getTownBlocks()); + + TextComponent[] plotsFormatted = ((page * 10) > plotCount) + ? new TextComponent[plotCount % 10] + : new TextComponent[10]; + + String headerMsg = ChatColor.GOLD + "# " + + ChatColor.DARK_GRAY + "- " + + ChatColor.GREEN + "Coord " + + ChatColor.DARK_GRAY + " - " + + ChatColor.AQUA + "Town" + + ChatColor.DARK_GRAY + " - " + + ChatColor.GREEN + "Type" + + ChatColor.DARK_GRAY + " - " + + ChatColor.YELLOW + "Name"; + + for (int i = (page - 1) * 10; i < iMax; i++) { + TownBlock tb = townblocks.get(i); + String tbName = tb.getName().isEmpty() ? translator.of("msg_unnamed") : tb.getName(); + TextComponent coord = Component.text(tb.getWorldCoord().toString(), NamedTextColor.GREEN); + TextComponent town = Component.text(tb.getTownOrNull().getName(), NamedTextColor.AQUA); + TextComponent type = Component.text(tb.getTypeName(), NamedTextColor.GREEN); + TextComponent name = Component.text(tbName, NamedTextColor.YELLOW); + TextComponent dash = Component.text(" - ", NamedTextColor.DARK_GRAY); + TextComponent line = Component.text(Integer.toString(i + 1), NamedTextColor.GOLD); + line = line.append(dash).append(coord).append(dash).append(town).append(dash).append(type).append(dash).append(name); + + plotsFormatted[i % 10] = line; + } + + Audience audience = Towny.getAdventure().sender(sender); + sendMessage(sender, ChatTools.formatTitle(resident.getName() + " " + translator.of("townblock_plu"))); + sendMessage(sender, headerMsg); + for (TextComponent textComponent : plotsFormatted) + audience.sendMessage(textComponent); + + // Page navigation + Component pageFooter = getPageNavigationFooter("towny:resident plotlist" + resident.getName(), page, "", totalPages, translator); + audience.sendMessage(pageFooter); + } + /* * TRANSLATABLES FOLLOW */ diff --git a/Towny/src/main/java/com/palmergames/bukkit/towny/command/ResidentCommand.java b/Towny/src/main/java/com/palmergames/bukkit/towny/command/ResidentCommand.java index b6460ea046..88e191a5ee 100644 --- a/Towny/src/main/java/com/palmergames/bukkit/towny/command/ResidentCommand.java +++ b/Towny/src/main/java/com/palmergames/bukkit/towny/command/ResidentCommand.java @@ -30,6 +30,7 @@ import com.palmergames.bukkit.util.ChatTools; import com.palmergames.bukkit.util.Colors; import com.palmergames.bukkit.util.NameValidation; +import com.palmergames.util.MathUtil; import com.palmergames.util.StringMgmt; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; @@ -52,6 +53,7 @@ public class ResidentCommand extends BaseCommand implements CommandExecutor { "friend", "list", "jail", + "plotlist", "spawn", "toggle", "set", @@ -168,6 +170,12 @@ public List onTabComplete(CommandSender sender, Command command, String if (sender instanceof Player) { switch (args[0].toLowerCase(Locale.ROOT)) { + case "plotlist": + if (args.length == 2) + return getTownyStartingWith(args[1], "r"); + if (args.length == 3) + return Collections.singletonList("[page #]"); + break; case "tax": if (args.length == 2) return getTownyStartingWith(args[1], "r"); @@ -267,6 +275,7 @@ public void parseResidentCommand(final Player player, String[] split) throws Tow case "?", "help" -> HelpMenu.RESIDENT_HELP.send(player); case "list" -> listResidents(player); case "tax" -> parseResidentTax(player, StringMgmt.remFirstArg(split)); + case "plotlist" -> parseResidentPlotlist(player, StringMgmt.remFirstArg(split)); case "jail" -> parseResidentJail(player, StringMgmt.remFirstArg(split)); case "set" -> residentSet(player, StringMgmt.remFirstArg(split)); case "toggle" -> residentToggle(player, StringMgmt.remFirstArg(split)); @@ -308,6 +317,36 @@ private void parseResidentTax(Player player, String[] split) throws TownyExcepti TownyMessaging.sendMessage(player, TownyFormatter.getTaxStatus(res, Translator.locale(player))); } + private void parseResidentPlotlist(Player player, String[] split) throws TownyException { + + checkPermOrThrow(player, PermissionNodes.TOWNY_COMMAND_RESIDENT_PLOTLIST.getNode()); + + int pageLoc = 0; + Resident res = getResidentOrThrow(player); + if (split.length > 0) { + if (TownyUniverse.getInstance().hasResident(split[0])) { + res = getResidentOrThrow(split[0]); + pageLoc = 1; + } + } + + if (res.getTownBlocks().isEmpty()) + throw new TownyException(Translatable.of("msg_err_resident_doesnt_own_any_land")); + + int page = 1; + int total = (int) Math.ceil(((double) res.getTownBlocks().size()) / ((double) 10)); + if (split.length > pageLoc) { + page = MathUtil.getPositiveIntOrThrow(split[pageLoc]); + if (page == 0) + throw new TownyException(Translatable.of("msg_error_must_be_int")); + // Page will continue to be one. + } + if (page > total) + throw new TownyException(Translatable.of("LIST_ERR_NOT_ENOUGH_PAGES", total)); + + TownyMessaging.sendPlotList(player, res, page, total); + } + private void parseResidentJail(Player player, String[] split) throws TownyException { checkPermOrThrow(player, PermissionNodes.TOWNY_COMMAND_RESIDENT_JAIL.getNode()); diff --git a/Towny/src/main/java/com/palmergames/bukkit/towny/permissions/PermissionNodes.java b/Towny/src/main/java/com/palmergames/bukkit/towny/permissions/PermissionNodes.java index e2e91bb2e2..f81f85110e 100644 --- a/Towny/src/main/java/com/palmergames/bukkit/towny/permissions/PermissionNodes.java +++ b/Towny/src/main/java/com/palmergames/bukkit/towny/permissions/PermissionNodes.java @@ -246,6 +246,7 @@ public enum PermissionNodes { TOWNY_COMMAND_RESIDENT_OTHERRESIDENT("towny.command.resident.otherresident"), TOWNY_COMMAND_RESIDENT_LIST("towny.command.resident.list"), TOWNY_COMMAND_RESIDENT_TAX("towny.command.resident.tax"), + TOWNY_COMMAND_RESIDENT_PLOTLIST("towny.command.resident.plotlist"), TOWNY_COMMAND_RESIDENT_JAIL("towny.command.resident.jail"), TOWNY_COMMAND_RESIDENT_SET("towny.command.resident.set.*"), TOWNY_COMMAND_RESIDENT_SET_PERM("towny.command.resident.set.perm"), diff --git a/Towny/src/main/resources/lang/en-US.yml b/Towny/src/main/resources/lang/en-US.yml index 09603cf207..67af762099 100644 --- a/Towny/src/main/resources/lang/en-US.yml +++ b/Towny/src/main/resources/lang/en-US.yml @@ -2365,4 +2365,9 @@ msg_err_floodfill_out_of_bounds: "Claim shape must be fully closed off in order msg_err_floodfill_cannot_contain_towns: "Flood fill selection must not contain other towns." # Message shown when a resident is an NPC and is not allowed to do something. -msg_err_resident_is_npc: "You cannot do this to an NPC resident." \ No newline at end of file +msg_err_resident_is_npc: "You cannot do this to an NPC resident." + +# Message shown when a resident doesn't own any land and the /res plotlist command is used. +msg_err_resident_doesnt_own_any_land: "The resident does not own any land personally." + +msg_unnamed: "Unnamed" \ No newline at end of file diff --git a/Towny/src/main/resources/plugin.yml b/Towny/src/main/resources/plugin.yml index ec3feb951d..640db5bc98 100644 --- a/Towny/src/main/resources/plugin.yml +++ b/Towny/src/main/resources/plugin.yml @@ -603,6 +603,7 @@ permissions: towny.command.resident.friend: true towny.command.resident.jail: true towny.command.resident.list: true + towny.command.resident.plotlist: true towny.command.resident.set.*: true towny.command.resident.otherresident: true towny.command.resident.tax: true