@@ -32,8 +32,7 @@ public class TextManager implements Reloadable {
3232 private final QuickShop plugin ;
3333 private final Distribution distribution ;
3434 // <File <Locale, Section>>
35- private final Map <String , Map <String , JsonConfiguration >> locale2ContentMapping = new HashMap <>();
36- private final Map <String , JsonConfiguration > bundledFile2ContentMapping = new HashMap <>();
35+ private final TextMapper mapper = new TextMapper ();
3736 private final static String CROWDIN_LANGUAGE_FILE = "/master/src/main/resources/lang/%locale%/messages.json" ;
3837 public final List <PostProcessor > postProcessors = new ArrayList <>();
3938 private List <String > disabledLanguages = new ArrayList <>();
@@ -65,9 +64,8 @@ private File getOverrideFilesFolder(@NotNull String crowdinPath) {
6564 * Reset everything
6665 */
6766 private void reset () {
68- locale2ContentMapping . clear ();
67+ mapper . reset ();
6968 postProcessors .clear ();
70- bundledFile2ContentMapping .clear ();
7169 disabledLanguages .clear ();
7270 }
7371
@@ -97,11 +95,11 @@ public void load() {
9795 this .reset ();
9896 disabledLanguages = plugin .getConfig ().getStringList ("disabled-languages" );
9997 // Initial file mapping
100- locale2ContentMapping .computeIfAbsent (CROWDIN_LANGUAGE_FILE , e -> new HashMap <>()); // Prevent nullportinter exception
101- distribution .getAvailableFiles ().forEach (file -> locale2ContentMapping .computeIfAbsent (file , e -> new HashMap <>()));
98+ // locale2ContentMapping.computeIfAbsent(CROWDIN_LANGUAGE_FILE, e -> new HashMap<>()); // Prevent nullportinter exception
99+ // distribution.getAvailableFiles().forEach(file -> locale2ContentMapping.computeIfAbsent(file, e -> new HashMap<>()));
102100
103101 // Read bundled language files
104- distribution .getAvailableFiles ().forEach (crowdinFile -> this .bundledFile2ContentMapping .computeIfAbsent (crowdinFile , e -> loadBundled (crowdinFile )));
102+ // distribution.getAvailableFiles().forEach(crowdinFile -> this.bundledFile2ContentMapping.computeIfAbsent(crowdinFile, e -> loadBundled(crowdinFile)));
105103
106104 // Multi File and Multi-Language loader
107105 distribution .getAvailableLanguages ().parallelStream ().forEach (crowdinCode -> distribution .getAvailableFiles ().parallelStream ().forEach (crowdinFile -> {
@@ -116,8 +114,8 @@ public void load() {
116114 JsonConfiguration configuration = getDistributionConfiguration (crowdinFile , crowdinCode );
117115 // Loading override text (allow user modification the translation)
118116 JsonConfiguration override = getOverrideConfiguration (crowdinFile , minecraftCode );
119- applyOverrideConfiguration (configuration ,override );
120- locale2ContentMapping . get (crowdinFile ). computeIfAbsent ( minecraftCode , e -> configuration );
117+ applyOverrideConfiguration (configuration , override );
118+ mapper . deploy (crowdinFile , minecraftCode , configuration , loadBundled ( crowdinFile ) );
121119 Util .debugLog ("Locale " + crowdinFile .replace ("%locale%" , crowdinCode ) + " has been successfully loaded" );
122120 } catch (CrowdinOTA .OTAException e ) {
123121 // Key founds in available locales but not in custom mapping on crowdin platform
@@ -137,7 +135,7 @@ public void load() {
137135 postProcessors .add (new ColorProcessor ());
138136 }
139137
140- private void applyOverrideConfiguration (JsonConfiguration distributionConfiguration , JsonConfiguration overrideConfiguration ){
138+ private void applyOverrideConfiguration (JsonConfiguration distributionConfiguration , JsonConfiguration overrideConfiguration ) {
141139 for (String key : overrideConfiguration .getKeys (true )) {
142140 if ("language-version" .equals (key ) || "config-version" .equals (key ) || "version" .equals (key )) {
143141 continue ;
@@ -178,7 +176,7 @@ private JsonConfiguration getOverrideConfiguration(String overrideFile, String l
178176 * @return The text object
179177 */
180178 public Text of (@ NotNull String path , String ... args ) {
181- return new Text (this , (CommandSender ) null , locale2ContentMapping . get (CROWDIN_LANGUAGE_FILE ), bundledFile2ContentMapping . get (CROWDIN_LANGUAGE_FILE ), path , args );
179+ return new Text (this , (CommandSender ) null , mapper . getDistribution (CROWDIN_LANGUAGE_FILE ), mapper . getBundled (CROWDIN_LANGUAGE_FILE ), path , args );
182180 }
183181
184182 /**
@@ -190,7 +188,7 @@ public Text of(@NotNull String path, String... args) {
190188 * @return The text object
191189 */
192190 public Text of (@ Nullable CommandSender sender , @ NotNull String path , String ... args ) {
193- return new Text (this , sender , locale2ContentMapping . get (CROWDIN_LANGUAGE_FILE ), bundledFile2ContentMapping . get (CROWDIN_LANGUAGE_FILE ), path , args );
191+ return new Text (this , sender , mapper . getDistribution (CROWDIN_LANGUAGE_FILE ), mapper . getBundled (CROWDIN_LANGUAGE_FILE ), path , args );
194192 }
195193
196194 /**
@@ -202,7 +200,7 @@ public Text of(@Nullable CommandSender sender, @NotNull String path, String... a
202200 * @return The text object
203201 */
204202 public Text of (@ Nullable UUID sender , @ NotNull String path , String ... args ) {
205- return new Text (this , sender , locale2ContentMapping . get (CROWDIN_LANGUAGE_FILE ), bundledFile2ContentMapping . get (CROWDIN_LANGUAGE_FILE ), path , args );
203+ return new Text (this , sender , mapper . getDistribution (CROWDIN_LANGUAGE_FILE ), mapper . getBundled (CROWDIN_LANGUAGE_FILE ), path , args );
206204 }
207205
208206 /**
@@ -213,7 +211,7 @@ public Text of(@Nullable UUID sender, @NotNull String path, String... args) {
213211 * @return The text object
214212 */
215213 public TextList ofList (@ NotNull String path , String ... args ) {
216- return new TextList (this , (CommandSender ) null , locale2ContentMapping . get (CROWDIN_LANGUAGE_FILE ), bundledFile2ContentMapping . get (CROWDIN_LANGUAGE_FILE ), path , args );
214+ return new TextList (this , (CommandSender ) null , mapper . getDistribution (CROWDIN_LANGUAGE_FILE ), mapper . getBundled (CROWDIN_LANGUAGE_FILE ), path , args );
217215 }
218216
219217 /**
@@ -225,7 +223,7 @@ public TextList ofList(@NotNull String path, String... args) {
225223 * @return The text object
226224 */
227225 public TextList ofList (@ Nullable UUID sender , @ NotNull String path , String ... args ) {
228- return new TextList (this , sender , locale2ContentMapping . get (CROWDIN_LANGUAGE_FILE ), bundledFile2ContentMapping . get (CROWDIN_LANGUAGE_FILE ), path , args );
226+ return new TextList (this , sender , mapper . getDistribution (CROWDIN_LANGUAGE_FILE ), mapper . getBundled (CROWDIN_LANGUAGE_FILE ), path , args );
229227 }
230228
231229 /**
@@ -237,7 +235,7 @@ public TextList ofList(@Nullable UUID sender, @NotNull String path, String... ar
237235 * @return The text object
238236 */
239237 public TextList ofList (@ Nullable CommandSender sender , @ NotNull String path , String ... args ) {
240- return new TextList (this , sender , locale2ContentMapping . get (CROWDIN_LANGUAGE_FILE ), bundledFile2ContentMapping . get (CROWDIN_LANGUAGE_FILE ), path , args );
238+ return new TextList (this , sender , mapper . getDistribution (CROWDIN_LANGUAGE_FILE ), mapper . getBundled (CROWDIN_LANGUAGE_FILE ), path , args );
241239 }
242240
243241 public static class TextList {
0 commit comments