diff options
author | Ben Kerllenevich <bkerllenevich@gmail.com> | 2022-06-28 14:57:36 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-28 19:57:36 +0100 |
commit | 7f422948755c2988180c32fda9554ea1531949c2 (patch) | |
tree | 027f332e680d44ec420d0ca5fd1ca1e558218f5d /spark-common | |
parent | d5d5cb10714b0993ec91d6a2b523b661c1314917 (diff) | |
download | spark-7f422948755c2988180c32fda9554ea1531949c2.tar.gz spark-7f422948755c2988180c32fda9554ea1531949c2.tar.bz2 spark-7f422948755c2988180c32fda9554ea1531949c2.zip |
Better handling of Paper's split config system (#218)
Diffstat (limited to 'spark-common')
2 files changed, 23 insertions, 14 deletions
diff --git a/spark-common/src/main/java/me/lucko/spark/common/platform/serverconfig/AbstractServerConfigProvider.java b/spark-common/src/main/java/me/lucko/spark/common/platform/serverconfig/AbstractServerConfigProvider.java index 0eef111..5a14382 100644 --- a/spark-common/src/main/java/me/lucko/spark/common/platform/serverconfig/AbstractServerConfigProvider.java +++ b/spark-common/src/main/java/me/lucko/spark/common/platform/serverconfig/AbstractServerConfigProvider.java @@ -73,9 +73,7 @@ public abstract class AbstractServerConfigProvider implements ServerConfigProvid } delete(json, this.hiddenPaths); - - String name = rewriteConfigPath(path); - builder.put(name, json); + builder.put(path, json); } catch (Exception e) { e.printStackTrace(); } @@ -85,25 +83,18 @@ public abstract class AbstractServerConfigProvider implements ServerConfigProvid } private JsonElement load(String path, ConfigParser parser) throws IOException { - Path filePath = Paths.get(path); - if (!Files.exists(filePath)) { + Map<String, Object> values = parser.parse(path); + if (values == null) { return null; } - try (BufferedReader reader = Files.newBufferedReader(filePath, StandardCharsets.UTF_8)) { - Map<String, Object> values = parser.parse(reader); - return this.gson.toJsonTree(values); - } + return this.gson.toJsonTree(values); } protected void customiseGson(GsonBuilder gson) { } - protected String rewriteConfigPath(String path) { - return path; - } - /** * Deletes the given paths from the json element. * diff --git a/spark-common/src/main/java/me/lucko/spark/common/platform/serverconfig/ConfigParser.java b/spark-common/src/main/java/me/lucko/spark/common/platform/serverconfig/ConfigParser.java index 2dd15fe..dfbf816 100644 --- a/spark-common/src/main/java/me/lucko/spark/common/platform/serverconfig/ConfigParser.java +++ b/spark-common/src/main/java/me/lucko/spark/common/platform/serverconfig/ConfigParser.java @@ -22,10 +22,28 @@ package me.lucko.spark.common.platform.serverconfig; 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.Map; public interface ConfigParser { - Map<String, Object> parse(BufferedReader reader) throws IOException; + default Map<String, Object> parse(String file) throws IOException { + return parse(Paths.get(file)); + } + + default Map<String, Object> parse(Path file) throws IOException { + if (!Files.exists(file)) { + return null; + } + + try (BufferedReader reader = Files.newBufferedReader(file, StandardCharsets.UTF_8)) { + return this.parse(reader); + } + } + + Map<String, Object> parse(BufferedReader reader) throws IOException; } |