Skip to content

Commit

Permalink
Merge pull request #1531 from Dans-Plugins/locale-service-changes
Browse files Browse the repository at this point in the history
Locale Service Changes
  • Loading branch information
dmccoystephenson authored Oct 7, 2022
2 parents 24f2c35 + 0863c20 commit 8a48bcc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,14 @@ public class ConfigService {

public ConfigService(MedievalFactions medievalFactions) {
this.medievalFactions = medievalFactions;
if (!getConfig().isSet("languageid")) {
getConfig().set("languageid", "en-us");
}
localeService = new LocaleService(medievalFactions, this);
}

public void handleVersionMismatch() {
if (!getConfig().isString("version")) {
getConfig().set("version", medievalFactions.getVersion());
} else {
getConfig().set("version", medievalFactions.getVersion());
}
getConfig().set("version", medievalFactions.getVersion());

// add defaults if they don't exist
if (!getConfig().isInt("initialMaxPowerLevel")) {
Expand Down
26 changes: 15 additions & 11 deletions src/main/java/dansplugins/factionsystem/services/LocaleService.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ public void loadStrings() {
if (isFilePresent(localizationFilePath)) {
loadFromPluginFolder();
if (medievalFactions.isDebugEnabled()) {
System.out.println("medievalFactions.isDebugEnabled(): Loaded from plugin folder!");
System.out.println("[DEBUG] Loaded from plugin folder!");
}
} else {
loadFromResource();
if (medievalFactions.isDebugEnabled()) {
System.out.println("medievalFactions.isDebugEnabled(): Loaded from resource!");
System.out.println("[DEBUG] Loaded from resource!");
}
}
if (medievalFactions.isDebugEnabled()) {
Expand Down Expand Up @@ -106,7 +106,7 @@ private void loadFromPluginFolder() {

} catch (Exception e) {
if (medievalFactions.isDebugEnabled()) {
System.out.println("medievalFactions.isDebugEnabled(): Something went wrong loading from the plugin folder.");
System.out.println("[DEBUG] Something went wrong loading from the plugin folder.");
}
e.printStackTrace();
}
Expand All @@ -127,7 +127,7 @@ private void loadFromFile(File file) {

} catch (Exception e) {
if (medievalFactions.isDebugEnabled()) {
System.out.println("medievalFactions.isDebugEnabled(): Something went wrong loading from file!");
System.out.println("[DEBUG] Something went wrong loading from file!");
}
e.printStackTrace();
}
Expand All @@ -137,7 +137,7 @@ private void loadFromFile(File file) {
// this should be called after loading from plugin folder
private void updateCurrentLocalLanguageFile() {
if (medievalFactions.isDebugEnabled()) {
System.out.println("medievalFactions.isDebugEnabled(): LocaleManager is updating supported local language files.");
System.out.println("[DEBUG] LocaleManager is updating supported local language files.");
}
String ID = configService.getString("languageid");
if (isLanguageIDSupported(ID)) {
Expand All @@ -159,11 +159,15 @@ private void loadFromResource() {
try {
// get resource as input stream
InputStream inputStream = getResourceAsInputStream(localizationFileName);
if (inputStream == null) {
System.out.println("[DEBUG] localization file '" + localizationFileName + "'was not found!");
return;
}
loadMissingKeysFromInputStream(inputStream);
saveToPluginFolder();
} catch (Exception e) {
if (medievalFactions.isDebugEnabled()) {
System.out.println("medievalFactions.isDebugEnabled(): Error loading from resource!");
System.out.println("[DEBUG] Error loading from resource!");
}
e.printStackTrace();
}
Expand All @@ -177,7 +181,7 @@ private void loadMissingKeysFromInputStream(InputStream inputStream) {
if (pair != null && !strings.containsKey(pair.getLeft())) { // if pair found and if key not already loaded
strings.put(pair.getLeft(), pair.getRight());
keys.add(pair.getLeft());
// System.out.println(String.format("medievalFactions.isDebugEnabled(): Loaded missing key %s from resources!", pair.getLeft()));
System.out.println(String.format("[DEBUG] Loaded missing key %s from resources!", pair.getLeft()));
}
});
}
Expand Down Expand Up @@ -216,7 +220,7 @@ private void saveToPluginFolder() {
if (!folder.exists()) {
if (!folder.mkdir()) {
if (medievalFactions.isDebugEnabled()) {
System.out.println("medievalFactions.isDebugEnabled(): Failed to create directory.");
System.out.println("[DEBUG] Failed to create directory.");
}
return;
}
Expand All @@ -225,7 +229,7 @@ private void saveToPluginFolder() {
if (!file.exists()) {
if (!file.createNewFile()) {
if (medievalFactions.isDebugEnabled()) {
System.out.println("medievalFactions.isDebugEnabled(): Failed to create file.");
System.out.println("[DEBUG] Failed to create file.");
}
return;
}
Expand All @@ -237,12 +241,12 @@ private void saveToPluginFolder() {
}
} catch (Exception ex) {
if (medievalFactions.isDebugEnabled()) {
System.out.println("medievalFactions.isDebugEnabled(): Failed to write to file.");
System.out.println("[DEBUG] Failed to write to file.");
}
}
} catch (Exception e) {
if (medievalFactions.isDebugEnabled()) {
System.out.println("medievalFactions.isDebugEnabled(): There was a problem saving the strings.");
System.out.println("[DEBUG] There was a problem saving the strings.");
}
e.printStackTrace();
}
Expand Down

0 comments on commit 8a48bcc

Please sign in to comment.