@@ -49,16 +49,16 @@ private File getOverrideFilesFolder(@NotNull String crowdinPath) {
4949 return folder ;
5050 }
5151
52- private void reset (){
52+ private void reset () {
5353 locale2ContentMapping .clear ();
5454 postProcessors .clear ();
5555 }
5656
57- private JsonConfiguration loadBundled (String file ){
57+ private JsonConfiguration loadBundled (String file ) {
5858 JsonConfiguration bundledLang = new JsonConfiguration ();
5959 try {
6060 File fileObject = new File (file );
61- bundledLang .loadFromString (new String (IOUtils .toByteArray (new InputStreamReader (plugin .getResource ("lang-original/" +fileObject .getName ())), StandardCharsets .UTF_8 )));
61+ bundledLang .loadFromString (new String (IOUtils .toByteArray (new InputStreamReader (plugin .getResource ("lang-original/" + fileObject .getName ())), StandardCharsets .UTF_8 )));
6262 } catch (IOException | InvalidConfigurationException ex ) {
6363 bundledLang = new JsonConfiguration ();
6464 plugin .getLogger ().log (Level .SEVERE , "Cannot load bundled language file from Jar, some strings may missing!" , ex );
@@ -72,10 +72,10 @@ public void load() {
7272
7373 // Initial file mapping
7474 locale2ContentMapping .computeIfAbsent (languageFileCrowdin , e -> new HashMap <>()); // Prevent nullportinter exception
75- distribution .getAvailableFiles ().forEach (file -> locale2ContentMapping .computeIfAbsent (file , e -> new HashMap <>()));
75+ distribution .getAvailableFiles ().forEach (file -> locale2ContentMapping .computeIfAbsent (file , e -> new HashMap <>()));
7676
7777 // Read bundled language files
78- distribution .getAvailableFiles ().forEach (crowdinFile -> this .bundledFile2ContentMapping .computeIfAbsent (crowdinFile , e -> loadBundled (crowdinFile )));
78+ distribution .getAvailableFiles ().forEach (crowdinFile -> this .bundledFile2ContentMapping .computeIfAbsent (crowdinFile , e -> loadBundled (crowdinFile )));
7979
8080 // Multi File and Multi-Language loader
8181 distribution .getAvailableLanguages ().parallelStream ().forEach (crowdinCode -> distribution .getAvailableFiles ().parallelStream ().forEach (crowdinFile -> {
@@ -106,7 +106,7 @@ public void load() {
106106 configuration .set (key , override .get (key ));
107107 }
108108 locale2ContentMapping .get (languageFileCrowdin ).computeIfAbsent (minecraftCode , e -> configuration );
109- Util .debugLog ("Locale " + crowdinFile +" has been successfully loaded" );
109+ Util .debugLog ("Locale " + crowdinFile + " has been successfully loaded" );
110110 } catch (CrowdinOTA .OTAException e ) {
111111 plugin .getLogger ().warning ("Couldn't update the translation for locale " + crowdinCode + " because it not configured, please report to QuickShop" );
112112 } catch (IOException e ) {
@@ -122,28 +122,74 @@ public void load() {
122122 postProcessors .add (new PlaceHolderApiProcessor ());
123123 }
124124
125+ /**
126+ * Getting the translation with path with default locale
127+ *
128+ * @param path THe path
129+ * @param args The arguments
130+ * @return The text object
131+ */
125132 public Text of (@ NotNull String path , String ... args ) {
126- return new Text (this , (CommandSender ) null , locale2ContentMapping .get (languageFileCrowdin ),bundledFile2ContentMapping .get (languageFileCrowdin ), path , args );
133+ return new Text (this , (CommandSender ) null , locale2ContentMapping .get (languageFileCrowdin ), bundledFile2ContentMapping .get (languageFileCrowdin ), path , args );
127134 }
128135
136+ /**
137+ * Getting the translation with path with player's locale (if available)
138+ *
139+ * @param sender The sender
140+ * @param path The path
141+ * @param args The arguments
142+ * @return The text object
143+ */
129144 public Text of (@ Nullable CommandSender sender , @ NotNull String path , String ... args ) {
130- return new Text (this , sender , locale2ContentMapping .get (languageFileCrowdin ),bundledFile2ContentMapping .get (languageFileCrowdin ), path , args );
145+ return new Text (this , sender , locale2ContentMapping .get (languageFileCrowdin ), bundledFile2ContentMapping .get (languageFileCrowdin ), path , args );
131146 }
132147
148+ /**
149+ * Getting the translation with path with player's locale (if available)
150+ *
151+ * @param sender The player unique id
152+ * @param path The path
153+ * @param args The arguments
154+ * @return The text object
155+ */
133156 public Text of (@ Nullable UUID sender , @ NotNull String path , String ... args ) {
134- return new Text (this , sender , locale2ContentMapping .get (languageFileCrowdin ),bundledFile2ContentMapping .get (languageFileCrowdin ), path , args );
157+ return new Text (this , sender , locale2ContentMapping .get (languageFileCrowdin ), bundledFile2ContentMapping .get (languageFileCrowdin ), path , args );
135158 }
136159
160+ /**
161+ * Getting the translation with path with default locale (if available)
162+ *
163+ * @param path The path
164+ * @param args The arguments
165+ * @return The text object
166+ */
137167 public TextList ofList (@ NotNull String path , String ... args ) {
138- return new TextList (this , (CommandSender ) null , locale2ContentMapping .get (languageFileCrowdin ),bundledFile2ContentMapping .get (languageFileCrowdin ), path , args );
168+ return new TextList (this , (CommandSender ) null , locale2ContentMapping .get (languageFileCrowdin ), bundledFile2ContentMapping .get (languageFileCrowdin ), path , args );
139169 }
140170
171+ /**
172+ * Getting the translation with path with player's locale (if available)
173+ *
174+ * @param sender The player unique id
175+ * @param path The path
176+ * @param args The arguments
177+ * @return The text object
178+ */
141179 public TextList ofList (@ Nullable UUID sender , @ NotNull String path , String ... args ) {
142- return new TextList (this , sender , locale2ContentMapping .get (languageFileCrowdin ),bundledFile2ContentMapping .get (languageFileCrowdin ), path , args );
180+ return new TextList (this , sender , locale2ContentMapping .get (languageFileCrowdin ), bundledFile2ContentMapping .get (languageFileCrowdin ), path , args );
143181 }
144182
183+ /**
184+ * Getting the translation with path with player's locale (if available)
185+ *
186+ * @param sender The player
187+ * @param path The path
188+ * @param args The arguments
189+ * @return The text object
190+ */
145191 public TextList ofList (@ Nullable CommandSender sender , @ NotNull String path , String ... args ) {
146- return new TextList (this , sender , locale2ContentMapping .get (languageFileCrowdin ),bundledFile2ContentMapping .get (languageFileCrowdin ), path , args );
192+ return new TextList (this , sender , locale2ContentMapping .get (languageFileCrowdin ), bundledFile2ContentMapping .get (languageFileCrowdin ), path , args );
147193 }
148194
149195 public static class TextList {
@@ -178,10 +224,21 @@ private TextList(TextManager manager, UUID sender, Map<String, JsonConfiguration
178224 this .args = args ;
179225 }
180226
227+ /**
228+ * Getting the bundled fallback text
229+ *
230+ * @return The bundled text
231+ */
181232 private @ NotNull List <String > fallbackLocal () {
182233 return this .bundled .getStringList (path );
183234 }
184235
236+ /**
237+ * Post processes the text
238+ *
239+ * @param text The text
240+ * @return The text that processed
241+ */
185242 @ NotNull
186243 private List <String > postProcess (@ NotNull List <String > text ) {
187244 List <String > texts = new ArrayList <>();
@@ -192,6 +249,12 @@ private List<String> postProcess(@NotNull List<String> text) {
192249 return texts ;
193250 }
194251
252+ /**
253+ * Getting the text that use specify locale
254+ *
255+ * @param locale The minecraft locale code (like en_us)
256+ * @return The text
257+ */
195258 @ NotNull
196259 public List <String > forLocale (@ NotNull String locale ) {
197260 JsonConfiguration index = mapping .get (locale );
@@ -215,6 +278,11 @@ public List<String> forLocale(@NotNull String locale) {
215278
216279 }
217280
281+ /**
282+ * Getting the text for player locale
283+ *
284+ * @return Getting the text for player locale
285+ */
218286 @ NotNull
219287 public List <String > forLocale () {
220288 if (sender instanceof Player ) {
@@ -224,6 +292,9 @@ public List<String> forLocale() {
224292 }
225293 }
226294
295+ /**
296+ * Send text to the player
297+ */
227298 public void send () {
228299 if (sender == null )
229300 return ;
@@ -265,18 +336,35 @@ private Text(TextManager manager, UUID sender, Map<String, JsonConfiguration> ma
265336 this .args = args ;
266337 }
267338
339+ /**
340+ * Getting the bundled fallback text
341+ *
342+ * @return The bundled text
343+ */
268344 @ Nullable
269345 private String fallbackLocal () {
270346 return this .bundled .getString (path );
271347 }
272348
349+ /**
350+ * Post processes the text
351+ *
352+ * @param text The text
353+ * @return The text that processed
354+ */
273355 @ NotNull
274356 private String postProcess (@ NotNull String text ) {
275357 for (PostProcessor postProcessor : this .manager .postProcessors )
276358 text = postProcessor .process (text , sender , args );
277359 return text ;
278360 }
279361
362+ /**
363+ * Getting the text that use specify locale
364+ *
365+ * @param locale The minecraft locale code (like en_us)
366+ * @return The text
367+ */
280368 @ NotNull
281369 public String forLocale (@ NotNull String locale ) {
282370 JsonConfiguration index = mapping .get (locale );
@@ -297,6 +385,11 @@ public String forLocale(@NotNull String locale) {
297385 }
298386 }
299387
388+ /**
389+ * Getting the text for player locale
390+ *
391+ * @return Getting the text for player locale
392+ */
300393 @ NotNull
301394 public String forLocale () {
302395 if (sender instanceof Player ) {
@@ -306,6 +399,9 @@ public String forLocale() {
306399 }
307400 }
308401
402+ /**
403+ * Send text to the player
404+ */
309405 public void send () {
310406 if (sender == null )
311407 return ;
0 commit comments