Skip to content

Commit

Permalink
Add a new plotgroup mode for residents to toggle. (#6943)
Browse files Browse the repository at this point in the history
Allows a resident to set /res toggle plotgroup, which will auto-group
walked-into plots, as long as the resident has a plotgroupname set in
memory.

The plotgroupname is automatically set when a resident successfully runs
/plot group add NAME.

Closes #6404.
  • Loading branch information
LlmDl authored Aug 24, 2023
1 parent 3186094 commit 63ef45a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1216,15 +1216,13 @@ private void parsePlotGroup(String[] split, Resident resident, TownBlock townBlo
public void parsePlotGroupAdd(String[] split, TownBlock townBlock, Player player, Town town) throws TownyException {
checkPermOrThrow(player, PermissionNodes.TOWNY_COMMAND_PLOT_GROUP_ADD.getNode());

if (split.length == 1) {
TownyMessaging.sendErrorMsg(player, Translatable.of("msg_err_you_must_specify_a_group_name"));
return;
}
Resident resident = getResidentOrThrow(player);

if (split.length != 2)
if (split.length != 2 && !resident.hasPlotGroupName())
throw new TownyException(Translatable.of("msg_err_plot_group_name_required"));

String plotGroupName = NameValidation.filterName(split[1]);
String plotGroupName = split.length == 2 ? NameValidation.filterName(split[1]) :
resident.hasPlotGroupName() ? resident.getPlotGroupName() : null;
plotGroupName = NameValidation.filterCommas(plotGroupName);

if (town.hasPlotGroupName(plotGroupName)) {
Expand All @@ -1251,13 +1249,15 @@ public void parsePlotGroupAdd(String[] split, TownBlock townBlock, Player player
} else
oldGroup.save();
createOrAddOnToPlotGroup(townBlock, town, name);
resident.setPlotGroupName(name);
TownyMessaging.sendMsg(player, Translatable.of("msg_townblock_transferred_from_x_to_x_group", oldGroup.getName(), townBlock.getPlotObjectGroup().getName()));
})
.setTitle(Translatable.of("msg_plot_group_already_exists_did_you_want_to_transfer", townBlock.getPlotObjectGroup().getName(), split[1]))
.sendTo(player);
} else {
// Create a brand new plot group.
createOrAddOnToPlotGroup(townBlock, town, plotGroupName);
resident.setPlotGroupName(plotGroupName);
TownyMessaging.sendMsg(player, Translatable.of("msg_plot_was_put_into_group_x", townBlock.getX(), townBlock.getZ(), townBlock.getPlotObjectGroup().getName()));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public class ResidentCommand extends BaseCommand implements CommandExecutor {
"ignoreplots",
"bordertitles",
"townclaim",
"plotgroup",
"map",
"spy",
"reset",
Expand Down Expand Up @@ -572,6 +573,7 @@ private void setMode(Player player, String[] split) throws NoPermissionException
TownyMessaging.sendMessage(player, ChatTools.formatCommand("Mode", "map", "", Translatable.of("mode_1").forLocale(player)));
TownyMessaging.sendMessage(player, ChatTools.formatCommand("Mode", "townclaim", "", Translatable.of("mode_2").forLocale(player)));
TownyMessaging.sendMessage(player, ChatTools.formatCommand("Mode", "townunclaim", "", Translatable.of("mode_3").forLocale(player)));
TownyMessaging.sendMessage(player, ChatTools.formatCommand("Mode", "plotrgoup", "", "runs /plot group add with your last-used plot group name."));
TownyMessaging.sendMessage(player, ChatTools.formatCommand("Mode", "tc", "", Translatable.of("mode_4").forLocale(player)));
TownyMessaging.sendMessage(player, ChatTools.formatCommand("Mode", "nc", "", Translatable.of("mode_5").forLocale(player)));
TownyMessaging.sendMessage(player, ChatTools.formatCommand("Mode", "ignoreplots", "", ""));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ public void onPlayerChangePlotEvent(PlayerChangePlotEvent event) {
TownCommand.parseTownClaimCommand(player, new String[] {});
if (resident.hasMode("townunclaim"))
TownCommand.parseTownUnclaimCommand(player, new String[] {});
if (resident.hasMode("plotgroup") && resident.hasPlotGroupName())
Towny.getPlugin().getScheduler().runLater(player, () -> Bukkit.dispatchCommand(player, "plot group add " + resident.getPlotGroupName()), 1l);
} catch (TownyException e) {
TownyMessaging.sendErrorMsg(player, e.getMessage(player));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public class Resident extends TownyObject implements InviteReceiver, EconomyHand
private SelectionType guiSelectionType;
private ScheduledTask respawnProtectionTask = null;
private boolean respawnPickupWarningShown = false; // Prevents chat spam when a player attempts to pick up an item while under respawn protection.
private String plotGroupName = null;

public Resident(String name) {
super(name);
Expand Down Expand Up @@ -1014,4 +1015,16 @@ public boolean isSeeingBorderTitles() {
BooleanDataField borderMeta = new BooleanDataField("bordertitles");
return !MetaDataUtil.hasMeta(this, borderMeta) || MetaDataUtil.getBoolean(this, borderMeta);
}

public boolean hasPlotGroupName() {
return plotGroupName != null;
}

public String getPlotGroupName() {
return plotGroupName;
}

public void setPlotGroupName(String plotGroupName) {
this.plotGroupName = plotGroupName;
}
}

0 comments on commit 63ef45a

Please sign in to comment.