Skip to content

Commit

Permalink
Add /res plotlist Command
Browse files Browse the repository at this point in the history
New Permission Node: towny.command.resident.plotlist
New Command: /res plotlist {#}
New Command: /res plotlist [name] {#}

Closes #7075
  • Loading branch information
LlmDl committed Nov 10, 2023
1 parent 93c41b8 commit c8f00fb
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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<TownBlock> 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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -52,6 +53,7 @@ public class ResidentCommand extends BaseCommand implements CommandExecutor {
"friend",
"list",
"jail",
"plotlist",
"spawn",
"toggle",
"set",
Expand Down Expand Up @@ -168,6 +170,12 @@ public List<String> 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");
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
7 changes: 6 additions & 1 deletion Towny/src/main/resources/lang/en-US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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."
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"
1 change: 1 addition & 0 deletions Towny/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c8f00fb

Please sign in to comment.