aboutsummaryrefslogtreecommitdiff
path: root/spark-bukkit
diff options
context:
space:
mode:
authorBen Kerllenevich <bkerllenevich@gmail.com>2022-06-28 14:57:36 -0400
committerGitHub <noreply@github.com>2022-06-28 19:57:36 +0100
commit7f422948755c2988180c32fda9554ea1531949c2 (patch)
tree027f332e680d44ec420d0ca5fd1ca1e558218f5d /spark-bukkit
parentd5d5cb10714b0993ec91d6a2b523b661c1314917 (diff)
downloadspark-7f422948755c2988180c32fda9554ea1531949c2.tar.gz
spark-7f422948755c2988180c32fda9554ea1531949c2.tar.bz2
spark-7f422948755c2988180c32fda9554ea1531949c2.zip
Better handling of Paper's split config system (#218)
Diffstat (limited to 'spark-bukkit')
-rw-r--r--spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitServerConfigProvider.java59
1 files changed, 48 insertions, 11 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 ff1b55f..bc1bdf8 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,6 +22,7 @@ package me.lucko.spark.bukkit;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Maps;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonSerializer;
@@ -29,6 +30,8 @@ import me.lucko.spark.common.platform.serverconfig.AbstractServerConfigProvider;
import me.lucko.spark.common.platform.serverconfig.ConfigParser;
import me.lucko.spark.common.platform.serverconfig.PropertiesConfigParser;
+import org.bukkit.Bukkit;
+import org.bukkit.World;
import org.bukkit.configuration.MemorySection;
import org.bukkit.configuration.file.YamlConfiguration;
@@ -36,6 +39,9 @@ import co.aikar.timings.TimingsManager;
import java.io.BufferedReader;
import java.io.IOException;
+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;
@@ -58,15 +64,8 @@ public class BukkitServerConfigProvider extends AbstractServerConfigProvider {
gson.registerTypeAdapter(MemorySection.class, (JsonSerializer<MemorySection>) (obj, type, ctx) -> ctx.serialize(obj.getValues(false)));
}
- @Override
- protected String rewriteConfigPath(String path) {
- return path.startsWith("config/")
- ? path.substring("config/".length())
- : path;
- }
-
- private enum YamlConfigParser implements ConfigParser {
- INSTANCE;
+ private static class YamlConfigParser implements ConfigParser {
+ public static final YamlConfigParser INSTANCE = new YamlConfigParser();
@Override
public Map<String, Object> parse(BufferedReader reader) throws IOException {
@@ -75,14 +74,52 @@ public class BukkitServerConfigProvider extends AbstractServerConfigProvider {
}
}
+ // Paper 1.19+ split config layout
+ private static class SplitYamlConfigParser extends YamlConfigParser {
+ public static final SplitYamlConfigParser INSTANCE = new SplitYamlConfigParser();
+
+ @Override
+ public Map<String, Object> parse(String prefix) throws IOException {
+ Path configDir = Paths.get("config");
+ if (!Files.exists(configDir)) {
+ return null;
+ }
+
+ Map<String, Object> configs = Maps.newHashMap();
+
+ parseIfExists(configs,
+ "global.yml",
+ configDir.resolve(prefix + "-global.yml")
+ );
+ parseIfExists(configs,
+ "world-defaults.yml",
+ configDir.resolve(prefix + "-world-defaults.yml")
+ );
+ for (World world : Bukkit.getWorlds()) {
+ parseIfExists(configs,
+ world.getName() + ".yml",
+ world.getWorldFolder().toPath().resolve(prefix + "-world.yml")
+ );
+ }
+
+ return configs;
+ }
+
+ private void parseIfExists(Map<String, Object> configs, String name, Path path) throws IOException {
+ Map<String, Object> values = parse(path);
+ if (values != null) {
+ configs.put(name, values);
+ }
+ }
+ }
+
static {
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("paper", SplitYamlConfigParser.INSTANCE)
.put("purpur.yml", YamlConfigParser.INSTANCE);
for (String config : getSystemPropertyList("spark.serverconfigs.extra")) {