Skip to content

Commit 82e9a94

Browse files
committed
add regex support, change to white-list mode
1 parent 2ef0da1 commit 82e9a94

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1908,6 +1908,11 @@ private void updateConfig(int selectedVersion) throws IOException {
19081908
getConfig().set("shop.use-fast-shop-search-algorithm",null);
19091909
getConfig().set("config-version", ++selectedVersion);
19101910
}
1911+
if(selectedVersion == 142){
1912+
getConfig().set("disabled-languages",null);
1913+
getConfig().set("enabled-languages",Collections.singletonList("*"));
1914+
getConfig().set("config-version", ++selectedVersion);
1915+
}
19111916

19121917
if (getConfig().getInt("matcher.work-type") != 0 && GameVersion.get(ReflectFactory.getServerVersion()).name().contains("1_16")) {
19131918
getLogger().warning("You are not using QS Matcher, it may meeting item comparing issue mentioned there: https://hub.spigotmc.org/jira/browse/SPIGOT-5063");

src/main/java/org/maxgamer/quickshop/util/language/text/TextManager.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.nio.charset.StandardCharsets;
2828
import java.util.*;
2929
import java.util.logging.Level;
30+
import java.util.regex.PatternSyntaxException;
3031

3132
public class TextManager implements Reloadable {
3233
private final QuickShop plugin;
@@ -35,7 +36,6 @@ public class TextManager implements Reloadable {
3536
private final TextMapper mapper = new TextMapper();
3637
private final static String CROWDIN_LANGUAGE_FILE = "/master/src/main/resources/lang/%locale%/messages.json";
3738
public final List<PostProcessor> postProcessors = new ArrayList<>();
38-
private List<String> disabledLanguages = new ArrayList<>();
3939

4040

4141
public TextManager(QuickShop plugin) {
@@ -66,7 +66,6 @@ private File getOverrideFilesFolder(@NotNull String crowdinPath) {
6666
private void reset() {
6767
mapper.reset();
6868
postProcessors.clear();
69-
disabledLanguages.clear();
7069
}
7170

7271
/**
@@ -93,14 +92,14 @@ private JsonConfiguration loadBundled(String file) {
9392
public void load() {
9493
plugin.getLogger().info("Checking for translation updates...");
9594
this.reset();
96-
disabledLanguages = plugin.getConfig().getStringList("disabled-languages");
95+
List<String> enabledLanguagesRegex = plugin.getConfig().getStringList("enabled-languages");
9796
// Multi File and Multi-Language loader
9897
distribution.getAvailableLanguages().parallelStream().forEach(crowdinCode -> distribution.getAvailableFiles().parallelStream().forEach(crowdinFile -> {
9998
try {
10099
// Minecraft client use lowercase wi
101100
String minecraftCode = crowdinCode.toLowerCase(Locale.ROOT).replace("-", "_");
102-
if (disabledLanguages.contains(minecraftCode) || disabledLanguages.contains(crowdinCode)) {
103-
Util.debugLog("Locale " + crowdinCode + "(" + minecraftCode + ") has been disabled, skipping.");
101+
if (!localeEnabled(minecraftCode,enabledLanguagesRegex)) {
102+
Util.debugLog("Locale: " + minecraftCode + " not enabled in configuration.");
104103
return;
105104
}
106105
Util.debugLog("Loading translation for locale: " + crowdinCode + " (" + minecraftCode + ")");
@@ -128,6 +127,19 @@ public void load() {
128127
postProcessors.add(new ColorProcessor());
129128
}
130129

130+
private boolean localeEnabled(String locale, List<String> regex){
131+
for (String languagesRegex : regex) {
132+
try {
133+
if (locale.matches(languagesRegex)) {
134+
return true;
135+
}
136+
} catch (PatternSyntaxException exception) {
137+
Util.debugLog("Pattern " + languagesRegex + " invalid, skipping...");
138+
}
139+
}
140+
return false;
141+
}
142+
131143
private void applyOverrideConfiguration(JsonConfiguration distributionConfiguration, JsonConfiguration overrideConfiguration) {
132144
for (String key : overrideConfiguration.getKeys(true)) {
133145
if ("language-version".equals(key) || "config-version".equals(key) || "version".equals(key)) {

src/main/resources/config.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
# TO EDIT QUICKSHOP'S CONFIGURATION, USE THE "config.yml" FILE!
2323

2424
#Do not touch this if you don't know what you're doing!
25-
config-version: 142
25+
config-version: 143
2626

2727
#Select the language you want to use, (e.g de), use only supported language codes from the list below.
2828
#If you use a not existant/not supported language, then QuickShop will use en_US.
@@ -40,8 +40,8 @@ game-language: default
4040
# By default, QuickShop use Mojang official servers to downloading resources.
4141
mojangapi-mirror: 0
4242

43-
disabled-languages:
44-
- disable_here
43+
enabled-languages:
44+
- '*'
4545

4646
#This enables the developer mode, do not touch this if you don't not know what it does!
4747
dev-mode: false

0 commit comments

Comments
 (0)