Skip to content

Commit

Permalink
- Improve /ta town new TOWNNAME MAYORNAME, to support town names
Browse files Browse the repository at this point in the history
entered with spaces in them.
  • Loading branch information
LlmDl committed Jun 27, 2024
1 parent 4929b71 commit c6225f7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1179,7 +1179,7 @@ public void parseAdminTownCommand(CommandSender sender, String[] split) throws T

// Special case where we can create a new Town before we use split[0] to get a Town.
if (split[0].equalsIgnoreCase("new")) {
parseAdminNewTownCommand(sender, split);
parseAdminNewTownCommand(sender, StringMgmt.remFirstArg(split));
return;
}

Expand Down Expand Up @@ -1398,25 +1398,27 @@ public void parseAdminTownCommand(CommandSender sender, String[] split) throws T
}

private void parseAdminNewTownCommand(CommandSender sender, String[] split) throws TownyException {
if (split.length != 3)
if (split.length < 2)
throw new TownyException(Translatable.of("msg_err_not_enough_variables") + "/ta town new [townname] [mayor]");

checkPermOrThrow(sender, PermissionNodes.TOWNY_COMMAND_TOWNYADMIN_TOWN_NEW.getNode());

String mayorName = split[split.length - 1];
String townName = StringMgmt.join(StringMgmt.remLastArg(split), "_");
Player player = sender instanceof Player p ? p : null;
Resident resident;
if ("npc".equalsIgnoreCase(split[2]) && player != null) // Avoid creating a new npc resident if command is ran from console.
if ("npc".equalsIgnoreCase(mayorName) && player != null) // Avoid creating a new npc resident if command is ran from console.
resident = ResidentUtil.createAndGetNPCResident();
else
resident = getResidentOrThrow(split[2]);
resident = getResidentOrThrow(mayorName);

// If the command is being run from console, try to sub in the specfied player.
if (player == null) {
if (!resident.isOnline())
throw new TownyException(Translatable.of("msg_player_is_not_online", split[2]));
throw new TownyException(Translatable.of("msg_player_is_not_online", mayorName));
player = resident.getPlayer();
}
TownCommand.newTown(player, split[1], resident, true, true);
TownCommand.newTown(player, townName, resident, true, true);
}

private void parseAdminTownSet(CommandSender sender, Town town, String[] split) throws TownyException {
Expand Down
3 changes: 2 additions & 1 deletion Towny/src/main/resources/ChangeLog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9845,4 +9845,5 @@ v0.92.0.11:
withdraw from the bank anyways, but it might keep towns from being deleted for not paying their upkeep.
- Fix potential NPEs in PlotGroup, courtesy of galacticwarrior9 with PR #7483.
0.100.3.4:
- Fix town plot permissions changing not causing the town to save.
- Fix town plot permissions changing not causing the town to save.
- Improve /ta town new TOWNNAME MAYORNAME, to support town names entered with spaces in them.

0 comments on commit c6225f7

Please sign in to comment.