Skip to content

Commit 0d2d08b

Browse files
committed
Allow user disable specific locale from configuration
1 parent 8fd56e2 commit 0d2d08b

File tree

3 files changed

+27
-36
lines changed

3 files changed

+27
-36
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1897,6 +1897,11 @@ private void updateConfig(int selectedVersion) throws IOException {
18971897
getConfig().set("integration.towny.delete-shop-on-plot-destroy", true);
18981898
getConfig().set("config-version", ++selectedVersion);
18991899
}
1900+
if (selectedVersion == 141) {
1901+
getConfig().set("language", null);
1902+
getConfig().set("disabled-languages",Collections.singletonList("disable_here"));
1903+
getConfig().set("config-version", ++selectedVersion);
1904+
}
19001905

19011906
if (getConfig().getInt("matcher.work-type") != 0 && GameVersion.get(ReflectFactory.getServerVersion()).name().contains("1_16")) {
19021907
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: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
import org.maxgamer.quickshop.util.language.text.postprocessing.impl.ColorProcessor;
1818
import org.maxgamer.quickshop.util.language.text.postprocessing.impl.FillerProcessor;
1919
import org.maxgamer.quickshop.util.language.text.postprocessing.impl.PlaceHolderApiProcessor;
20+
import org.maxgamer.quickshop.util.reload.ReloadResult;
21+
import org.maxgamer.quickshop.util.reload.ReloadStatus;
22+
import org.maxgamer.quickshop.util.reload.Reloadable;
2023

2124
import java.io.File;
2225
import java.io.IOException;
@@ -25,20 +28,23 @@
2528
import java.util.*;
2629
import java.util.logging.Level;
2730

28-
public class TextManager {
31+
public class TextManager implements Reloadable {
2932
private final QuickShop plugin;
3033
private final Distribution distribution;
3134
// <File <Locale, Section>>
3235
private final Map<String, Map<String, JsonConfiguration>> locale2ContentMapping = new HashMap<>();
3336
private final Map<String, JsonConfiguration> bundledFile2ContentMapping = new HashMap<>();
3437
private final static String languageFileCrowdin = "/master/src/main/resources/lang/%locale%/messages.json";
3538
public final List<PostProcessor> postProcessors = new ArrayList<>();
39+
private List<String> disabledLanguages = new ArrayList<>();
3640

3741

3842
public TextManager(QuickShop plugin) {
3943
this.plugin = plugin;
44+
plugin.getReloadManager().register(this);
4045
this.distribution = new CrowdinOTA(plugin);
4146
load();
47+
4248
}
4349

4450
@NotNull
@@ -69,7 +75,7 @@ private JsonConfiguration loadBundled(String file) {
6975
public void load() {
7076
plugin.getLogger().info("Checking for translation updates...");
7177
this.reset();
72-
78+
disabledLanguages = plugin.getConfig().getStringList("disabled-languages");
7379
// Initial file mapping
7480
locale2ContentMapping.computeIfAbsent(languageFileCrowdin, e -> new HashMap<>()); // Prevent nullportinter exception
7581
distribution.getAvailableFiles().forEach(file -> locale2ContentMapping.computeIfAbsent(file, e -> new HashMap<>()));
@@ -82,6 +88,10 @@ public void load() {
8288
try {
8389
// Minecraft client use lowercase wi
8490
String minecraftCode = crowdinCode.toLowerCase(Locale.ROOT).replace("-", "_");
91+
if(disabledLanguages.contains(minecraftCode) || disabledLanguages.contains(crowdinCode)) {
92+
Util.debugLog("Locale "+crowdinCode+"("+minecraftCode+") has been disabled, skipping.");
93+
return;
94+
}
8595
Util.debugLog("Loading translation for locale: " + crowdinCode + " (" + minecraftCode + ")");
8696
JsonConfiguration configuration = new JsonConfiguration();
8797
try {
@@ -410,4 +420,10 @@ public void send() {
410420
// plugin.getQuickChat().send(sender, lang);
411421
}
412422
}
423+
424+
@Override
425+
public ReloadResult reloadModule() throws Exception {
426+
this.load();
427+
return ReloadResult.builder().status(ReloadStatus.SUCCESS).build();
428+
}
413429
}

src/main/resources/config.yml

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -22,50 +22,20 @@
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: 141
25+
config-version: 142
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.
2929
#After you have selected your language, you need to delete the `messages.yml` file and reload the plugin to apply the new language.
3030

31-
#Available languages:
32-
#af-ZA
33-
#ar-SA
34-
#ca-ES
35-
#cs-CZ
36-
#da-DK
37-
#de-DE
38-
#el-GR
39-
#en-US
40-
#es-ES
41-
#fi-FI
42-
#fr-FR
43-
#he-IL
44-
#hu-HU
45-
#it-IT
46-
#ja-JP
47-
#ko-KR
48-
#nl-NL
49-
#no-NO
50-
#pl-PL
51-
#pt-BR
52-
#pt-PT
53-
#ro-RO
54-
#sr-SP
55-
#sv-SE
56-
#tr-TR
57-
#uk-UA
58-
#vi-VN
59-
#zh-CN
60-
#zh-TW
61-
62-
language: en-US
63-
6431
#After you have setup a language, QuickShop will download all the required Game language files from Mojang.
6532
#You can find all supported languages in your Minecraft Client Languages Menu.
6633
#Enter the language Code here (e.g English (en-US) -> Language Code = en-US).
6734
game-language: default
6835

36+
disabled-languages:
37+
- disable_here
38+
6939
#This enables the developer mode, do not touch this if you don't not know what it does!
7040
dev-mode: false
7141

0 commit comments

Comments
 (0)