Skip to content

Commit

Permalink
- Add optional -ignore subcommand to /town leave.
Browse files Browse the repository at this point in the history
    - When used, the player will not have to confirm their leaving the
town.
  • Loading branch information
LlmDl committed Feb 14, 2025
1 parent e08af78 commit 641ea8a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,10 @@ public List<String> onTabComplete(CommandSender sender, Command command, String
if (args.length == 3)
return Collections.singletonList("-ignore");
break;
case "leave":
if (args.length == 2)
return Collections.singletonList("-ignore");
break;
case "rank":
switch (args.length) {
case 2:
Expand Down Expand Up @@ -661,7 +665,7 @@ private void parseTownCommand(final Player player, String[] split) throws TownyE
case "jail"-> parseJailCommand(player, null, subArg, false);
case "join"-> parseTownJoin(player, subArg);
case "kick"-> townKick(player, subArg);
case "leave"-> townLeave(player);
case "leave"-> townLeave(player, StringMgmt.remFirstArg(split));
case "list" -> listTowns(player, split);
case "mayor" -> parseTownyMayorCommand(player);
case "merge"-> parseTownMergeCommand(player, subArg);
Expand Down Expand Up @@ -2692,7 +2696,7 @@ public static void townRename(CommandSender sender, Town town, String newName) {
}
}

public void townLeave(Player player) throws TownyException {
public void townLeave(Player player, String[] args) throws TownyException {
checkPermOrThrow(player, PermissionNodes.TOWNY_COMMAND_TOWN_LEAVE.getNode());
Resident resident = getResidentOrThrow(player);
Town town = getTownFromResidentOrThrow(resident);
Expand All @@ -2703,22 +2707,29 @@ public void townLeave(Player player) throws TownyException {
if (resident.isJailed() && TownySettings.JailDeniesTownLeave() && resident.getJailTown().getName().equals(town.getName()))
throw new TownyException(Translatable.of("msg_cannot_abandon_town_while_jailed"));

Confirmation.runOnAccept(() -> {
if (resident.isJailed() && resident.getJailTown().getUUID().equals(town.getUUID()))
JailUtil.unJailResident(resident, UnJailReason.LEFT_TOWN);

if (town.hasResident(resident))
resident.removeTown();

TownyMessaging.sendPrefixedTownMessage(town, Translatable.of("msg_left_town", resident.getName()));
TownyMessaging.sendMsg(player, Translatable.of("msg_left_town", resident.getName()));
if (args.length > 0 && args[0].equalsIgnoreCase("-ignore")) {
townLeave(player, resident, town);
return;
}

town.checkTownHasEnoughResidentsForNationRequirements();
})
Confirmation.runOnAccept(() -> townLeave(player, resident, town))
.setCancellableEvent(new TownLeaveEvent(resident, town))
.sendTo(player);
}

private void townLeave(Player player, Resident resident, Town town) {
if (resident.isJailed() && resident.getJailTown().getUUID().equals(town.getUUID()))
JailUtil.unJailResident(resident, UnJailReason.LEFT_TOWN);

if (town.hasResident(resident))
resident.removeTown();

TownyMessaging.sendPrefixedTownMessage(town, Translatable.of("msg_left_town", resident.getName()));
TownyMessaging.sendMsg(player, Translatable.of("msg_left_town", resident.getName()));

town.checkTownHasEnoughResidentsForNationRequirements();
}

/**
* Wrapper for the townSpawn() method. All calls should be through here
* unless bypassing for admins.
Expand Down
4 changes: 3 additions & 1 deletion Towny/src/main/resources/ChangeLog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10232,4 +10232,6 @@ v0.92.0.11:
- New Config Option: global_nation_settings.are_conquered_towns_given_nation_plot_perms
- Default: true
- While true, conquered towns will be considered a member of good standing in the nation, and will be treated as normal nation members when plot perms are calculated.
- When set to false plot permission tests will treat conquered towns' residents as not members of their nations, preventing them from using their host nation's plots while the nation's towns have nation plot perms enabled.
- When set to false plot permission tests will treat conquered towns' residents as not members of their nations, preventing them from using their host nation's plots while the nation's towns have nation plot perms enabled.
- Add optional -ignore subcommand to /town leave.
- When used, the player will not have to confirm their leaving the town.

0 comments on commit 641ea8a

Please sign in to comment.