Upstream has released updates that appears to apply and compile correctly Paper Changes: 26fb7cc35 Fix Chunk Post Processing deadlock risk ffecc4e26 Revert "Optimize entity list iteration requiring entities be in" 0a4286cc4 Prevent Fire from loading chunks 07915ea18 Add Player Client Options API (#2883) bc48a3172 Optimize entity list iteration requiring entities be in loaded chunks 88092fef1 Optimize ChunkProviderServer's chunk level checking helper methods 01e8ce8d2 Forced Watchdog Crash support and Improve Async Shutdown fdb8fe780 Be less strict with vanilla teleport command limits 0f06d3806 Restrict vanilla teleport command to within worldborder 24d93aafa Fix Optional null issue - Fixes #3155 eb71c5fa3 Fix incorect timing of mspt 1ca804342 Optimise entity hard collision checking b67a42376 Don't run entity collision code if not needed bd9aa547d Optimise ArraySetSorted#removeIf
284 lines
12 KiB
Diff
284 lines
12 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: =?UTF-8?q?=E3=84=97=E3=84=A0=CB=8B=20=E3=84=91=E3=84=A7=CB=8A?=
|
|
<tsao-chi@the-lingo.org>
|
|
Date: Fri, 3 Apr 2020 14:59:22 +0800
|
|
Subject: [PATCH] Akarin configuration
|
|
|
|
|
|
diff --git a/src/main/java/io/akarin/server/Config.java b/src/main/java/io/akarin/server/Config.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..2ac8f02a97429f04f3e5c9206ec228edccaf24c9
|
|
--- /dev/null
|
|
+++ b/src/main/java/io/akarin/server/Config.java
|
|
@@ -0,0 +1,183 @@
|
|
+package io.akarin.server;
|
|
+
|
|
+import org.bukkit.Bukkit;
|
|
+import org.bukkit.configuration.ConfigurationSection;
|
|
+import org.bukkit.configuration.file.YamlConfiguration;
|
|
+
|
|
+import java.io.File;
|
|
+import java.lang.reflect.Method;
|
|
+import java.lang.reflect.Modifier;
|
|
+import java.util.List;
|
|
+import java.util.logging.Level;
|
|
+
|
|
+public final class Config {
|
|
+
|
|
+ public static final String CONFIG_HEADER = "Configuration file for Akarin.";
|
|
+ public static final int CURRENT_CONFIG_VERSION = 1;
|
|
+
|
|
+ private static final Object[] EMPTY = new Object[0];
|
|
+
|
|
+ private static File configFile;
|
|
+ public static YamlConfiguration config;
|
|
+ private static int configVersion;
|
|
+
|
|
+ public static void init(final File file) {
|
|
+ Config.configFile = file;
|
|
+ final YamlConfiguration config = new YamlConfiguration();
|
|
+ config.options().header(CONFIG_HEADER);
|
|
+ config.options().copyDefaults(true);
|
|
+
|
|
+ if (!file.exists()) {
|
|
+ try {
|
|
+ file.createNewFile();
|
|
+ } catch (final Exception ex) {
|
|
+ Bukkit.getLogger().log(Level.SEVERE, "Failure to create Akarin config", ex);
|
|
+ }
|
|
+ } else {
|
|
+ try {
|
|
+ config.load(file);
|
|
+ } catch (final Exception ex) {
|
|
+ Bukkit.getLogger().log(Level.SEVERE, "Failure to load Akarin config", ex);
|
|
+ throw new RuntimeException(ex);
|
|
+ }
|
|
+ }
|
|
+
|
|
+ Config.load(config);
|
|
+ }
|
|
+
|
|
+ public static void load(final YamlConfiguration config) {
|
|
+ Config.config = config;
|
|
+ Config.configVersion = Config.getInt("config-version-please-do-not-modify-me", CURRENT_CONFIG_VERSION);
|
|
+ Config.set("config-version-please-do-not-modify-me", CURRENT_CONFIG_VERSION);
|
|
+
|
|
+ for (final Method method : Config.class.getDeclaredMethods()) {
|
|
+ if (method.getReturnType() != void.class || method.getParameterCount() != 0 ||
|
|
+ !Modifier.isPrivate(method.getModifiers()) || !Modifier.isStatic(method.getModifiers())) {
|
|
+ continue;
|
|
+ }
|
|
+
|
|
+ try {
|
|
+ method.setAccessible(true);
|
|
+ method.invoke(null, EMPTY);
|
|
+ } catch (final Exception ex) {
|
|
+ throw new RuntimeException(ex);
|
|
+ }
|
|
+ }
|
|
+
|
|
+ /* We re-save to add new options */
|
|
+ try {
|
|
+ config.save(Config.configFile);
|
|
+ } catch (final Exception ex) {
|
|
+ Bukkit.getLogger().log(Level.SEVERE, "Unable to save Akarin config", ex);
|
|
+ }
|
|
+ }
|
|
+
|
|
+ static void set(final String path, final Object value) {
|
|
+ Config.config.set(path, value);
|
|
+ }
|
|
+
|
|
+ static boolean getBoolean(final String path, final boolean dfl) {
|
|
+ Config.config.addDefault(path, Boolean.valueOf(dfl));
|
|
+ return Config.config.getBoolean(path, dfl);
|
|
+ }
|
|
+
|
|
+ static int getInt(final String path, final int dfl) {
|
|
+ Config.config.addDefault(path, Integer.valueOf(dfl));
|
|
+ return Config.config.getInt(path, dfl);
|
|
+ }
|
|
+
|
|
+ static long getLong(final String path, final long dfl) {
|
|
+ Config.config.addDefault(path, Long.valueOf(dfl));
|
|
+ return Config.config.getLong(path, dfl);
|
|
+ }
|
|
+
|
|
+ static double getDouble(final String path, final double dfl) {
|
|
+ Config.config.addDefault(path, Double.valueOf(dfl));
|
|
+ return Config.config.getDouble(path, dfl);
|
|
+ }
|
|
+
|
|
+ public static final class WorldConfig {
|
|
+
|
|
+ public final String worldName;
|
|
+ public ConfigurationSection config;
|
|
+ ConfigurationSection worldDefaults;
|
|
+
|
|
+ public WorldConfig(final String worldName) {
|
|
+ this.worldName = worldName;
|
|
+ this.init();
|
|
+ }
|
|
+
|
|
+ public void init() {
|
|
+ this.worldDefaults = Config.config.getConfigurationSection("world-settings.default");
|
|
+ if (this.worldDefaults == null) {
|
|
+ this.worldDefaults = Config.config.createSection("world-settings.default");
|
|
+ }
|
|
+
|
|
+ String worldSectionPath = "world-settings.".concat(this.worldName);
|
|
+ ConfigurationSection section = Config.config.getConfigurationSection(worldSectionPath);
|
|
+ if (section == null) {
|
|
+ section = Config.config.createSection(worldSectionPath);
|
|
+ }
|
|
+ Config.config.set(worldSectionPath, section);
|
|
+
|
|
+ this.load(section);
|
|
+ }
|
|
+
|
|
+ public void load(final ConfigurationSection config) {
|
|
+ this.config = config;
|
|
+
|
|
+ for (final Method method : Config.WorldConfig.class.getDeclaredMethods()) {
|
|
+ if (method.getReturnType() != void.class || method.getParameterCount() != 0 ||
|
|
+ !Modifier.isPrivate(method.getModifiers()) || Modifier.isStatic(method.getModifiers())) {
|
|
+ continue;
|
|
+ }
|
|
+
|
|
+ try {
|
|
+ method.setAccessible(true);
|
|
+ method.invoke(this, EMPTY);
|
|
+ } catch (final Exception ex) {
|
|
+ throw new RuntimeException(ex);
|
|
+ }
|
|
+ }
|
|
+
|
|
+ /* We re-save to add new options */
|
|
+ try {
|
|
+ Config.config.save(Config.configFile);
|
|
+ } catch (final Exception ex) {
|
|
+ Bukkit.getLogger().log(Level.SEVERE, "Unable to save Akarin config", ex);
|
|
+ }
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * update world defaults for the specified path, but also sets this world's config value for the path
|
|
+ * if it exists
|
|
+ */
|
|
+ void set(final String path, final Object val) {
|
|
+ this.worldDefaults.set(path, val);
|
|
+ if (this.config.get(path) != null) {
|
|
+ this.config.set(path, val);
|
|
+ }
|
|
+ }
|
|
+
|
|
+ boolean getBoolean(final String path, final boolean dfl) {
|
|
+ this.worldDefaults.addDefault(path, Boolean.valueOf(dfl));
|
|
+ return this.config.getBoolean(path, this.worldDefaults.getBoolean(path));
|
|
+ }
|
|
+
|
|
+ int getInt(final String path, final int dfl) {
|
|
+ this.worldDefaults.addDefault(path, Integer.valueOf(dfl));
|
|
+ return this.config.getInt(path, this.worldDefaults.getInt(path));
|
|
+ }
|
|
+
|
|
+ long getLong(final String path, final long dfl) {
|
|
+ this.worldDefaults.addDefault(path, Long.valueOf(dfl));
|
|
+ return this.config.getLong(path, this.worldDefaults.getLong(path));
|
|
+ }
|
|
+
|
|
+ double getDouble(final String path, final double dfl) {
|
|
+ this.worldDefaults.addDefault(path, Double.valueOf(dfl));
|
|
+ return this.config.getDouble(path, this.worldDefaults.getDouble(path));
|
|
+ }
|
|
+ }
|
|
+
|
|
+}
|
|
diff --git a/src/main/java/net/minecraft/server/DedicatedServer.java b/src/main/java/net/minecraft/server/DedicatedServer.java
|
|
index e62ca0543f1819259ad8720ad792fed3ef134d6a..e936dee73aa8c4b2212d0f29fa2f9825b36345e0 100644
|
|
--- a/src/main/java/net/minecraft/server/DedicatedServer.java
|
|
+++ b/src/main/java/net/minecraft/server/DedicatedServer.java
|
|
@@ -194,6 +194,7 @@ public class DedicatedServer extends MinecraftServer implements IMinecraftServer
|
|
com.destroystokyo.paper.PaperConfig.registerCommands();
|
|
com.destroystokyo.paper.VersionHistoryManager.INSTANCE.getClass(); // load version history now
|
|
// Paper end
|
|
+ io.akarin.server.Config.init((File) options.valueOf("akarin-settings")); // Akarin - Server Config
|
|
|
|
this.setSpawnAnimals(dedicatedserverproperties.spawnAnimals);
|
|
this.setSpawnNPCs(dedicatedserverproperties.spawnNpcs);
|
|
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
|
|
index 09b03afffa496b7090454682495ca35147c2f8a9..8d043de794d8ce13ed7efef88cfa93e3bc9b57f8 100644
|
|
--- a/src/main/java/net/minecraft/server/World.java
|
|
+++ b/src/main/java/net/minecraft/server/World.java
|
|
@@ -82,6 +82,8 @@ public abstract class World implements GeneratorAccess, AutoCloseable {
|
|
public final com.destroystokyo.paper.PaperWorldConfig paperConfig; // Paper
|
|
public final ChunkPacketBlockController chunkPacketBlockController; // Paper - Anti-Xray
|
|
|
|
+ public final io.akarin.server.Config.WorldConfig akarinConfig; // Akarin - Server Config
|
|
+
|
|
public final co.aikar.timings.WorldTimingsHandler timings; // Paper
|
|
public static BlockPosition lastPhysicsProblem; // Spigot
|
|
private org.spigotmc.TickLimiter entityLimiter;
|
|
@@ -131,6 +133,7 @@ public abstract class World implements GeneratorAccess, AutoCloseable {
|
|
this.spigotConfig = new org.spigotmc.SpigotWorldConfig( worlddata.getName() ); // Spigot
|
|
this.paperConfig = new com.destroystokyo.paper.PaperWorldConfig(worlddata.getName(), this.spigotConfig); // Paper
|
|
this.chunkPacketBlockController = this.paperConfig.antiXray ? new ChunkPacketBlockControllerAntiXray(this.paperConfig) : ChunkPacketBlockController.NO_OPERATION_INSTANCE; // Paper - Anti-Xray
|
|
+ this.akarinConfig = new io.akarin.server.Config.WorldConfig(worlddata.getName()); // Akarin - Server Config
|
|
this.generator = gen;
|
|
this.world = new CraftWorld((WorldServer) this, gen, env);
|
|
this.ticksPerAnimalSpawns = this.getServer().getTicksPerAnimalSpawns(); // CraftBukkit
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
|
index dcc44be613119f0e2c9d7f7e76bdf641ad1ae7c0..5ce50f5fd831955b74e002c0aebcdb6e25b5af31 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
|
@@ -806,6 +806,7 @@ public final class CraftServer implements Server {
|
|
|
|
org.spigotmc.SpigotConfig.init((File) console.options.valueOf("spigot-settings")); // Spigot
|
|
com.destroystokyo.paper.PaperConfig.init((File) console.options.valueOf("paper-settings")); // Paper
|
|
+ io.akarin.server.Config.init((File) console.options.valueOf("akarin-settings")); // Akarin - Server Config
|
|
for (WorldServer world : console.getWorlds()) {
|
|
world.worldData.setDifficulty(config.difficulty);
|
|
world.setSpawnFlags(config.spawnMonsters, config.spawnAnimals);
|
|
@@ -834,6 +835,7 @@ public final class CraftServer implements Server {
|
|
}
|
|
world.spigotConfig.init(); // Spigot
|
|
world.paperConfig.init(); // Paper
|
|
+ world.akarinConfig.init(); // Akarin - Server Config
|
|
}
|
|
|
|
Plugin[] pluginClone = pluginManager.getPlugins().clone(); // Paper
|
|
@@ -2092,6 +2094,14 @@ public final class CraftServer implements Server {
|
|
return com.destroystokyo.paper.PaperConfig.config;
|
|
}
|
|
|
|
+ // Akarin Start - Server Config
|
|
+ @Override
|
|
+ public YamlConfiguration getAkarinConfig()
|
|
+ {
|
|
+ return io.akarin.server.Config.config;
|
|
+ }
|
|
+ // Akarin End - Server Config
|
|
+
|
|
@Override
|
|
public void restart() {
|
|
org.spigotmc.RestartCommand.restart();
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/Main.java b/src/main/java/org/bukkit/craftbukkit/Main.java
|
|
index cb60310e63ce0f55f5e706edf9e1ef61a3732600..04694464b105aba007718e7b5933df8709d98b33 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/Main.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/Main.java
|
|
@@ -138,6 +138,14 @@ public class Main {
|
|
.describedAs("Yml file");
|
|
// Paper end
|
|
|
|
+ // Akarin Start - Server Config
|
|
+ acceptsAll(asList("akarin", "akarin-settings"), "File for Akarin settings")
|
|
+ .withRequiredArg()
|
|
+ .ofType(File.class)
|
|
+ .defaultsTo(new File("akarin.yml"))
|
|
+ .describedAs("Yml file");
|
|
+ // Akarin End - Server Config
|
|
+
|
|
// Paper start
|
|
acceptsAll(asList("server-name"), "Name of the server")
|
|
.withRequiredArg()
|