aboutsummaryrefslogtreecommitdiff
path: root/spark-bukkit/src
diff options
context:
space:
mode:
Diffstat (limited to 'spark-bukkit/src')
-rw-r--r--spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitServerConfigProvider.java70
1 files changed, 29 insertions, 41 deletions
diff --git a/spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitServerConfigProvider.java b/spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitServerConfigProvider.java
index 953e171..ff1b55f 100644
--- a/spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitServerConfigProvider.java
+++ b/spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitServerConfigProvider.java
@@ -22,13 +22,12 @@ package me.lucko.spark.bukkit;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
-import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
-import com.google.gson.JsonElement;
import com.google.gson.JsonSerializer;
import me.lucko.spark.common.platform.serverconfig.AbstractServerConfigProvider;
-import me.lucko.spark.common.platform.serverconfig.PropertiesFileReader;
+import me.lucko.spark.common.platform.serverconfig.ConfigParser;
+import me.lucko.spark.common.platform.serverconfig.PropertiesConfigParser;
import org.bukkit.configuration.MemorySection;
import org.bukkit.configuration.file.YamlConfiguration;
@@ -37,23 +36,16 @@ import co.aikar.timings.TimingsManager;
import java.io.BufferedReader;
import java.io.IOException;
-import java.nio.charset.StandardCharsets;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
-public class BukkitServerConfigProvider extends AbstractServerConfigProvider<BukkitServerConfigProvider.FileType> {
- private static final Gson GSON = new GsonBuilder()
- .registerTypeAdapter(MemorySection.class, (JsonSerializer<MemorySection>) (obj, type, ctx) -> ctx.serialize(obj.getValues(false)))
- .create();
+public class BukkitServerConfigProvider extends AbstractServerConfigProvider {
/** A map of provided files and their type */
- private static final Map<String, FileType> FILES;
+ private static final Map<String, ConfigParser> FILES;
/** A collection of paths to be excluded from the files */
private static final Collection<String> HIDDEN_PATHS;
@@ -62,50 +54,46 @@ public class BukkitServerConfigProvider extends AbstractServerConfigProvider<Buk
}
@Override
- protected JsonElement load(String path, FileType type) throws IOException {
- Path filePath = Paths.get(path);
- if (!Files.exists(filePath)) {
- return null;
- }
+ protected void customiseGson(GsonBuilder gson) {
+ gson.registerTypeAdapter(MemorySection.class, (JsonSerializer<MemorySection>) (obj, type, ctx) -> ctx.serialize(obj.getValues(false)));
+ }
- try (BufferedReader reader = Files.newBufferedReader(filePath, StandardCharsets.UTF_8)) {
- Map<String, Object> values;
+ @Override
+ protected String rewriteConfigPath(String path) {
+ return path.startsWith("config/")
+ ? path.substring("config/".length())
+ : path;
+ }
- if (type == FileType.PROPERTIES) {
- PropertiesFileReader propertiesReader = new PropertiesFileReader(reader);
- values = propertiesReader.readProperties();
- } else if (type == FileType.YAML) {
- YamlConfiguration config = YamlConfiguration.loadConfiguration(reader);
- values = config.getValues(false);
- } else {
- throw new IllegalArgumentException("Unknown file type: " + type);
- }
+ private enum YamlConfigParser implements ConfigParser {
+ INSTANCE;
- return GSON.toJsonTree(values);
+ @Override
+ public Map<String, Object> parse(BufferedReader reader) throws IOException {
+ YamlConfiguration config = YamlConfiguration.loadConfiguration(reader);
+ return config.getValues(false);
}
}
- enum FileType {
- PROPERTIES,
- YAML
- }
-
static {
- ImmutableMap.Builder<String, FileType> files = ImmutableMap.<String, FileType>builder()
- .put("server.properties", FileType.PROPERTIES)
- .put("bukkit.yml", FileType.YAML)
- .put("spigot.yml", FileType.YAML)
- .put("paper.yml", FileType.YAML)
- .put("purpur.yml", FileType.YAML);
+ ImmutableMap.Builder<String, ConfigParser> files = ImmutableMap.<String, ConfigParser>builder()
+ .put("server.properties", PropertiesConfigParser.INSTANCE)
+ .put("bukkit.yml", YamlConfigParser.INSTANCE)
+ .put("spigot.yml", YamlConfigParser.INSTANCE)
+ .put("paper.yml", YamlConfigParser.INSTANCE)
+ .put("config/paper-global.yml", YamlConfigParser.INSTANCE)
+ .put("config/paper-world-defaults.yml", YamlConfigParser.INSTANCE)
+ .put("purpur.yml", YamlConfigParser.INSTANCE);
for (String config : getSystemPropertyList("spark.serverconfigs.extra")) {
- files.put(config, FileType.YAML);
+ files.put(config, YamlConfigParser.INSTANCE);
}
ImmutableSet.Builder<String> hiddenPaths = ImmutableSet.<String>builder()
.add("database")
.add("settings.bungeecord-addresses")
.add("settings.velocity-support.secret")
+ .add("proxies.velocity.secret")
.add("server-ip")
.add("motd")
.add("resource-pack")