aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitServerConfigProvider.java26
-rw-r--r--spark-common/src/main/java/me/lucko/spark/common/platform/serverconfig/PropertiesFileReader.java64
2 files changed, 68 insertions, 22 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 492e610..0ef662c 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
@@ -28,6 +28,7 @@ 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 org.bukkit.configuration.MemorySection;
import org.bukkit.configuration.file.YamlConfiguration;
@@ -43,10 +44,8 @@ import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.Properties;
public class BukkitServerConfigProvider extends AbstractServerConfigProvider<BukkitServerConfigProvider.FileType> {
private static final Gson GSON = new GsonBuilder()
@@ -73,26 +72,8 @@ public class BukkitServerConfigProvider extends AbstractServerConfigProvider<Buk
Map<String, Object> values;
if (type == FileType.PROPERTIES) {
- Properties properties = new Properties();
- properties.load(reader);
-
- values = new HashMap<>();
- properties.forEach((k, v) -> {
- String key = k.toString();
- String value = v.toString();
-
- if ("true".equals(value) || "false".equals(value)) {
- values.put(key, Boolean.parseBoolean(value));
- } else if (value.matches("\\d+")) {
- try {
- values.put(key, Long.parseLong(value));
- } catch (NumberFormatException e) {
- values.put(key, value);
- }
- } else {
- values.put(key, value);
- }
- });
+ PropertiesFileReader propertiesReader = new PropertiesFileReader(reader);
+ values = propertiesReader.readProperties();
} else if (type == FileType.YAML) {
YamlConfiguration config = YamlConfiguration.loadConfiguration(reader);
values = config.getValues(false);
@@ -129,6 +110,7 @@ public class BukkitServerConfigProvider extends AbstractServerConfigProvider<Buk
.add("motd")
.add("resource-pack")
.add("rcon<dot>password")
+ .add("level-seed")
.addAll(getTimingsHiddenConfigs())
.addAll(getSystemPropertyList("spark.serverconfigs.hiddenpaths"));
diff --git a/spark-common/src/main/java/me/lucko/spark/common/platform/serverconfig/PropertiesFileReader.java b/spark-common/src/main/java/me/lucko/spark/common/platform/serverconfig/PropertiesFileReader.java
new file mode 100644
index 0000000..8fc89d7
--- /dev/null
+++ b/spark-common/src/main/java/me/lucko/spark/common/platform/serverconfig/PropertiesFileReader.java
@@ -0,0 +1,64 @@
+/*
+ * This file is part of spark.
+ *
+ * Copyright (c) lucko (Luck) <luck@lucko.me>
+ * Copyright (c) contributors
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package me.lucko.spark.common.platform.serverconfig;
+
+import java.io.FilterReader;
+import java.io.IOException;
+import java.io.Reader;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+/**
+ * A {@link Reader} that can parse a .properties file.
+ */
+public class PropertiesFileReader extends FilterReader {
+
+ public PropertiesFileReader(Reader in) {
+ super(in);
+ }
+
+ public Map<String, Object> readProperties() throws IOException {
+ Properties properties = new Properties();
+ properties.load(this);
+
+ Map<String, Object> values = new HashMap<>();
+ properties.forEach((k, v) -> {
+ String key = k.toString();
+ String value = v.toString();
+
+ if ("true".equals(value) || "false".equals(value)) {
+ values.put(key, Boolean.parseBoolean(value));
+ } else if (value.matches("\\d+")) {
+ try {
+ values.put(key, Long.parseLong(value));
+ } catch (NumberFormatException e) {
+ values.put(key, value);
+ }
+ } else {
+ values.put(key, value);
+ }
+ });
+
+ return values;
+ }
+
+}