mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-17 08:27:43 +01:00
Upstream has released updates that appears to apply and compile correctly Paper Changes: c8bc57c7 Cleanup ChunkMapDistance patch 276afaa2 Updated Upstream (Bukkit/CraftBukkit/Spigot)
369 lines
15 KiB
Diff
369 lines
15 KiB
Diff
From 2e9eb1dadfd676fce0e6e5a18cb5e80722cdf531 Mon Sep 17 00:00:00 2001
|
|
From: William Blake Galbreath <blake.galbreath@gmail.com>
|
|
Date: Thu, 9 May 2019 18:09:43 -0500
|
|
Subject: [PATCH] Purpur config files
|
|
|
|
---
|
|
.../net/minecraft/server/DedicatedServer.java | 9 ++
|
|
src/main/java/net/minecraft/server/World.java | 3 +
|
|
.../java/net/pl3x/purpur/PurpurCommand.java | 59 ++++++++
|
|
.../java/net/pl3x/purpur/PurpurConfig.java | 127 ++++++++++++++++++
|
|
.../net/pl3x/purpur/PurpurWorldConfig.java | 63 +++++++++
|
|
.../org/bukkit/craftbukkit/CraftServer.java | 2 +
|
|
.../java/org/bukkit/craftbukkit/Main.java | 8 ++
|
|
7 files changed, 271 insertions(+)
|
|
create mode 100644 src/main/java/net/pl3x/purpur/PurpurCommand.java
|
|
create mode 100644 src/main/java/net/pl3x/purpur/PurpurConfig.java
|
|
create mode 100644 src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/DedicatedServer.java b/src/main/java/net/minecraft/server/DedicatedServer.java
|
|
index c1473330f..f438323be 100644
|
|
--- a/src/main/java/net/minecraft/server/DedicatedServer.java
|
|
+++ b/src/main/java/net/minecraft/server/DedicatedServer.java
|
|
@@ -174,6 +174,15 @@ public class DedicatedServer extends MinecraftServer implements IMinecraftServer
|
|
return false;
|
|
}
|
|
com.destroystokyo.paper.PaperConfig.registerCommands();
|
|
+ // Purpur start
|
|
+ try {
|
|
+ net.pl3x.purpur.PurpurConfig.init((File) options.valueOf("purpur-settings"));
|
|
+ } catch (Exception e) {
|
|
+ DedicatedServer.LOGGER.error("Unable to load server configuration", e);
|
|
+ return false;
|
|
+ }
|
|
+ net.pl3x.purpur.PurpurConfig.registerCommands();
|
|
+ // Purpur end
|
|
com.destroystokyo.paper.VersionHistoryManager.INSTANCE.getClass(); // load version history now
|
|
// Paper end
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
|
|
index a7a35d6a6..c8f198fdf 100644
|
|
--- a/src/main/java/net/minecraft/server/World.java
|
|
+++ b/src/main/java/net/minecraft/server/World.java
|
|
@@ -94,6 +94,8 @@ public abstract class World implements IIBlockAccess, GeneratorAccess, AutoClose
|
|
|
|
public final com.destroystokyo.paper.PaperWorldConfig paperConfig; // Paper
|
|
|
|
+ public final net.pl3x.purpur.PurpurWorldConfig purpurConfig; // Purpur
|
|
+
|
|
public final co.aikar.timings.WorldTimingsHandler timings; // Paper
|
|
public static BlockPosition lastPhysicsProblem; // Spigot
|
|
private org.spigotmc.TickLimiter entityLimiter;
|
|
@@ -134,6 +136,7 @@ public abstract class World implements IIBlockAccess, GeneratorAccess, AutoClose
|
|
protected World(WorldData worlddata, DimensionManager dimensionmanager, BiFunction<World, WorldProvider, IChunkProvider> bifunction, GameProfilerFiller gameprofilerfiller, boolean flag, org.bukkit.generator.ChunkGenerator gen, org.bukkit.World.Environment env) {
|
|
this.spigotConfig = new org.spigotmc.SpigotWorldConfig( worlddata.getName() ); // Spigot
|
|
this.paperConfig = new com.destroystokyo.paper.PaperWorldConfig(worlddata.getName(), this.spigotConfig); // Paper
|
|
+ this.purpurConfig = new net.pl3x.purpur.PurpurWorldConfig(worlddata.getName(), this.paperConfig, this.spigotConfig); // Purpur
|
|
this.generator = gen;
|
|
this.world = new CraftWorld((WorldServer) this, gen, env);
|
|
this.ticksPerAnimalSpawns = this.getServer().getTicksPerAnimalSpawns(); // CraftBukkit
|
|
diff --git a/src/main/java/net/pl3x/purpur/PurpurCommand.java b/src/main/java/net/pl3x/purpur/PurpurCommand.java
|
|
new file mode 100644
|
|
index 000000000..293ed7da5
|
|
--- /dev/null
|
|
+++ b/src/main/java/net/pl3x/purpur/PurpurCommand.java
|
|
@@ -0,0 +1,59 @@
|
|
+package net.pl3x.purpur;
|
|
+
|
|
+import net.minecraft.server.MinecraftServer;
|
|
+import net.minecraft.server.WorldServer;
|
|
+import org.bukkit.ChatColor;
|
|
+import org.bukkit.Location;
|
|
+import org.bukkit.command.Command;
|
|
+import org.bukkit.command.CommandSender;
|
|
+
|
|
+import java.io.File;
|
|
+import java.util.Arrays;
|
|
+import java.util.Collections;
|
|
+import java.util.List;
|
|
+import java.util.stream.Collectors;
|
|
+
|
|
+public class PurpurCommand extends Command {
|
|
+ public PurpurCommand(String name) {
|
|
+ super(name);
|
|
+ this.description = "Purpur related commands";
|
|
+ this.usageMessage = "/purpur [reload | version]";
|
|
+ this.setPermission("bukkit.command.purpur");
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public List<String> tabComplete(CommandSender sender, String alias, String[] args, Location location) throws IllegalArgumentException {
|
|
+ if (args.length == 1) {
|
|
+ return Arrays.asList("reload", "version").stream()
|
|
+ .filter(arg -> arg.startsWith(args[0].toLowerCase()))
|
|
+ .collect(Collectors.toList());
|
|
+ }
|
|
+ return Collections.emptyList();
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public boolean execute(CommandSender sender, String commandLabel, String[] args) {
|
|
+ if (!testPermission(sender)) return true;
|
|
+
|
|
+ if (args.length != 1) {
|
|
+ sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
|
|
+ return false;
|
|
+ }
|
|
+
|
|
+ if (args[0].equals("reload")) {
|
|
+ Command.broadcastCommandMessage(sender, ChatColor.RED + "Please note that this command is not supported and may cause issues.");
|
|
+ Command.broadcastCommandMessage(sender, ChatColor.RED + "If you encounter any issues please use the /stop command to restart your server.");
|
|
+
|
|
+ MinecraftServer console = MinecraftServer.getServer();
|
|
+ net.pl3x.purpur.PurpurConfig.init((File) console.options.valueOf("purpur-settings"));
|
|
+ for (WorldServer world : console.getWorlds()) {
|
|
+ world.purpurConfig.init();
|
|
+ }
|
|
+ console.server.reloadCount++;
|
|
+
|
|
+ Command.broadcastCommandMessage(sender, ChatColor.GREEN + "Purpur config reload complete.");
|
|
+ }
|
|
+
|
|
+ return true;
|
|
+ }
|
|
+}
|
|
diff --git a/src/main/java/net/pl3x/purpur/PurpurConfig.java b/src/main/java/net/pl3x/purpur/PurpurConfig.java
|
|
new file mode 100644
|
|
index 000000000..2f87a929c
|
|
--- /dev/null
|
|
+++ b/src/main/java/net/pl3x/purpur/PurpurConfig.java
|
|
@@ -0,0 +1,127 @@
|
|
+package net.pl3x.purpur;
|
|
+
|
|
+import com.google.common.base.Throwables;
|
|
+import net.minecraft.server.MinecraftServer;
|
|
+import org.bukkit.Bukkit;
|
|
+import org.bukkit.command.Command;
|
|
+import org.bukkit.configuration.InvalidConfigurationException;
|
|
+import org.bukkit.configuration.file.YamlConfiguration;
|
|
+
|
|
+import java.io.File;
|
|
+import java.io.IOException;
|
|
+import java.lang.reflect.InvocationTargetException;
|
|
+import java.lang.reflect.Method;
|
|
+import java.lang.reflect.Modifier;
|
|
+import java.util.HashMap;
|
|
+import java.util.List;
|
|
+import java.util.Map;
|
|
+import java.util.logging.Level;
|
|
+
|
|
+public class PurpurConfig {
|
|
+ private static final int CONFIG_VERSION = 1;
|
|
+ private static final String HEADER = "This is the main configuration file for Purpur.\n"
|
|
+ + "As you can see, there's tons to configure. Some options may impact gameplay, so use\n"
|
|
+ + "with caution, and make sure you know what each option does before configuring.\n"
|
|
+ + "\n"
|
|
+ + "If you need help with the configuration or have any questions related to Purpur,\n"
|
|
+ + "join us in our Discord guild.\n"
|
|
+ + "\n"
|
|
+ + "Website: https://pl3x.net \n"
|
|
+ + "Docs: https://purpur.readthedocs.org/ \n";
|
|
+ private static File CONFIG_FILE;
|
|
+ static YamlConfiguration config;
|
|
+ static Map<String, Command> commands;
|
|
+ private static int version;
|
|
+ private static boolean verbose;
|
|
+
|
|
+ public static void init(File configFile) {
|
|
+ CONFIG_FILE = configFile;
|
|
+ config = new YamlConfiguration();
|
|
+ try {
|
|
+ config.load(CONFIG_FILE);
|
|
+ } catch (IOException ignore) {
|
|
+ } catch (InvalidConfigurationException ex) {
|
|
+ Bukkit.getLogger().log(Level.SEVERE, "Could not load purpur.yml, please correct your syntax errors", ex);
|
|
+ throw Throwables.propagate(ex);
|
|
+ }
|
|
+ config.options().header(HEADER);
|
|
+ config.options().copyDefaults(true);
|
|
+ verbose = getBoolean("verbose", false);
|
|
+
|
|
+ commands = new HashMap<>();
|
|
+ commands.put("purpur", new PurpurCommand("purpur"));
|
|
+
|
|
+ version = getInt("config-version", CONFIG_VERSION);
|
|
+ set("config-version", version);
|
|
+
|
|
+ readConfig(PurpurConfig.class, null);
|
|
+ }
|
|
+
|
|
+ protected static void log(String s) {
|
|
+ log(Level.INFO, s);
|
|
+ }
|
|
+
|
|
+ protected static void log(Level level, String s) {
|
|
+ if (verbose) {
|
|
+ Bukkit.getLogger().log(level, s);
|
|
+ }
|
|
+ }
|
|
+
|
|
+ public static void registerCommands() {
|
|
+ for (Map.Entry<String, Command> entry : commands.entrySet()) {
|
|
+ MinecraftServer.getServer().server.getCommandMap().register(entry.getKey(), "Purpur", entry.getValue());
|
|
+ }
|
|
+ }
|
|
+
|
|
+ static void readConfig(Class<?> clazz, Object instance) {
|
|
+ for (Method method : clazz.getDeclaredMethods()) {
|
|
+ if (Modifier.isPrivate(method.getModifiers())) {
|
|
+ if (method.getParameterTypes().length == 0 && method.getReturnType() == Void.TYPE) {
|
|
+ try {
|
|
+ method.setAccessible(true);
|
|
+ method.invoke(instance);
|
|
+ } catch (InvocationTargetException ex) {
|
|
+ throw Throwables.propagate(ex.getCause());
|
|
+ } catch (Exception ex) {
|
|
+ Bukkit.getLogger().log(Level.SEVERE, "Error invoking " + method, ex);
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+
|
|
+ try {
|
|
+ config.save(CONFIG_FILE);
|
|
+ } catch (IOException ex) {
|
|
+ Bukkit.getLogger().log(Level.SEVERE, "Could not save " + CONFIG_FILE, ex);
|
|
+ }
|
|
+ }
|
|
+
|
|
+ private static void set(String path, Object val) {
|
|
+ config.set(path, val);
|
|
+ }
|
|
+
|
|
+ private static boolean getBoolean(String path, boolean def) {
|
|
+ config.addDefault(path, def);
|
|
+ return config.getBoolean(path, config.getBoolean(path));
|
|
+ }
|
|
+
|
|
+ private static double getDouble(String path, double def) {
|
|
+ config.addDefault(path, def);
|
|
+ return config.getDouble(path, config.getDouble(path));
|
|
+ }
|
|
+
|
|
+ private static int getInt(String path, int def) {
|
|
+ config.addDefault(path, def);
|
|
+ return config.getInt(path, config.getInt(path));
|
|
+ }
|
|
+
|
|
+ private static <T> List getList(String path, T def) {
|
|
+ config.addDefault(path, def);
|
|
+ return config.getList(path, config.getList(path));
|
|
+ }
|
|
+
|
|
+ private static String getString(String path, String def) {
|
|
+ config.addDefault(path, def);
|
|
+ return config.getString(path, config.getString(path));
|
|
+ }
|
|
+}
|
|
diff --git a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
|
|
new file mode 100644
|
|
index 000000000..30f11fe26
|
|
--- /dev/null
|
|
+++ b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
|
|
@@ -0,0 +1,63 @@
|
|
+package net.pl3x.purpur;
|
|
+
|
|
+import com.destroystokyo.paper.PaperWorldConfig;
|
|
+import org.bukkit.configuration.file.YamlConfiguration;
|
|
+import org.spigotmc.SpigotWorldConfig;
|
|
+
|
|
+import java.util.List;
|
|
+
|
|
+import static net.pl3x.purpur.PurpurConfig.log;
|
|
+
|
|
+public class PurpurWorldConfig {
|
|
+
|
|
+ private final String worldName;
|
|
+ private final PaperWorldConfig paperConfig;
|
|
+ private final SpigotWorldConfig spigotConfig;
|
|
+ private final YamlConfiguration config;
|
|
+ private boolean verbose;
|
|
+
|
|
+ public PurpurWorldConfig(String worldName, PaperWorldConfig paperConfig, SpigotWorldConfig spigotConfig) {
|
|
+ this.worldName = worldName;
|
|
+ this.paperConfig = paperConfig;
|
|
+ this.spigotConfig = spigotConfig;
|
|
+ this.config = PurpurConfig.config;
|
|
+ init();
|
|
+ }
|
|
+
|
|
+ public void init() {
|
|
+ log("-------- World Settings For [" + worldName + "] --------");
|
|
+ PurpurConfig.readConfig(PurpurWorldConfig.class, this);
|
|
+ }
|
|
+
|
|
+ private void set(String path, Object val) {
|
|
+ config.set("world-settings.default." + path, val);
|
|
+ if (config.get("world-settings." + worldName + "." + path) != null) {
|
|
+ config.set("world-settings." + worldName + "." + path, val);
|
|
+ }
|
|
+ }
|
|
+
|
|
+ private boolean getBoolean(String path, boolean def) {
|
|
+ config.addDefault("world-settings.default." + path, def);
|
|
+ return config.getBoolean("world-settings." + worldName + "." + path, config.getBoolean("world-settings.default." + path));
|
|
+ }
|
|
+
|
|
+ private double getDouble(String path, double def) {
|
|
+ config.addDefault("world-settings.default." + path, def);
|
|
+ return config.getDouble("world-settings." + worldName + "." + path, config.getDouble("world-settings.default." + path));
|
|
+ }
|
|
+
|
|
+ private int getInt(String path, int def) {
|
|
+ config.addDefault("world-settings.default." + path, def);
|
|
+ return config.getInt("world-settings." + worldName + "." + path, config.getInt("world-settings.default." + path));
|
|
+ }
|
|
+
|
|
+ private <T> List getList(String path, T def) {
|
|
+ config.addDefault("world-settings.default." + path, def);
|
|
+ return config.getList("world-settings." + worldName + "." + path, config.getList("world-settings.default." + path));
|
|
+ }
|
|
+
|
|
+ private String getString(String path, String def) {
|
|
+ config.addDefault("world-settings.default." + path, def);
|
|
+ return config.getString("world-settings." + worldName + "." + path, config.getString("world-settings.default." + path));
|
|
+ }
|
|
+}
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
|
index 6dfdc9813..6a9786eb9 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
|
@@ -793,6 +793,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
|
|
+ net.pl3x.purpur.PurpurConfig.init((File) console.options.valueOf("purpur-settings")); // Purpur
|
|
for (WorldServer world : console.getWorlds()) {
|
|
world.worldData.setDifficulty(config.difficulty);
|
|
world.setSpawnFlags(config.spawnMonsters, config.spawnAnimals);
|
|
@@ -809,6 +810,7 @@ public final class CraftServer implements Server {
|
|
}
|
|
world.spigotConfig.init(); // Spigot
|
|
world.paperConfig.init(); // Paper
|
|
+ world.purpurConfig.init(); // Purpur
|
|
}
|
|
|
|
Plugin[] pluginClone = pluginManager.getPlugins().clone(); // Paper
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/Main.java b/src/main/java/org/bukkit/craftbukkit/Main.java
|
|
index 405ea5c46..2d60e7588 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/Main.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/Main.java
|
|
@@ -137,6 +137,14 @@ public class Main {
|
|
.describedAs("Yml file");
|
|
// Paper end
|
|
|
|
+ // Purpur Start
|
|
+ acceptsAll(asList("purpur", "purpur-settings"), "File for purpur settings")
|
|
+ .withRequiredArg()
|
|
+ .ofType(File.class)
|
|
+ .defaultsTo(new File("purpur.yml"))
|
|
+ .describedAs("Yml file");
|
|
+ // Purpur end
|
|
+
|
|
// Paper start
|
|
acceptsAll(asList("server-name"), "Name of the server")
|
|
.withRequiredArg()
|
|
--
|
|
2.20.1
|
|
|