Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Locale Service Changes #1531

Merged
merged 1 commit into from
Oct 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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