2023-06-08 01:30:00 +10:00
From 01f883c974a22f19888baadf0c23ded9cf89ad33 Mon Sep 17 00:00:00 2001
2013-05-14 12:08:11 +10:00
From: md_5 <md_5@live.com.au>
2013-07-07 09:33:34 +10:00
Date: Sun, 7 Jul 2013 09:32:53 +1000
2013-05-14 12:08:11 +10:00
Subject: [PATCH] Spigot Configuration
2014-07-05 20:34:22 +10:00
Provides the basic infrastructure to load and save the Spigot configuration file, spigot.yml
2013-05-14 12:08:11 +10:00
2021-03-16 09:00:00 +11:00
diff --git a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
2023-06-08 01:30:00 +10:00
index e59110d36..9576ac188 100644
2021-03-16 09:00:00 +11:00
--- a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
+++ b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
2022-12-08 03:00:00 +11:00
@@ -178,6 +178,11 @@ public class DedicatedServer extends MinecraftServer implements IMinecraftServer
2021-11-22 09:00:00 +11:00
this.setPreventProxyConnections(dedicatedserverproperties.preventProxyConnections);
this.setLocalIp(dedicatedserverproperties.serverIp);
2019-04-23 12:00:00 +10:00
}
+ // Spigot start
2022-12-08 03:00:00 +11:00
+ this.setPlayerList(new DedicatedPlayerList(this, this.registries(), this.playerDataStorage));
2020-06-25 10:00:00 +10:00
+ org.spigotmc.SpigotConfig.init((java.io.File) options.valueOf("spigot-settings"));
2019-04-23 12:00:00 +10:00
+ org.spigotmc.SpigotConfig.registerCommands();
+ // Spigot end
2013-06-21 19:08:32 +10:00
2021-11-22 09:00:00 +11:00
this.setPvpAllowed(dedicatedserverproperties.pvp);
this.setFlightAllowed(dedicatedserverproperties.allowFlight);
2022-12-08 03:00:00 +11:00
@@ -209,7 +214,7 @@ public class DedicatedServer extends MinecraftServer implements IMinecraftServer
2019-04-23 12:00:00 +10:00
}
2013-06-21 19:08:32 +10:00
2019-04-23 12:00:00 +10:00
// CraftBukkit start
2022-12-08 03:00:00 +11:00
- this.setPlayerList(new DedicatedPlayerList(this, this.registries(), this.playerDataStorage));
+ // this.setPlayerList(new DedicatedPlayerList(this, this.registries(), this.playerDataStorage)); // Spigot - moved up
2019-04-23 12:00:00 +10:00
server.loadPlugins();
server.enablePlugins(org.bukkit.plugin.PluginLoadOrder.STARTUP);
// CraftBukkit end
2021-03-16 09:00:00 +11:00
diff --git a/src/main/java/net/minecraft/world/level/World.java b/src/main/java/net/minecraft/world/level/World.java
2023-06-08 01:30:00 +10:00
index 63b48cf02..8610cb15f 100644
2021-03-16 09:00:00 +11:00
--- a/src/main/java/net/minecraft/world/level/World.java
+++ b/src/main/java/net/minecraft/world/level/World.java
2023-06-08 01:30:00 +10:00
@@ -153,6 +153,7 @@ public abstract class World implements GeneratorAccess, AutoCloseable {
2022-02-07 18:54:42 +11:00
public List<EntityItem> captureDrops;
public final it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap<SpawnCategory> ticksPerSpawnCategory = new it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap<>();
2014-11-26 08:27:08 +11:00
public boolean populating;
2013-06-20 17:31:40 +10:00
+ public final org.spigotmc.SpigotWorldConfig spigotConfig; // Spigot
public CraftWorld getWorld() {
return this.world;
2023-06-08 01:30:00 +10:00
@@ -165,6 +166,7 @@ public abstract class World implements GeneratorAccess, AutoCloseable {
2021-11-23 18:48:10 +11:00
public abstract ResourceKey<WorldDimension> getTypeKey();
2013-06-20 17:31:40 +10:00
2023-03-15 03:30:00 +11:00
protected World(WorldDataMutable worlddatamutable, ResourceKey<World> resourcekey, IRegistryCustom iregistrycustom, Holder<DimensionManager> holder, Supplier<GameProfilerFiller> supplier, boolean flag, boolean flag1, long i, int j, org.bukkit.generator.ChunkGenerator gen, org.bukkit.generator.BiomeProvider biomeProvider, org.bukkit.World.Environment env) {
2021-11-22 09:00:00 +11:00
+ this.spigotConfig = new org.spigotmc.SpigotWorldConfig(((net.minecraft.world.level.storage.WorldDataServer) worlddatamutable).getLevelName()); // Spigot
2013-06-15 22:01:15 +10:00
this.generator = gen;
2021-08-15 08:08:25 +10:00
this.world = new CraftWorld((WorldServer) this, gen, biomeProvider, env);
2022-02-07 18:54:42 +11:00
2013-06-21 18:14:27 +10:00
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
2023-06-08 01:30:00 +10:00
index c4856af13..cf1800826 100644
2013-06-21 18:14:27 +10:00
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
2023-06-08 01:30:00 +10:00
@@ -884,6 +884,7 @@ public final class CraftServer implements Server {
2014-04-17 19:03:00 +10:00
logger.log(Level.WARNING, "Failed to load banned-players.json, " + ex.getMessage());
}
2013-06-21 18:14:27 +10:00
2015-05-25 20:09:58 +01:00
+ org.spigotmc.SpigotConfig.init((File) console.options.valueOf("spigot-settings")); // Spigot
2021-11-22 09:00:00 +11:00
for (WorldServer world : console.getAllLevels()) {
2021-06-11 15:00:00 +10:00
world.serverLevelData.setDifficulty(config.difficulty);
2021-11-22 09:00:00 +11:00
world.setSpawnSettings(config.spawnMonsters, config.spawnAnimals);
2023-06-08 01:30:00 +10:00
@@ -898,11 +899,13 @@ public final class CraftServer implements Server {
2022-02-07 18:54:42 +11:00
}
}
2013-06-21 18:14:27 +10:00
}
+ world.spigotConfig.init(); // Spigot
}
pluginManager.clearPlugins();
2013-06-22 14:07:01 +10:00
commandMap.clearCommands();
2017-05-14 12:00:00 +10:00
reloadData();
2013-06-22 14:07:01 +10:00
+ org.spigotmc.SpigotConfig.registerCommands(); // Spigot
2014-02-12 13:48:26 +00:00
overrideAllCommandBlockCommands = commandsConfiguration.getStringList("command-block-overrides").contains("*");
2018-07-16 12:16:51 +10:00
ignoreVanillaPermissions = commandsConfiguration.getBoolean("ignore-vanilla-permissions");
2013-06-22 14:07:01 +10:00
2015-05-25 20:09:58 +01:00
diff --git a/src/main/java/org/bukkit/craftbukkit/Main.java b/src/main/java/org/bukkit/craftbukkit/Main.java
2023-06-08 01:30:00 +10:00
index de9e099be..3c5e6a489 100644
2015-05-25 20:09:58 +01:00
--- a/src/main/java/org/bukkit/craftbukkit/Main.java
+++ b/src/main/java/org/bukkit/craftbukkit/Main.java
2023-03-15 03:30:00 +11:00
@@ -133,6 +133,14 @@ public class Main {
2015-05-25 20:09:58 +01:00
acceptsAll(asList("demo"), "Demo mode");
2022-08-30 22:00:30 +10:00
acceptsAll(asList("initSettings"), "Only create configuration files and then exit"); // SPIGOT-5761: Add initSettings option
2015-05-25 20:09:58 +01:00
+
+ // Spigot Start
+ acceptsAll(asList("S", "spigot-settings"), "File for spigot settings")
+ .withRequiredArg()
+ .ofType(File.class)
+ .defaultsTo(new File("spigot.yml"))
+ .describedAs("Yml file");
+ // Spigot End
}
};
2017-03-20 16:04:02 +11:00
diff --git a/src/main/java/org/spigotmc/SpigotCommand.java b/src/main/java/org/spigotmc/SpigotCommand.java
new file mode 100644
2023-06-08 01:30:00 +10:00
index 000000000..7443e7334
2017-03-20 16:04:02 +11:00
--- /dev/null
+++ b/src/main/java/org/spigotmc/SpigotCommand.java
@@ -0,0 +1,44 @@
+package org.spigotmc;
+
+import java.io.File;
+import net.minecraft.server.MinecraftServer;
2021-03-16 09:00:00 +11:00
+import net.minecraft.server.level.WorldServer;
2017-03-20 16:04:02 +11:00
+import org.bukkit.ChatColor;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+
+public class SpigotCommand extends Command {
+
+ public SpigotCommand(String name) {
+ super(name);
+ this.description = "Spigot related commands";
+ this.usageMessage = "/spigot reload";
+ this.setPermission("bukkit.command.spigot");
+ }
+
+ @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();
+ org.spigotmc.SpigotConfig.init((File) console.options.valueOf("spigot-settings"));
2021-11-22 09:00:00 +11:00
+ for (WorldServer world : console.getAllLevels()) {
2017-03-20 16:04:02 +11:00
+ world.spigotConfig.init();
+ }
+ console.server.reloadCount++;
+
+ Command.broadcastCommandMessage(sender, ChatColor.GREEN + "Reload complete.");
+ }
+
+ return true;
+ }
+}
2013-06-20 17:31:40 +10:00
diff --git a/src/main/java/org/spigotmc/SpigotConfig.java b/src/main/java/org/spigotmc/SpigotConfig.java
new file mode 100644
2023-06-08 01:30:00 +10:00
index 000000000..9ee0b4a1e
2013-06-20 17:31:40 +10:00
--- /dev/null
+++ b/src/main/java/org/spigotmc/SpigotConfig.java
2017-03-20 16:04:02 +11:00
@@ -0,0 +1,140 @@
2013-06-20 17:31:40 +10:00
+package org.spigotmc;
+
+import com.google.common.base.Throwables;
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
2013-06-21 18:21:29 +10:00
+import java.util.HashMap;
2013-06-20 18:16:28 +10:00
+import java.util.List;
2013-06-21 18:21:29 +10:00
+import java.util.Map;
2013-06-20 17:31:40 +10:00
+import java.util.logging.Level;
2013-06-21 19:08:32 +10:00
+import net.minecraft.server.MinecraftServer;
2013-06-20 17:31:40 +10:00
+import org.bukkit.Bukkit;
2013-06-21 18:21:29 +10:00
+import org.bukkit.command.Command;
2014-07-12 11:27:09 +10:00
+import org.bukkit.configuration.InvalidConfigurationException;
2013-06-20 17:31:40 +10:00
+import org.bukkit.configuration.file.YamlConfiguration;
+
+public class SpigotConfig
+{
+
2015-05-25 20:09:58 +01:00
+ private static File CONFIG_FILE;
2013-06-20 17:31:40 +10:00
+ private static final String HEADER = "This is the main configuration file for Spigot.\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"
+ + "For a reference for any variable inside this file, check out the Spigot wiki at\n"
+ + "http://www.spigotmc.org/wiki/spigot-configuration/\n"
+ + "\n"
+ + "If you need help with the configuration or have any questions related to Spigot,\n"
2022-01-03 08:22:42 +11:00
+ + "join us at the Discord or drop by our forums and leave a post.\n"
2013-06-20 17:31:40 +10:00
+ + "\n"
2022-01-03 08:22:42 +11:00
+ + "Discord: https://www.spigotmc.org/go/discord\n"
2014-08-23 14:14:57 +10:00
+ + "Forums: http://www.spigotmc.org/\n";
2013-06-20 17:31:40 +10:00
+ /*========================================================================*/
2014-08-25 20:09:32 +01:00
+ public static YamlConfiguration config;
2013-06-20 17:31:40 +10:00
+ static int version;
2013-06-21 18:21:29 +10:00
+ static Map<String, Command> commands;
2013-06-20 17:31:40 +10:00
+ /*========================================================================*/
+
2015-05-25 20:09:58 +01:00
+ public static void init(File configFile)
2013-06-20 17:31:40 +10:00
+ {
2015-05-25 20:09:58 +01:00
+ CONFIG_FILE = configFile;
2014-07-12 11:27:09 +10:00
+ config = new YamlConfiguration();
+ try
+ {
+ config.load( CONFIG_FILE );
+ } catch ( IOException ex )
+ {
+ } catch ( InvalidConfigurationException ex )
+ {
+ Bukkit.getLogger().log( Level.SEVERE, "Could not load spigot.yml, please correct your syntax errors", ex );
+ throw Throwables.propagate( ex );
+ }
+
2013-06-20 17:31:40 +10:00
+ config.options().header( HEADER );
+ config.options().copyDefaults( true );
+
2013-06-21 18:21:29 +10:00
+ commands = new HashMap<String, Command>();
2017-03-20 16:04:02 +11:00
+ commands.put( "spigot", new SpigotCommand( "spigot" ) );
2013-06-21 18:21:29 +10:00
+
2019-04-30 12:16:33 +10:00
+ version = getInt( "config-version", 12 );
+ set( "config-version", 12 );
2013-06-20 18:16:28 +10:00
+ readConfig( SpigotConfig.class, null );
2013-06-22 14:07:01 +10:00
+ }
2013-06-15 22:01:15 +10:00
+
2013-06-22 14:07:01 +10:00
+ public static void registerCommands()
+ {
2013-06-21 18:21:29 +10:00
+ for ( Map.Entry<String, Command> entry : commands.entrySet() )
+ {
2013-06-21 19:08:32 +10:00
+ MinecraftServer.getServer().server.getCommandMap().register( entry.getKey(), "Spigot", entry.getValue() );
2013-06-21 18:21:29 +10:00
+ }
+ }
+
2013-06-20 18:16:28 +10:00
+ static void readConfig(Class<?> clazz, Object instance)
2013-06-20 17:31:40 +10:00
+ {
2013-06-21 19:10:58 +10:00
+ for ( Method method : clazz.getDeclaredMethods() )
2013-06-20 17:31:40 +10:00
+ {
2013-06-20 18:16:28 +10:00
+ if ( Modifier.isPrivate( method.getModifiers() ) )
2013-06-20 17:31:40 +10:00
+ {
2013-06-21 19:17:26 +10:00
+ if ( method.getParameterTypes().length == 0 && method.getReturnType() == Void.TYPE )
2013-06-20 17:31:40 +10:00
+ {
+ try
+ {
2013-06-21 19:17:26 +10:00
+ method.setAccessible( true );
2013-06-20 18:16:28 +10:00
+ method.invoke( instance );
2013-06-20 17:31:40 +10:00
+ } catch ( InvocationTargetException ex )
+ {
2014-07-12 11:27:09 +10:00
+ throw Throwables.propagate( ex.getCause() );
2013-06-25 18:12:27 +10:00
+ } catch ( Exception ex )
2013-06-20 17:31:40 +10:00
+ {
+ Bukkit.getLogger().log( Level.SEVERE, "Error invoking " + method, ex );
+ }
+ }
+ }
+ }
2013-06-11 12:56:24 +10:00
+
2013-06-20 17:31:40 +10:00
+ try
+ {
+ config.save( CONFIG_FILE );
+ } catch ( IOException ex )
+ {
+ Bukkit.getLogger().log( Level.SEVERE, "Could not save " + CONFIG_FILE, ex );
+ }
+ }
2013-06-11 12:56:24 +10:00
+
2013-07-13 11:37:21 +10:00
+ private static void set(String path, Object val)
+ {
+ config.set( path, val );
+ }
+
2013-06-20 17:36:06 +10:00
+ private static boolean getBoolean(String path, boolean def)
2013-06-20 17:31:40 +10:00
+ {
+ config.addDefault( path, def );
+ return config.getBoolean( path, config.getBoolean( path ) );
+ }
+
2013-06-20 17:36:06 +10:00
+ private static int getInt(String path, int def)
2013-06-20 17:31:40 +10:00
+ {
+ config.addDefault( path, def );
+ return config.getInt( path, config.getInt( path ) );
+ }
+
2013-06-21 18:57:20 +10:00
+ private static <T> List getList(String path, T def)
2013-06-20 18:16:28 +10:00
+ {
+ config.addDefault( path, def );
+ return (List<T>) config.getList( path, config.getList( path ) );
+ }
+
2013-06-20 17:36:06 +10:00
+ private static String getString(String path, String def)
2013-06-20 17:31:40 +10:00
+ {
+ config.addDefault( path, def );
+ return config.getString( path, config.getString( path ) );
+ }
2014-07-26 18:03:45 +01:00
+
+ private static double getDouble(String path, double def)
+ {
+ config.addDefault( path, def );
+ return config.getDouble( path, config.getDouble( path ) );
+ }
2013-06-20 17:31:40 +10:00
+}
diff --git a/src/main/java/org/spigotmc/SpigotWorldConfig.java b/src/main/java/org/spigotmc/SpigotWorldConfig.java
new file mode 100644
2023-06-08 01:30:00 +10:00
index 000000000..1cce14866
2013-06-20 17:31:40 +10:00
--- /dev/null
+++ b/src/main/java/org/spigotmc/SpigotWorldConfig.java
2019-08-08 20:48:47 +10:00
@@ -0,0 +1,82 @@
2013-06-20 17:31:40 +10:00
+package org.spigotmc;
2013-06-11 12:56:24 +10:00
+
2013-06-20 18:16:28 +10:00
+import java.util.List;
2013-06-20 17:31:40 +10:00
+import org.bukkit.Bukkit;
+import org.bukkit.configuration.file.YamlConfiguration;
+
+public class SpigotWorldConfig
+{
+
+ private final String worldName;
2013-06-20 17:36:06 +10:00
+ private final YamlConfiguration config;
2013-06-21 18:14:27 +10:00
+ private boolean verbose;
2013-06-20 17:31:40 +10:00
+
+ public SpigotWorldConfig(String worldName)
+ {
+ this.worldName = worldName;
2013-06-20 17:36:06 +10:00
+ this.config = SpigotConfig.config;
2013-06-21 18:14:27 +10:00
+ init();
+ }
+
+ public void init()
+ {
2013-06-20 17:36:06 +10:00
+ this.verbose = getBoolean( "verbose", true );
2013-06-20 17:31:40 +10:00
+
+ log( "-------- World Settings For [" + worldName + "] --------" );
2013-06-20 18:16:28 +10:00
+ SpigotConfig.readConfig( SpigotWorldConfig.class, this );
2013-06-20 17:31:40 +10:00
+ }
+
+ private void log(String s)
+ {
+ if ( verbose )
2013-06-11 12:56:24 +10:00
+ {
2013-06-20 17:31:40 +10:00
+ Bukkit.getLogger().info( s );
2013-06-11 12:56:24 +10:00
+ }
2013-06-20 17:31:40 +10:00
+ }
+
2013-07-13 11:37:21 +10:00
+ private void set(String path, Object val)
+ {
+ config.set( "world-settings.default." + path, val );
+ }
+
2013-06-20 17:36:06 +10:00
+ private boolean getBoolean(String path, boolean def)
2013-06-20 17:31:40 +10:00
+ {
+ config.addDefault( "world-settings.default." + path, def );
+ return config.getBoolean( "world-settings." + worldName + "." + path, config.getBoolean( "world-settings.default." + path ) );
+ }
+
2013-06-21 17:00:01 +10:00
+ private double getDouble(String path, double def)
+ {
+ config.addDefault( "world-settings.default." + path, def );
2013-06-21 18:14:27 +10:00
+ return config.getDouble( "world-settings." + worldName + "." + path, config.getDouble( "world-settings.default." + path ) );
2013-06-21 17:00:01 +10:00
+ }
+
2019-04-30 12:16:33 +10:00
+ private int getInt(String path)
+ {
+ return config.getInt( "world-settings." + worldName + "." + path );
+ }
+
2013-06-20 17:36:06 +10:00
+ private int getInt(String path, int def)
2013-06-20 17:31:40 +10:00
+ {
+ config.addDefault( "world-settings.default." + path, def );
+ return config.getInt( "world-settings." + worldName + "." + path, config.getInt( "world-settings.default." + path ) );
+ }
+
2013-06-21 17:41:26 +10:00
+ private <T> List getList(String path, T def)
2013-06-20 18:16:28 +10:00
+ {
+ config.addDefault( "world-settings.default." + path, def );
+ return (List<T>) config.getList( "world-settings." + worldName + "." + path, config.getList( "world-settings.default." + path ) );
+ }
+
2013-06-20 17:36:06 +10:00
+ private String getString(String path, String def)
2013-06-20 17:31:40 +10:00
+ {
+ config.addDefault( "world-settings.default." + path, def );
+ return config.getString( "world-settings." + worldName + "." + path, config.getString( "world-settings.default." + path ) );
+ }
2019-08-08 20:48:47 +10:00
+
+ private Object get(String path, Object def)
+ {
+ config.addDefault( "world-settings.default." + path, def );
+ return config.get( "world-settings." + worldName + "." + path, config.get( "world-settings.default." + path ) );
+ }
2013-06-20 17:31:40 +10:00
+}
2013-05-14 12:08:11 +10:00
--
2023-05-25 07:31:10 +10:00
2.40.1
2013-05-14 12:08:11 +10:00