Fixes some code style issues, and attempts to fix test failures
This commit is contained in:
@@ -11,9 +11,8 @@ import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.EnumMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* This class is responsible for loading all strings which are translated into several languages
|
||||
@@ -153,11 +152,14 @@ public final class LanguageLoader {
|
||||
|
||||
//If a key is not found in the language file, add the one in the internal file. Must update the external file
|
||||
if (!internalLanguageValues.keySet().equals(currentLanguageValues.keySet())) {
|
||||
Map<Message, String> newLanguageValues = new HashMap<>();
|
||||
Map<Message, String> newLanguageValues = new EnumMap<>(Message.class);
|
||||
boolean updateNecessary = false;
|
||||
for (Message key : internalLanguageValues.keySet()) {
|
||||
for (Map.Entry<Message, String> entry : internalLanguageValues.entrySet()) {
|
||||
Message key = entry.getKey();
|
||||
String value = entry.getValue();
|
||||
|
||||
if (currentLanguageValues.get(key) == null) {
|
||||
newLanguageValues.put(key, internalLanguageValues.get(key));
|
||||
newLanguageValues.put(key, value);
|
||||
//Found at least one value in the internal file not in the external file. Need to update
|
||||
updateNecessary = true;
|
||||
} else {
|
||||
@@ -186,15 +188,15 @@ public final class LanguageLoader {
|
||||
BufferedWriter bufferedWriter = FileHelper.getBufferedWriterFromString(languageFolder + language + ".txt");
|
||||
|
||||
//Output normal Language data
|
||||
for (Message key : languageStrings.keySet()) {
|
||||
bufferedWriter.write(key + "=" + languageStrings.get(key));
|
||||
for (Map.Entry<Message, String> entry : languageStrings.entrySet()) {
|
||||
bufferedWriter.write(entry.getKey() + "=" + entry.getValue());
|
||||
bufferedWriter.newLine();
|
||||
}
|
||||
bufferedWriter.newLine();
|
||||
//Output any custom language strings the user had
|
||||
if (customLanguageStrings != null) {
|
||||
for (Message key : customLanguageStrings.keySet()) {
|
||||
bufferedWriter.write(key + "=" + customLanguageStrings.get(key));
|
||||
for (Map.Entry<Message, String> entry : customLanguageStrings.entrySet()) {
|
||||
bufferedWriter.write(entry.getKey() + "=" + entry.getValue());
|
||||
bufferedWriter.newLine();
|
||||
}
|
||||
}
|
||||
@@ -240,25 +242,24 @@ public final class LanguageLoader {
|
||||
*/
|
||||
public void debug() {
|
||||
if (loadedStringTranslations != null) {
|
||||
Set<Message> keys = loadedStringTranslations.keySet();
|
||||
for (Message key : keys) {
|
||||
Stargate.debug("LanguageLoader::Debug::loadedStringTranslations", key + " => " +
|
||||
loadedStringTranslations.get(key));
|
||||
for (Map.Entry<Message, String> entry : loadedStringTranslations.entrySet()) {
|
||||
Stargate.debug("LanguageLoader::Debug::loadedStringTranslations", entry.getKey() +
|
||||
" => " + entry.getValue());
|
||||
}
|
||||
}
|
||||
if (loadedBackupStrings == null) {
|
||||
return;
|
||||
}
|
||||
Set<Message> keys = loadedBackupStrings.keySet();
|
||||
for (Message key : keys) {
|
||||
Stargate.debug("LanguageLoader::Debug::loadedBackupStrings", key + " => " +
|
||||
loadedBackupStrings.get(key));
|
||||
|
||||
for (Map.Entry<Message, String> entry : loadedBackupStrings.entrySet()) {
|
||||
Stargate.debug("LanguageLoader::Debug::loadedBackupStrings", entry.getKey() + " => " +
|
||||
entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Map<Message, String> fromStringMap(@NotNull Map<String, String> configurationStrings) {
|
||||
Map<Message, String> output = new HashMap<>();
|
||||
Map<Message, String> output = new EnumMap<>(Message.class);
|
||||
for (Map.Entry<String, String> entry : configurationStrings.entrySet()) {
|
||||
Message message = Message.getFromKey(entry.getKey());
|
||||
if (message == null) {
|
||||
|
@@ -30,6 +30,8 @@ import java.util.Queue;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* The stargate config is responsible for keeping track of all configuration values
|
||||
@@ -429,10 +431,14 @@ public final class StargateConfig {
|
||||
portalFolder = (String) configOptions.get(ConfigOption.PORTAL_FOLDER);
|
||||
if (portalFolder.isEmpty()) {
|
||||
portalFolder = dataFolderPath + "/portals/";
|
||||
} else {
|
||||
portalFolder = replacePluginFolderPath(portalFolder);
|
||||
}
|
||||
gateFolder = (String) configOptions.get(ConfigOption.GATE_FOLDER);
|
||||
if (gateFolder.isEmpty()) {
|
||||
gateFolder = dataFolderPath + "/gates/";
|
||||
} else {
|
||||
gateFolder = replacePluginFolderPath(gateFolder);
|
||||
}
|
||||
|
||||
//If users have an outdated config, assume they also need to update their default gates
|
||||
@@ -450,6 +456,23 @@ public final class StargateConfig {
|
||||
Stargate.getInstance().saveConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces "plugins/Stargate" in a folder path, and replaces it with the full path relative to the data folder
|
||||
*
|
||||
* @param input <p>The input string to replace in</p>
|
||||
* @return <p>The replaced path, or the input if not applicable</p>
|
||||
*/
|
||||
@NotNull
|
||||
private String replacePluginFolderPath(@NotNull String input) {
|
||||
Pattern pattern = Pattern.compile("(?i)^plugins/Stargate");
|
||||
Matcher matcher = pattern.matcher(input);
|
||||
if (matcher.matches()) {
|
||||
return dataFolderPath + matcher.replaceAll("");
|
||||
} else {
|
||||
return input;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the object containing configuration values regarding gates
|
||||
*
|
||||
|
Reference in New Issue
Block a user