1717import org .maxgamer .quickshop .util .language .text .postprocessing .impl .ColorProcessor ;
1818import org .maxgamer .quickshop .util .language .text .postprocessing .impl .FillerProcessor ;
1919import 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
2124import java .io .File ;
2225import java .io .IOException ;
2528import java .util .*;
2629import 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}
0 commit comments