11package org .maxgamer .quickshop .util .language .text ;
22
33import com .dumptruckman .bukkit .configuration .json .JsonConfiguration ;
4+ import lombok .SneakyThrows ;
45import org .apache .commons .io .IOUtils ;
56import org .bukkit .Bukkit ;
67import org .bukkit .command .CommandSender ;
@@ -49,15 +50,19 @@ public TextManager(QuickShop plugin) {
4950 /**
5051 * Generate the override files storage path
5152 *
52- * @param crowdinPath The crowdin file path
53+ * @param path The distribution file path
5354 * @return Override files storage path
5455 */
56+ @ SneakyThrows
5557 @ NotNull
56- private File getOverrideFilesFolder (@ NotNull String crowdinPath ) {
57- File file = new File (crowdinPath );
58- File folder = new File (new File (plugin .getDataFolder (), "overrides" ), file .getName () + ".overrides" );
59- folder .mkdirs ();
60- return folder ;
58+ private File getOverrideFilesFolder (@ NotNull String path ) {
59+ File file = new File (path );
60+ String module = file .getParentFile ().getName ();
61+ File moduleFolder = new File (new File (plugin .getDataFolder (), "overrides" ), module );
62+ moduleFolder .mkdirs ();
63+ File fileFolder = new File (moduleFolder ,file .getName ());
64+ fileFolder .mkdirs ();
65+ return file ;
6166 }
6267
6368 /**
@@ -78,7 +83,7 @@ private JsonConfiguration loadBundled(String file) {
7883 JsonConfiguration bundledLang = new JsonConfiguration ();
7984 try {
8085 File fileObject = new File (file );
81- bundledLang .loadFromString (new String (IOUtils .toByteArray (new InputStreamReader (plugin .getResource ("lang-original /" + fileObject .getName ())), StandardCharsets .UTF_8 )));
86+ bundledLang .loadFromString (new String (IOUtils .toByteArray (new InputStreamReader (plugin .getResource ("lang/" + fileObject .getName ())), StandardCharsets .UTF_8 )));
8287 } catch (IOException | InvalidConfigurationException ex ) {
8388 bundledLang = new JsonConfiguration ();
8489 plugin .getLogger ().log (Level .SEVERE , "Cannot load bundled language file from Jar, some strings may missing!" , ex );
@@ -127,7 +132,13 @@ public void load() {
127132 postProcessors .add (new ColorProcessor ());
128133 }
129134
130- private boolean localeEnabled (String locale , List <String > regex ){
135+ /**
136+ * Gets specific locale status
137+ * @param locale The locale
138+ * @param regex The regexes
139+ * @return The locale enabled status
140+ */
141+ private boolean localeEnabled (@ NotNull String locale , @ NotNull List <String > regex ){
131142 for (String languagesRegex : regex ) {
132143 try {
133144 if (locale .matches (languagesRegex )) {
@@ -140,7 +151,12 @@ private boolean localeEnabled(String locale, List<String> regex){
140151 return false ;
141152 }
142153
143- private void applyOverrideConfiguration (JsonConfiguration distributionConfiguration , JsonConfiguration overrideConfiguration ) {
154+ /**
155+ * Merge override data into distribution configuration to override texts
156+ * @param distributionConfiguration The configuration that from distribution (will override it)
157+ * @param overrideConfiguration The configuration that from local
158+ */
159+ private void applyOverrideConfiguration (@ NotNull JsonConfiguration distributionConfiguration , @ NotNull JsonConfiguration overrideConfiguration ) {
144160 for (String key : overrideConfiguration .getKeys (true )) {
145161 if ("language-version" .equals (key ) || "config-version" .equals (key ) || "version" .equals (key )) {
146162 continue ;
@@ -149,7 +165,14 @@ private void applyOverrideConfiguration(JsonConfiguration distributionConfigurat
149165 }
150166 }
151167
152- private JsonConfiguration getDistributionConfiguration (String distributionFile , String distributionCode ) throws Exception {
168+ /**
169+ * Getting configuration from distribution platform
170+ * @param distributionFile Distribution path
171+ * @param distributionCode Locale code on distribution platform
172+ * @return The configuration
173+ * @throws Exception Any errors when getting it
174+ */
175+ private JsonConfiguration getDistributionConfiguration (@ NotNull String distributionFile , @ NotNull String distributionCode ) throws Exception {
153176 JsonConfiguration configuration = new JsonConfiguration ();
154177 try {
155178 // Load the locale file from local cache if available
@@ -162,7 +185,15 @@ private JsonConfiguration getDistributionConfiguration(String distributionFile,
162185 return configuration ;
163186 }
164187
165- private JsonConfiguration getOverrideConfiguration (String overrideFile , String locale ) throws IOException , InvalidConfigurationException {
188+ /**
189+ * Getting user's override configuration for specific distribution path
190+ * @param overrideFile The distribution
191+ * @param locale the locale
192+ * @return The override configuration
193+ * @throws IOException IOException
194+ * @throws InvalidConfigurationException File invalid
195+ */
196+ private JsonConfiguration getOverrideConfiguration (@ NotNull String overrideFile , @ NotNull String locale ) throws IOException , InvalidConfigurationException {
166197 File localOverrideFile = new File (getOverrideFilesFolder (overrideFile ), locale + ".json" );
167198 if (!localOverrideFile .exists ()) {
168199 localOverrideFile .getParentFile ().mkdirs ();
0 commit comments