Skip to content

Commit 176afe3

Browse files
committed
Remove language cause it useless, all option switch to game-language
1 parent a45e015 commit 176afe3

File tree

5 files changed

+37
-33
lines changed

5 files changed

+37
-33
lines changed

src/main/java/org/maxgamer/quickshop/QuickShop.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1941,16 +1941,18 @@ private void updateConfig(int selectedVersion) throws IOException {
19411941
getConfiguration().set("config-version", ++selectedVersion);
19421942
}
19431943
if (selectedVersion == 143) {
1944-
if (getConfiguration().get("language") == null) {
1945-
getConfiguration().set("language", "en-US");
1946-
}
1944+
getConfiguration().set("language", null);
1945+
// if (getConfiguration().get("language") == null) {
1946+
// getConfiguration().set("language", "en-US");
1947+
// }
19471948
getConfiguration().set("config-version", ++selectedVersion);
19481949
}
19491950

19501951
if (selectedVersion == 144) {
19511952
// Updater set it to true because plugin upgrading
19521953
// Default configuration disable it cause probably fresh install
19531954
getConfiguration().getOrDefault("legacy-updater.shop-sign", true);
1955+
getConfiguration().set("language", null);
19541956
getConfiguration().set("config-version", ++selectedVersion);
19551957
}
19561958
if (getConfiguration().getInt("matcher.work-type") != 0 && GameVersion.get(ReflectFactory.getServerVersion()).name().contains("1_16")) {

src/main/java/org/maxgamer/quickshop/localization/game/game/MojangGameLanguageImpl.java

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import lombok.Getter;
2626
import lombok.SneakyThrows;
2727
import org.apache.commons.codec.digest.DigestUtils;
28-
import org.apache.commons.lang.StringUtils;
2928
import org.bukkit.Material;
3029
import org.bukkit.configuration.file.YamlConfiguration;
3130
import org.bukkit.enchantments.Enchantment;
@@ -47,7 +46,6 @@
4746
import java.io.IOException;
4847
import java.nio.charset.StandardCharsets;
4948
import java.nio.file.Files;
50-
import java.util.Locale;
5149
import java.util.Optional;
5250
import java.util.concurrent.TimeUnit;
5351
import java.util.concurrent.locks.Condition;
@@ -72,29 +70,7 @@ public class MojangGameLanguageImpl extends BukkitGameLanguageImpl implements Ga
7270
public MojangGameLanguageImpl(@NotNull QuickShop plugin, @NotNull String languageCode) {
7371
super(plugin);
7472
this.plugin = plugin;
75-
if ("default".equalsIgnoreCase(languageCode)) {
76-
Locale locale = Locale.getDefault();
77-
String language = locale.getLanguage();
78-
String country = locale.getCountry();
79-
boolean isLanguageEmpty = StringUtils.isEmpty(language);
80-
boolean isCountryEmpty = StringUtils.isEmpty(country);
81-
if (isLanguageEmpty && isCountryEmpty) {
82-
plugin.getLogger().warning("Unable to get language code, fallback to en_US, please change game-language option in config.yml.");
83-
languageCode = "en_US";
84-
} else {
85-
if (isCountryEmpty || isLanguageEmpty) {
86-
languageCode = isLanguageEmpty ? country + '_' + country : language + '_' + language;
87-
if ("en_en".equals(languageCode)) {
88-
languageCode = "en_US";
89-
}
90-
plugin.getLogger().warning("Unable to get language code, guessing " + languageCode + " instead, If it's incorrect, please change game-language option in config.yml.");
91-
} else {
92-
languageCode = language + '_' + country;
93-
}
94-
}
95-
}
96-
languageCode = languageCode.replace("-", "_").toLowerCase(Locale.ROOT);
97-
73+
languageCode = MsgUtil.processGameLanguageCode(languageCode);
9874
switch (plugin.getConfiguration().getOrDefault("mojangapi-mirror", 0)) {
9975
case 0:
10076
mirror = new MojangApiOfficialMirror();

src/main/java/org/maxgamer/quickshop/shop/ContainerShop.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import org.maxgamer.quickshop.api.chat.ComponentPackage;
5353
import org.maxgamer.quickshop.api.event.*;
5454
import org.maxgamer.quickshop.api.shop.*;
55+
import org.maxgamer.quickshop.util.MsgUtil;
5556
import org.maxgamer.quickshop.util.ReflectFactory;
5657
import org.maxgamer.quickshop.util.Util;
5758
import org.maxgamer.quickshop.util.logging.container.ShopRemoveLog;
@@ -819,7 +820,7 @@ public void setSignText() {
819820
if (!Util.isLoaded(this.location)) {
820821
return;
821822
}
822-
this.setSignText(getSignText(plugin.getConfiguration().getOrDefault("language", "en-US")));
823+
this.setSignText(getSignText(MsgUtil.processGameLanguageCode(plugin.getConfiguration().getOrDefault("game-language", "default"))));
823824
// this.setSignText(getSignText("en_us"));
824825
}
825826

src/main/java/org/maxgamer/quickshop/util/MsgUtil.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,33 @@ public static String fillArgs(@Nullable String raw, @Nullable String... args) {
170170
return raw;
171171
}
172172

173+
@Unstable
174+
public static String processGameLanguageCode(String languageCode) {
175+
if ("default".equalsIgnoreCase(languageCode)) {
176+
Locale locale = Locale.getDefault();
177+
String language = locale.getLanguage();
178+
String country = locale.getCountry();
179+
boolean isLanguageEmpty = StringUtils.isEmpty(language);
180+
boolean isCountryEmpty = StringUtils.isEmpty(country);
181+
if (isLanguageEmpty && isCountryEmpty) {
182+
plugin.getLogger().warning("Unable to get language code, fallback to en_us, please change game-language option in config.yml.");
183+
languageCode = "en_us";
184+
} else {
185+
if (isCountryEmpty || isLanguageEmpty) {
186+
languageCode = isLanguageEmpty ? country + '_' + country : language + '_' + language;
187+
if ("en_en".equals(languageCode)) {
188+
languageCode = "en_us";
189+
}
190+
plugin.getLogger().warning("Unable to get language code, guessing " + languageCode + " instead, If it's incorrect, please change game-language option in config.yml.");
191+
} else {
192+
languageCode = language + '_' + country;
193+
}
194+
}
195+
}
196+
languageCode = languageCode.replace("-", "_").toLowerCase(Locale.ROOT);
197+
return languageCode;
198+
}
199+
173200
@Unstable
174201
@Deprecated
175202
public static void loadGameLanguage(@NotNull String languageCode) {

src/main/resources/config.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
#Do not touch this if you don't know what you're doing!
44
config-version: 145
55

6-
#This language will used by Shop signs and other texts that direct write on the block/entity.
7-
language: en-US
8-
9-
#This language will used by Item Name, Enchantment Name and Potion Effect Name and other them related position.
6+
#This language will used by Item Name, Enchantment Name,
7+
#and Potion Effect Name or the text on the shop info sign (nbtapi not installed) and other them related position.
108
#Use default will use your system language.
119
game-language: default
1210

0 commit comments

Comments
 (0)