Fixes some code style issues, and attempts to fix test failures

This commit is contained in:
2024-02-20 18:54:04 +01:00
parent e57aa4097c
commit ee9bc21099
5 changed files with 137 additions and 60 deletions

View File

@@ -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
*