Skip to content

Commit abc7184

Browse files
feat(i18n): convert scoreboard strings to translation system
Replace all hardcoded strings in 8 scoreboard files with I18n.string() calls using scoreboard.properties keys for all game modes.
1 parent 9f7a4a5 commit abc7184

8 files changed

Lines changed: 137 additions & 116 deletions

File tree

type.bedwarsgame/src/main/java/net/swofty/type/bedwarsgame/BedWarsGameScoreboard.java

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@
1010
import net.swofty.type.generic.HypixelConst;
1111
import net.swofty.type.generic.data.HypixelDataHandler;
1212
import net.swofty.type.generic.data.handlers.BedWarsDataHandler;
13+
import net.swofty.type.generic.i18n.I18n;
1314
import net.swofty.type.generic.scoreboard.HypixelScoreboard;
1415
import net.swofty.type.generic.user.HypixelPlayer;
1516

1617
import java.text.SimpleDateFormat;
1718
import java.util.ArrayList;
1819
import java.util.Date;
1920
import java.util.List;
21+
import java.util.Map;
2022

2123
public class BedWarsGameScoreboard {
2224
private static final HypixelScoreboard scoreboard = new HypixelScoreboard();
@@ -46,17 +48,17 @@ public static void start(Game game) {
4648
}
4749

4850
List<String> lines = new ArrayList<>();
49-
lines.add("§7" + new SimpleDateFormat("MM/dd/yy").format(new Date()) + " §8" + HypixelConst.getServerName());
51+
lines.add("§7" + new SimpleDateFormat(I18n.string("scoreboard.common.date_format")).format(new Date()) + " §8" + HypixelConst.getServerName());
5052
lines.add("§7 ");
5153

5254
if (game.getGameStatus() == GameStatus.WAITING) {
53-
lines.add("§fMap: §a" + game.getMapEntry().getName());
54-
lines.add("§fPlayers: §a" + game.getPlayers().size() + "/" + game.getMapEntry().getConfiguration().getTeams().size());
55+
lines.add(I18n.string("scoreboard.bedwars_game.map_label") + game.getMapEntry().getName());
56+
lines.add(I18n.string("scoreboard.bedwars_game.players_label") + game.getPlayers().size() + "/" + game.getMapEntry().getConfiguration().getTeams().size());
5557
lines.add("§7 ");
56-
lines.add("§fStarting in §a" + game.getCountdown().getRemainingSeconds() + "s");
58+
lines.add(I18n.string("scoreboard.bedwars_game.starting_in_label") + game.getCountdown().getRemainingSeconds() + I18n.string("scoreboard.bedwars_game.starting_in_suffix"));
5759
lines.add("§7 ");
58-
lines.add("§fMode: §a" + game.getBedwarsGameType().getDisplayName());
59-
lines.add("§fVersion: §7v1.9");
60+
lines.add(I18n.string("scoreboard.bedwars_game.mode_label") + game.getBedwarsGameType().getDisplayName());
61+
lines.add(I18n.string("scoreboard.bedwars_game.version_label"));
6062
} else {
6163
String eventName = game.getEventManager().getNextEvent() != null
6264
? game.getEventManager().getNextEvent().getDisplayName()
@@ -65,19 +67,21 @@ public static void start(Game game) {
6567
long minutesPart = seconds / 60;
6668
long secondsPart = seconds % 60;
6769
String timeLeft = String.format("%d:%02d", minutesPart, secondsPart);
68-
lines.add("§f" + eventName + " in §a" + timeLeft);
70+
lines.add(I18n.string("scoreboard.bedwars_game.event_in_label", Map.of("event_name", eventName, "time_left", timeLeft)));
6971
lines.add("§7 ");
70-
for (java.util.Map.Entry<TeamKey, net.swofty.commons.bedwars.map.BedWarsMapsConfig.MapTeam> entry : game.getMapEntry().getConfiguration().getTeams().entrySet()) {
72+
for (Map.Entry<TeamKey, net.swofty.commons.bedwars.map.BedWarsMapsConfig.MapTeam> entry : game.getMapEntry().getConfiguration().getTeams().entrySet()) {
7173
TeamKey teamKey = entry.getKey();
7274
String teamName = teamKey.getName();
7375
String teamInitial = teamName.substring(0, 1).toUpperCase();
7476

75-
String bedStatus = game.getTeamManager().isBedAlive(teamKey) ? "§a✔" : "§c✖";
77+
String bedStatus = game.getTeamManager().isBedAlive(teamKey)
78+
? I18n.string("scoreboard.bedwars_game.bed_alive")
79+
: I18n.string("scoreboard.bedwars_game.bed_dead");
7680
lines.add(String.format("%s%s §f%s %s", teamKey.chatColor(), teamInitial, teamName, bedStatus));
7781
}
7882
}
7983
lines.add("§7 ");
80-
lines.add("§ewww.hypixel.net");
84+
lines.add(I18n.string("scoreboard.common.footer"));
8185

8286
if (!scoreboard.hasScoreboard(player)) {
8387
scoreboard.createScoreboard(player, getSidebarName(prototypeName));
@@ -95,7 +99,7 @@ public static void removeCache(Player player) {
9599
}
96100

97101
private static String getSidebarName(int counter) {
98-
String baseText = "BED WARS";
102+
String baseText = I18n.string("scoreboard.bedwars_game.title_base");
99103
String[] colors = {"§f§l", "§6§l", "§e§l"};
100104
String endColor = "§a§l";
101105

type.bedwarslobby/src/main/java/net/swofty/type/bedwarslobby/BedWarsLobbyScoreboard.java

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import net.swofty.type.generic.data.HypixelDataHandler;
1212
import net.swofty.type.generic.data.datapoints.DatapointLeaderboardLong;
1313
import net.swofty.type.generic.data.handlers.BedWarsDataHandler;
14+
import net.swofty.type.generic.i18n.I18n;
1415
import net.swofty.type.generic.scoreboard.HypixelScoreboard;
1516
import net.swofty.type.generic.user.HypixelPlayer;
1617

@@ -48,34 +49,34 @@ public static void start() {
4849

4950
double percentage = Math.min(1.0, (double) progress / maxExperience);
5051
int filledSquares = (int) Math.round(percentage * 10);
51-
StringBuilder progressBar = new StringBuilder(" §8[");
52+
StringBuilder progressBar = new StringBuilder(" " + I18n.string("scoreboard.bedwars_lobby.progress_bar_open"));
5253
for (int i = 0; i < 10; i++) {
5354
if (i < filledSquares) {
54-
progressBar.append("§b■");
55+
progressBar.append(I18n.string("scoreboard.bedwars_lobby.progress_bar_filled"));
5556
} else {
56-
progressBar.append("§7■");
57+
progressBar.append(I18n.string("scoreboard.bedwars_lobby.progress_bar_empty"));
5758
}
5859
}
59-
progressBar.append("§8]");
60+
progressBar.append(I18n.string("scoreboard.bedwars_lobby.progress_bar_close"));
6061

6162
long tokens = bwDataHandler.get(BedWarsDataHandler.Data.TOKENS, DatapointLeaderboardLong.class).getValue();
6263
long tickets = bwDataHandler.get(BedWarsDataHandler.Data.SLUMBER_TICKETS, DatapointLeaderboardLong.class).getValue();
6364

6465
List<String> lines = new ArrayList<>();
65-
lines.add("§7" + new SimpleDateFormat("MM/dd/yy").format(new Date()) + " §8" + HypixelConst.getServerName());
66+
lines.add("§7" + new SimpleDateFormat(I18n.string("scoreboard.common.date_format")).format(new Date()) + " §8" + HypixelConst.getServerName());
6667
lines.add("§7 ");
67-
lines.add("§fLevel: §7" + BedwarsLevelColor.constructLevelString(BedwarsLevelUtil.calculateLevel(experience)));
68+
lines.add(I18n.string("scoreboard.bedwars_lobby.level_label") + BedwarsLevelColor.constructLevelString(BedwarsLevelUtil.calculateLevel(experience)));
6869
lines.add("§7 ");
69-
lines.add("§fProgress: §b" + suffix(progress) + "§7/§a" + suffix(maxExperience));
70+
lines.add(I18n.string("scoreboard.bedwars_lobby.progress_label") + suffix(progress) + I18n.string("scoreboard.bedwars_lobby.progress_separator") + suffix(maxExperience));
7071
lines.add(progressBar.toString());
7172
lines.add("§7 ");
72-
lines.add("§fTokens: §2" + tokens);
73-
lines.add("§fTickets: §b" + tickets + "§7/75");
73+
lines.add(I18n.string("scoreboard.bedwars_lobby.tokens_label") + tokens);
74+
lines.add(I18n.string("scoreboard.bedwars_lobby.tickets_label") + tickets + I18n.string("scoreboard.bedwars_lobby.tickets_max"));
7475
lines.add("§7 ");
75-
lines.add("§fTotal Kills: §a0");
76-
lines.add("§fTotal Wins: §a0");
76+
lines.add(I18n.string("scoreboard.bedwars_lobby.total_kills_label"));
77+
lines.add(I18n.string("scoreboard.bedwars_lobby.total_wins_label"));
7778
lines.add("§7 ");
78-
lines.add("§ewww.hypixel.net");
79+
lines.add(I18n.string("scoreboard.common.footer"));
7980

8081
if (!scoreboard.hasScoreboard(player)) {
8182
scoreboard.createScoreboard(player, getSidebarName(prototypeName));
@@ -93,7 +94,7 @@ public static void removeCache(Player player) {
9394
}
9495

9596
private static String getSidebarName(int counter) {
96-
String baseText = "BED WARS";
97+
String baseText = I18n.string("scoreboard.bedwars_lobby.title_base");
9798
String[] colors = {"§f§l", "§6§l", "§e§l"};
9899
String endColor = "§a§l";
99100

type.murdermysterygame/src/main/java/net/swofty/type/murdermysterygame/MurderMysteryGameScoreboard.java

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@
1111
import net.swofty.type.murdermysterygame.role.GameRole;
1212
import net.swofty.type.murdermysterygame.user.MurderMysteryPlayer;
1313
import net.swofty.type.generic.HypixelConst;
14+
import net.swofty.type.generic.i18n.I18n;
1415
import net.swofty.type.generic.scoreboard.HypixelScoreboard;
1516

1617
import java.text.SimpleDateFormat;
1718
import java.util.ArrayList;
1819
import java.util.Date;
1920
import java.util.List;
21+
import java.util.Map;
2022

2123
public class MurderMysteryGameScoreboard {
2224
private static final HypixelScoreboard scoreboard = new HypixelScoreboard();
@@ -37,102 +39,106 @@ public static void start() {
3739
if (player.getInstance() == null) continue;
3840

3941
List<String> lines = new ArrayList<>();
40-
lines.add("§7" + new SimpleDateFormat("MM/dd/yy").format(new Date()) + " §8" + HypixelConst.getServerName());
42+
lines.add("§7" + new SimpleDateFormat(I18n.string("scoreboard.common.date_format")).format(new Date()) + " §8" + HypixelConst.getServerName());
4143
lines.add("§7 ");
4244

4345
if (game.getGameStatus() == GameStatus.WAITING) {
44-
lines.add("§fMap: §a" + game.getMapEntry().getName());
45-
lines.add("§fPlayers: §a" + game.getPlayers().size() + "/" + game.getGameType().getMaxPlayers());
46+
lines.add(I18n.string("scoreboard.murdermystery_game.map_label") + game.getMapEntry().getName());
47+
lines.add(I18n.string("scoreboard.murdermystery_game.players_label") + game.getPlayers().size() + "/" + game.getGameType().getMaxPlayers());
4648
lines.add("§7 ");
4749
if (game.getCountdown().isActive()) {
48-
lines.add("§fStarting in §a" + game.getCountdown().getSecondsRemaining() + "s");
50+
lines.add(I18n.string("scoreboard.murdermystery_game.starting_in_label") + game.getCountdown().getSecondsRemaining() + I18n.string("scoreboard.murdermystery_game.starting_in_suffix"));
4951
} else {
50-
lines.add("§fWaiting for players...");
52+
lines.add(I18n.string("scoreboard.murdermystery_game.waiting_for_players"));
5153
}
5254
lines.add("§7 ");
53-
lines.add("§fMode: §a" + game.getGameType().getDisplayName());
55+
lines.add(I18n.string("scoreboard.murdermystery_game.mode_label") + game.getGameType().getDisplayName());
5456

5557
int playerCount = game.getPlayers().size();
5658
int murdererChance = playerCount > 0 ? Math.round(100f / playerCount) : 0;
5759
int detectiveChance = playerCount > 0 ? Math.round(100f / playerCount) : 0;
5860
Component actionBar = Component.empty()
59-
.append(Component.text("Murderer Chance: " + murdererChance + "%", NamedTextColor.RED))
61+
.append(Component.text(I18n.string("scoreboard.murdermystery_game.actionbar.murderer_chance", Map.of("chance", String.valueOf(murdererChance))), NamedTextColor.RED))
6062
.append(Component.text(" ", NamedTextColor.GRAY))
61-
.append(Component.text("Detective Chance: " + detectiveChance + "%", NamedTextColor.AQUA));
63+
.append(Component.text(I18n.string("scoreboard.murdermystery_game.actionbar.detective_chance", Map.of("chance", String.valueOf(detectiveChance))), NamedTextColor.AQUA));
6264
player.sendActionBar(actionBar);
6365
} else if (game.getGameStatus() == GameStatus.IN_PROGRESS) {
6466
GameRole role = game.getRoleManager().getRole(player.getUuid());
6567

6668
if (player.isEliminated()) {
67-
lines.add("§7§lSPECTATING");
69+
lines.add(I18n.string("scoreboard.murdermystery_game.spectating_label"));
6870
lines.add("§7 ");
6971

7072
if (role != null) {
71-
lines.add("§fYour Role: " + getScoreboardRoleColor(role) + role.getDisplayName());
73+
lines.add(I18n.string("scoreboard.murdermystery_game.your_role_label") + " " + getScoreboardRoleColor(role) + role.getDisplayName());
7274
}
7375
lines.add("§7 ");
7476

7577
int playersAlive = game.getRoleManager().countAliveWithRole(GameRole.INNOCENT)
7678
+ game.getRoleManager().countAliveWithRole(GameRole.DETECTIVE)
7779
+ game.getRoleManager().countAliveWithRole(GameRole.MURDERER);
78-
lines.add("§fPlayers Alive: §a" + playersAlive);
80+
lines.add(I18n.string("scoreboard.murdermystery_game.players_alive_label") + playersAlive);
7981

8082
String timeLeft = formatTimeRemaining(game.getGameStartTime());
81-
lines.add("§fTime Left: §a" + timeLeft);
83+
lines.add(I18n.string("scoreboard.murdermystery_game.time_left_label") + timeLeft);
8284
lines.add("§7 ");
8385

8486
boolean detectiveAlive = game.getRoleManager().countAliveWithRole(GameRole.DETECTIVE) > 0;
85-
String detectiveStatus = detectiveAlive ? "§aAlive" : "§cDead";
86-
lines.add("§fDetective: " + detectiveStatus);
87+
String detectiveStatus = detectiveAlive
88+
? I18n.string("scoreboard.murdermystery_game.detective_alive")
89+
: I18n.string("scoreboard.murdermystery_game.detective_dead");
90+
lines.add(I18n.string("scoreboard.murdermystery_game.detective_label") + " " + detectiveStatus);
8791
lines.add("§7 ");
8892

89-
lines.add("§fMap: §a" + game.getMapEntry().getName());
93+
lines.add(I18n.string("scoreboard.murdermystery_game.map_label") + game.getMapEntry().getName());
9094
} else {
9195
if (role != null) {
92-
lines.add("§fRole: " + getScoreboardRoleColor(role) + role.getDisplayName());
96+
lines.add(I18n.string("scoreboard.murdermystery_game.role_label") + " " + getScoreboardRoleColor(role) + role.getDisplayName());
9397
}
9498
lines.add("§7 ");
9599

96100
int innocentsLeft = game.getRoleManager().countAliveWithRole(GameRole.INNOCENT)
97101
+ game.getRoleManager().countAliveWithRole(GameRole.DETECTIVE);
98-
lines.add("§fInnocents Left: §a" + innocentsLeft);
102+
lines.add(I18n.string("scoreboard.murdermystery_game.innocents_left_label") + innocentsLeft);
99103

100104
String timeLeft = formatTimeRemaining(game.getGameStartTime());
101-
lines.add("§fTime Left: §a" + timeLeft);
105+
lines.add(I18n.string("scoreboard.murdermystery_game.time_left_label") + timeLeft);
102106
lines.add("§7 ");
103107

104108
boolean detectiveAlive = game.getRoleManager().countAliveWithRole(GameRole.DETECTIVE) > 0;
105-
String detectiveStatus = detectiveAlive ? "§aAlive" : "§cDead";
106-
lines.add("§fDetective: " + detectiveStatus);
109+
String detectiveStatus = detectiveAlive
110+
? I18n.string("scoreboard.murdermystery_game.detective_alive")
111+
: I18n.string("scoreboard.murdermystery_game.detective_dead");
112+
lines.add(I18n.string("scoreboard.murdermystery_game.detective_label") + " " + detectiveStatus);
107113
lines.add("§7 ");
108114

109-
lines.add("§fMap: §a" + game.getMapEntry().getName());
115+
lines.add(I18n.string("scoreboard.murdermystery_game.map_label") + game.getMapEntry().getName());
110116
}
111117
} else if (game.getGameStatus() == GameStatus.ENDING) {
112-
lines.add("§a§lGAME OVER!");
118+
lines.add(I18n.string("scoreboard.murdermystery_game.game_over"));
113119
lines.add("§7 ");
114120

115121
GameRole role = game.getRoleManager().getRole(player.getUuid());
116122
if (role != null) {
117-
lines.add("§fYour Role: " + getScoreboardRoleColor(role) + role.getDisplayName());
123+
lines.add(I18n.string("scoreboard.murdermystery_game.your_role_label") + " " + getScoreboardRoleColor(role) + role.getDisplayName());
118124
}
119125
lines.add("§7 ");
120126

121127
int kills = player.getKillsThisGame();
122128
if (kills > 0) {
123-
lines.add("§fYour Kills: §a" + kills);
129+
lines.add(I18n.string("scoreboard.murdermystery_game.your_kills_label") + kills);
124130
}
125131

126132
int tokens = player.getTokensEarnedThisGame();
127-
lines.add("§fTokens Earned: §6" + tokens);
133+
lines.add(I18n.string("scoreboard.murdermystery_game.tokens_earned_label") + tokens);
128134
lines.add("§7 ");
129135

130-
lines.add("§fMap: §a" + game.getMapEntry().getName());
131-
lines.add("§fMode: §a" + game.getGameType().getDisplayName());
136+
lines.add(I18n.string("scoreboard.murdermystery_game.map_label") + game.getMapEntry().getName());
137+
lines.add(I18n.string("scoreboard.murdermystery_game.mode_label") + game.getGameType().getDisplayName());
132138
}
133139

134140
lines.add("§7 ");
135-
lines.add("§ewww.hypixel.net");
141+
lines.add(I18n.string("scoreboard.common.footer"));
136142

137143
if (!scoreboard.hasScoreboard(player)) {
138144
scoreboard.createScoreboard(player, getSidebarName(animationFrame));
@@ -148,15 +154,15 @@ public static void start() {
148154

149155
private static String getScoreboardRoleColor(GameRole role) {
150156
return switch (role) {
151-
case MURDERER -> "§c";
152-
case DETECTIVE -> "§b";
153-
case INNOCENT -> "§a";
154-
case ASSASSIN -> "§6";
157+
case MURDERER -> I18n.string("scoreboard.murdermystery_game.role_color.murderer");
158+
case DETECTIVE -> I18n.string("scoreboard.murdermystery_game.role_color.detective");
159+
case INNOCENT -> I18n.string("scoreboard.murdermystery_game.role_color.innocent");
160+
case ASSASSIN -> I18n.string("scoreboard.murdermystery_game.role_color.assassin");
155161
};
156162
}
157163

158164
private static String formatTimeRemaining(long gameStartTime) {
159-
if (gameStartTime == 0) return "5:00";
165+
if (gameStartTime == 0) return I18n.string("scoreboard.murdermystery_game.time_left_default");
160166
long elapsed = System.currentTimeMillis() - gameStartTime;
161167
long remaining = GAME_DURATION_MS - elapsed;
162168
if (remaining < 0) remaining = 0;
@@ -171,7 +177,7 @@ public static void removeCache(Player player) {
171177
}
172178

173179
private static String getSidebarName(int counter) {
174-
String baseText = "MURDER MYSTERY";
180+
String baseText = I18n.string("scoreboard.murdermystery_game.title_base");
175181
String[] colors = {"§f§l", "§6§l", "§e§l"};
176182
String endColor = "§a§l";
177183

type.murdermysterylobby/src/main/java/net/swofty/type/murdermysterylobby/MurderMysteryLobbyScoreboard.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import net.swofty.type.generic.HypixelGenericLoader;
1111
import net.swofty.type.generic.data.datapoints.DatapointMurderMysteryModeStats;
1212
import net.swofty.type.generic.data.handlers.MurderMysteryDataHandler;
13+
import net.swofty.type.generic.i18n.I18n;
1314
import net.swofty.type.generic.scoreboard.HypixelScoreboard;
1415
import net.swofty.type.generic.user.HypixelPlayer;
1516

@@ -56,17 +57,17 @@ public static void start() {
5657
}
5758

5859
List<String> lines = new ArrayList<>();
59-
lines.add("§7" + new SimpleDateFormat("MM/dd/yy").format(new Date()) + " §8" + HypixelConst.getServerName());
60+
lines.add("§7" + new SimpleDateFormat(I18n.string("scoreboard.common.date_format")).format(new Date()) + " §8" + HypixelConst.getServerName());
6061
lines.add("§7 ");
61-
lines.add("§fTotal Kills: §a" + totalKills);
62-
lines.add("§fTotal Wins: §a" + totalWins);
62+
lines.add(I18n.string("scoreboard.murdermystery_lobby.total_kills_label") + totalKills);
63+
lines.add(I18n.string("scoreboard.murdermystery_lobby.total_wins_label") + totalWins);
6364
lines.add("§7 ");
64-
lines.add("§fWins as Detective: §a" + detectiveWins);
65-
lines.add("§fWins as Murderer: §a" + murdererWins);
65+
lines.add(I18n.string("scoreboard.murdermystery_lobby.wins_as_detective_label") + detectiveWins);
66+
lines.add(I18n.string("scoreboard.murdermystery_lobby.wins_as_murderer_label") + murdererWins);
6667
lines.add("§7 ");
67-
lines.add("§fTokens: §2" + tokens);
68+
lines.add(I18n.string("scoreboard.murdermystery_lobby.tokens_label") + tokens);
6869
lines.add("§7 ");
69-
lines.add("§ewww.hypixel.net");
70+
lines.add(I18n.string("scoreboard.common.footer"));
7071

7172
if (!scoreboard.hasScoreboard(player)) {
7273
scoreboard.createScoreboard(player, getSidebarName(animationFrame));
@@ -84,7 +85,7 @@ public static void removeCache(Player player) {
8485
}
8586

8687
private static String getSidebarName(int counter) {
87-
String baseText = "MURDER MYSTERY";
88+
String baseText = I18n.string("scoreboard.murdermystery_lobby.title_base");
8889
String[] colors = {"§f§l", "§6§l", "§e§l"};
8990
String endColor = "§a§l";
9091

0 commit comments

Comments
 (0)