9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2026-01-06 15:51:31 +00:00

Update Leaf config

This commit is contained in:
Dreeam
2023-03-03 13:58:13 -05:00
parent 11b99487e2
commit a24cd1ceaf
19 changed files with 72 additions and 55 deletions

View File

@@ -64,12 +64,13 @@ index 1141b3a88e2eb1baa705b4f781353df0305a7c85..b104a38d2c879b649a3862876c389564
this.setFlightAllowed(dedicatedserverproperties.allowFlight);
diff --git a/src/main/java/org/dreeam/leaf/LeafConfig.java b/src/main/java/org/dreeam/leaf/LeafConfig.java
new file mode 100644
index 0000000000000000000000000000000000000000..309391c1da5ed895e9bf16361ec78944801a22d3
index 0000000000000000000000000000000000000000..511bc2175c4f25723bfdf59ae0ecb20e6fff1956
--- /dev/null
+++ b/src/main/java/org/dreeam/leaf/LeafConfig.java
@@ -0,0 +1,139 @@
@@ -0,0 +1,167 @@
+package org.dreeam.leaf;
+
+import com.google.common.collect.ImmutableMap;
+import net.minecraft.server.MinecraftServer;
+import org.bukkit.configuration.ConfigurationSection;
+import org.bukkit.configuration.MemoryConfiguration;
@@ -83,6 +84,7 @@ index 0000000000000000000000000000000000000000..309391c1da5ed895e9bf16361ec78944
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.List;
+import java.util.Map;
+
+public class LeafConfig {
+
@@ -157,6 +159,11 @@ index 0000000000000000000000000000000000000000..309391c1da5ed895e9bf16361ec78944
+ }
+ }
+
+ private static void set(String key, Object defaultValue) {
+ config.addDefault(key, defaultValue);
+ config.set(key, defaultValue);
+ }
+
+ private static boolean getBoolean(String key, boolean defaultValue, String... comment) {
+ return getBoolean(key, null, defaultValue, comment);
+ }
@@ -202,6 +209,27 @@ index 0000000000000000000000000000000000000000..309391c1da5ed895e9bf16361ec78944
+ return config.getStringList(key);
+ }
+
+ static Map<String, Object> getMap(String key, Map<String, Object> defaultValue) {
+ if (defaultValue != null && config.getConfigurationSection(key) == null) {
+ config.addDefault(key, defaultValue);
+ return defaultValue;
+ }
+ return toMap(convertToBukkit(config.getConfigurationSection(key)));
+ }
+
+ private static Map<String, Object> toMap(ConfigurationSection section) {
+ ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder();
+ if (section != null) {
+ for (String key : section.getKeys(false)) {
+ Object obj = section.get(key);
+ if (obj != null) {
+ builder.put(key, obj instanceof ConfigurationSection val ? toMap(val) : obj);
+ }
+ }
+ }
+ return builder.build();
+ }
+
+ public static String serverModName = "Leaf";
+ private static void serverModName() {
+ serverModName = getString("server-mod-name", serverModName);