Skip to content

Commit

Permalink
API: add NATION_LIST_BY, TOWN_LIST_BY TownyCommandAddons.
Browse files Browse the repository at this point in the history
Allows plugins to extend towny's /t list by and /n list by commands with
their own list commands.

Closes #7397.
  • Loading branch information
LlmDl committed May 3, 2024
1 parent 0eb183d commit dd73d64
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ public enum CommandType {
RESIDENT_SET,
RESIDENT_TOGGLE,
NATION,
NATION_LIST_BY,
NATION_SET,
NATION_TOGGLE,
TOWN,
TOWN_BUY,
TOWN_LIST_BY,
TOWN_SET,
TOWN_TOGGLE,
PLOT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ else if (args.length == 3)
case 2:
return Collections.singletonList("by");
case 3:
return NameUtil.filterByStart(nationListTabCompletes, args[2]);
return NameUtil.filterByStart(TownyCommandAddonAPI.getTabCompletes(CommandType.NATION_LIST_BY, nationListTabCompletes), args[2]);
default:
return Collections.emptyList();
}
Expand Down Expand Up @@ -810,6 +810,11 @@ public void listNations(CommandSender sender, String[] split) throws TownyExcept
int total = (int) Math.ceil(((double) nationsToSort.size()) / ((double) 10));
for (int i = 1; i < split.length; i++) {
if (split[i].equalsIgnoreCase("by")) { // Is a case of someone using /n list by {comparator}
if (TownyCommandAddonAPI.hasCommand(CommandType.NATION_LIST_BY, split[i+1])) {
TownyCommandAddonAPI.getAddonCommand(CommandType.NATION_LIST_BY, split[i+1]).execute(sender, "nation", split);
return;
}

if (comparatorSet) {
TownyMessaging.sendErrorMsg(sender, Translatable.of("msg_error_multiple_comparators_nation"));
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ public List<String> onTabComplete(CommandSender sender, Command command, String
case "list":
return switch (args.length) {
case 2 -> Collections.singletonList("by");
case 3 -> NameUtil.filterByStart(townListTabCompletes, args[2]);
case 3 -> NameUtil.filterByStart(TownyCommandAddonAPI.getTabCompletes(CommandType.TOWN_LIST_BY, townListTabCompletes), args[2]);
default -> Collections.emptyList();
};
case "trust":
Expand Down Expand Up @@ -1144,6 +1144,11 @@ public void listTowns(CommandSender sender, String[] split) throws TownyExceptio
int total = (int) Math.ceil(((double) townsToSort.size()) / ((double) 10));
for (int i = 1; i < split.length; i++) {
if (split[i].equalsIgnoreCase("by")) { // Is a case of someone using /n list by {comparator}
if (TownyCommandAddonAPI.hasCommand(CommandType.TOWN_LIST_BY, split[i+1])) {
TownyCommandAddonAPI.getAddonCommand(CommandType.TOWN_LIST_BY, split[i+1]).execute(sender, "town", split);
return;
}

if (comparatorSet) {
TownyMessaging.sendErrorMsg(sender, Translatable.of("msg_error_multiple_comparators"));
return;
Expand Down

0 comments on commit dd73d64

Please sign in to comment.