Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Town board command improvements #6186

Merged
merged 2 commits into from
Sep 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion resources/lang/en-US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1763,4 +1763,6 @@ msg_town_plot_type_limit_reached: 'Your town has reached the limit of %d %s plot
msg_spawn_cost_free: 'Free'

#Message shown when someone tries to set a plot's type to one already set.
msg_plot_already_of_type: 'This plot is already a %s type.'
msg_plot_already_of_type: 'This plot is already a %s type.'

msg_town_board_reset: '&bTown board reset.'
6 changes: 3 additions & 3 deletions src/com/palmergames/bukkit/towny/TownyMessaging.java
Original file line number Diff line number Diff line change
Expand Up @@ -285,14 +285,14 @@ public static void sendPrefixedNationMessage(Nation nation, String line) {
/**
* Send the town board to a player (in yellow)
*
* @param player player to show to
* @param sender sender to show to
* @param town the town for which to show it's board
*/
public static void sendTownBoard(Player player, Town town) {
public static void sendTownBoard(CommandSender sender, Town town) {
String tbColor1 = Translation.of("townboard_message_colour_1");
String tbColor2 = Translation.of("townboard_message_colour_2");

sendMessage(player, tbColor1 + "[" + StringMgmt.remUnderscore(town.getName()) + "] " + tbColor2 + town.getBoard());
sendMessage(sender, tbColor1 + "[" + StringMgmt.remUnderscore(town.getName()) + "] " + tbColor2 + town.getBoard());
}

/**
Expand Down
48 changes: 29 additions & 19 deletions src/com/palmergames/bukkit/towny/command/TownCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -259,12 +259,17 @@ public class TownCommand extends BaseCommand implements CommandExecutor {
"all"
);

private static List<String> townInviteTabCompletes = Arrays.asList(
private static final List<String> townInviteTabCompletes = Arrays.asList(
"sent",
"received",
"accept",
"deny"
);

private static final List<String> townSetBoardTabCompletes = Arrays.asList(
"none",
"reset"
);

public TownCommand(Towny instance) {

Expand All @@ -274,8 +279,7 @@ public TownCommand(Towny instance) {
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {

if (sender instanceof Player) {
Player player = (Player) sender;
if (sender instanceof Player player) {

switch (args[0].toLowerCase()) {
case "online":
Expand Down Expand Up @@ -525,6 +529,9 @@ static List<String> townSetTabComplete(CommandSender sender, Town town, String[]
case "surname":
if (args.length == 3)
return NameUtil.filterByStart(NameUtil.getNames(town.getResidents()), args[2]);
case "board":
if (args.length == 3)
return NameUtil.filterByStart(townSetBoardTabCompletes, args[2]);
default:
return Collections.emptyList();
}
Expand Down Expand Up @@ -1909,7 +1916,7 @@ public static void townSet(CommandSender sender, String[] split, boolean admin,
if (split[0].equalsIgnoreCase("board")) {

checkPermOrThrow(sender, PermissionNodes.TOWNY_COMMAND_TOWN_SET_BOARD.getNode());
townSetBoard(sender, split, town, player);
townSetBoard(sender, String.join(" ", StringMgmt.remFirstArg(split)), town);

} else if (split[0].equalsIgnoreCase("title")) {

Expand Down Expand Up @@ -2031,29 +2038,32 @@ public static void townSet(CommandSender sender, String[] split, boolean admin,

}

public static void townSetBoard(CommandSender sender, String[] split, Town town, Player player) throws TownyException {
public static void townSetBoard(CommandSender sender, String board, Town town) throws TownyException {

if (split.length < 2)
if (board.isEmpty())
throw new TownyException("Eg: /town set board " + Translatable.of("town_help_9").forLocale(sender));

String line = StringMgmt.join(StringMgmt.remFirstArg(split), " ");

if (!line.equals("none")) {
if (!NameValidation.isValidString(line)) {
if ("reset".equalsIgnoreCase(board)) {
board = TownySettings.getTownDefaultBoard();
Warriorrrr marked this conversation as resolved.
Show resolved Hide resolved

TownyMessaging.sendMsg(sender, Translatable.of("msg_town_board_reset"));
} else if ("none".equalsIgnoreCase(board) || "clear".equalsIgnoreCase(board)) {
board = "";
} else {
if (!NameValidation.isValidString(board)) {
TownyMessaging.sendErrorMsg(sender, Translatable.of("msg_err_invalid_string_board_not_set"));
return;
}

// TownyFormatter shouldn't be given any string longer than 159, or it has trouble splitting lines.
if (line.length() > 159)
line = line.substring(0, 159);
} else
line = "";
if (board.length() > 159)
board = board.substring(0, 159);
}

town.setBoard(line);
// Player is null when set via the /townyadmin command.
if (player == null)
return;
TownyMessaging.sendTownBoard(player, town);
town.setBoard(board);
town.save();

TownyMessaging.sendTownBoard(sender, town);
}

@Deprecated
Expand Down