Skip to content

Commit f5aa7ec

Browse files
author
MagicTeaMC
committed
Stop using some of deprecated APIs
1 parent 65cf72a commit f5aa7ec

1 file changed

Lines changed: 8 additions & 23 deletions

File tree

src/main/java/org/milkteamc/autotreechop/translation/TranslationManager.java

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -249,39 +249,24 @@ private Locale parseLocale(String localeCode) {
249249
if (localeCode == null || localeCode.isEmpty()) {
250250
return null;
251251
}
252-
253-
String[] parts = localeCode.split("_");
254-
if (parts.length == 1) {
255-
return new Locale(parts[0]);
256-
} else if (parts.length == 2) {
257-
return new Locale(parts[0], parts[1]);
258-
} else if (parts.length == 3) {
259-
return new Locale(parts[0], parts[1], parts[2]);
260-
}
261-
262-
return null;
252+
String languageTag = localeCode.replace('_', '-');
253+
return Locale.forLanguageTag(languageTag);
263254
}
264255

265256
/**
266257
* Gets the appropriate locale for a command sender
267258
*/
268259
public Locale getLocale(CommandSender sender) {
269260
if (useClientLocale && sender instanceof Player player) {
270-
String clientLocale = player.getLocale();
261+
Locale clientLocale = player.locale();
271262

272-
// Try exact match first (e.g., zh_TW)
273-
Locale locale = parseLocale(clientLocale);
274-
if (locale != null && translations.containsKey(locale)) {
275-
return locale;
263+
if (translations.containsKey(clientLocale)) {
264+
return clientLocale;
276265
}
277266

278-
// Try just the language part (e.g., "zh" from "zh_TW")
279-
if (clientLocale.contains("_")) {
280-
String language = clientLocale.split("_")[0];
281-
locale = new Locale(language);
282-
if (translations.containsKey(locale)) {
283-
return locale;
284-
}
267+
Locale languageOnly = Locale.forLanguageTag(clientLocale.getLanguage());
268+
if (translations.containsKey(languageOnly)) {
269+
return languageOnly;
285270
}
286271
}
287272

0 commit comments

Comments
 (0)