2021-06-11 14:02:28 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Zach Brown <zach.brown@destroystokyo.com>
Date: Mon, 29 Feb 2016 21:02:09 -0600
Subject: [PATCH] Paper config files
Loads each yml file for early init too so it can be used for early options
diff --git a/src/main/java/com/destroystokyo/paper/PaperConfig.java b/src/main/java/com/destroystokyo/paper/PaperConfig.java
new file mode 100644
2022-05-07 18:47:28 +02:00
index 0000000000000000000000000000000000000000..80a3d5890aab91e6a48d5734140187851106bde3
2021-06-11 14:02:28 +02:00
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/PaperConfig.java
2021-11-09 08:59:15 +01:00
@@ -0,0 +1,188 @@
2021-06-11 14:02:28 +02:00
+package com.destroystokyo.paper;
+
+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;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+import java.util.logging.Level;
+import java.util.regex.Pattern;
+
+import net.minecraft.server.MinecraftServer;
+import org.bukkit.Bukkit;
+import org.bukkit.command.Command;
+import org.bukkit.configuration.ConfigurationSection;
+import org.bukkit.configuration.InvalidConfigurationException;
+import org.bukkit.configuration.file.YamlConfiguration;
+
+public class PaperConfig {
+
+ private static File CONFIG_FILE;
+ private static final String HEADER = "This is the main configuration file for Paper.\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 Paper,\n"
+ + "join us in our Discord or IRC channel.\n"
+ + "\n"
+ + "Discord: https://discord.gg/papermc\n"
+ + "IRC: #paper @ irc.esper.net ( https://webchat.esper.net/?channels=paper ) \n"
+ + "Website: https://papermc.io/ \n"
2022-03-09 10:10:53 +01:00
+ + "Docs: https://docs.papermc.io/ \n";
2021-06-11 14:02:28 +02:00
+ /*========================================================================*/
+ public static YamlConfiguration config;
+ static int version;
+ static Map<String, Command> commands;
+ private static boolean verbose;
+ private static boolean fatalError;
+ /*========================================================================*/
+
+ public static void init(File configFile) {
+ CONFIG_FILE = configFile;
+ config = new YamlConfiguration();
+ try {
+ config.load(CONFIG_FILE);
+ } catch (IOException ex) {
+ } catch (InvalidConfigurationException ex) {
+ Bukkit.getLogger().log(Level.SEVERE, "Could not load paper.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<String, Command>();
+ commands.put("paper", new PaperCommand("paper"));
+
2022-05-07 18:47:28 +02:00
+ version = getInt("config-version", 27);
+ set("config-version", 27);
2021-06-11 14:02:28 +02:00
+ readConfig(PaperConfig.class, null);
+ }
+
+ protected static void logError(String s) {
+ Bukkit.getLogger().severe(s);
+ }
+
+ protected static void fatal(String s) {
+ fatalError = true;
+ throw new RuntimeException("Fatal paper.yml config error: " + s);
+ }
+
+ protected static void log(String s) {
+ if (verbose) {
+ Bukkit.getLogger().info(s);
+ }
+ }
+
+ public static void registerCommands() {
+ for (Map.Entry<String, Command> entry : commands.entrySet()) {
+ MinecraftServer.getServer().server.getCommandMap().register(entry.getKey(), "Paper", 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);
+ }
+ }
+ }
+ }
2021-11-09 08:59:15 +01:00
+ saveConfig();
+ }
2021-06-11 14:02:28 +02:00
+
2021-11-09 08:59:15 +01:00
+ static void saveConfig() {
2021-06-11 14:02:28 +02:00
+ try {
+ config.save(CONFIG_FILE);
+ } catch (IOException ex) {
+ Bukkit.getLogger().log(Level.SEVERE, "Could not save " + CONFIG_FILE, ex);
+ }
+ }
+
+ private static final Pattern SPACE = Pattern.compile(" ");
+ private static final Pattern NOT_NUMERIC = Pattern.compile("[^-\\d.]");
+ public static int getSeconds(String str) {
+ str = SPACE.matcher(str).replaceAll("");
+ final char unit = str.charAt(str.length() - 1);
+ str = NOT_NUMERIC.matcher(str).replaceAll("");
+ double num;
+ try {
+ num = Double.parseDouble(str);
+ } catch (Exception e) {
+ num = 0D;
+ }
+ switch (unit) {
+ case 'd': num *= (double) 60*60*24; break;
+ case 'h': num *= (double) 60*60; break;
+ case 'm': num *= (double) 60; break;
+ default: case 's': break;
+ }
+ return (int) num;
+ }
+
+ protected static String timeSummary(int seconds) {
+ String time = "";
+
+ if (seconds > 60 * 60 * 24) {
+ time += TimeUnit.SECONDS.toDays(seconds) + "d";
+ seconds %= 60 * 60 * 24;
+ }
+
+ if (seconds > 60 * 60) {
+ time += TimeUnit.SECONDS.toHours(seconds) + "h";
+ seconds %= 60 * 60;
+ }
+
+ if (seconds > 0) {
+ time += TimeUnit.SECONDS.toMinutes(seconds) + "m";
+ }
+ return time;
+ }
+
+ 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 float getFloat(String path, float def) {
+ // TODO: Figure out why getFloat() always returns the default value.
+ return (float) getDouble(path, (double) def);
+ }
+
+ 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 (List<T>) 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/com/destroystokyo/paper/PaperWorldConfig.java b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
new file mode 100644
2022-06-06 02:17:27 +02:00
index 0000000000000000000000000000000000000000..0853ff7641103447f458b2dc08076c27e3937074
2021-06-11 14:02:28 +02:00
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
2022-06-06 02:17:27 +02:00
@@ -0,0 +1,104 @@
2021-06-11 14:02:28 +02:00
+package com.destroystokyo.paper;
+
+import java.util.List;
+
2021-11-24 18:58:26 +01:00
+import java.util.stream.Collectors;
2021-06-11 14:02:28 +02:00
+import org.bukkit.Bukkit;
+import org.bukkit.configuration.file.YamlConfiguration;
+import org.spigotmc.SpigotWorldConfig;
+
+import static com.destroystokyo.paper.PaperConfig.log;
+import static com.destroystokyo.paper.PaperConfig.logError;
2021-11-09 08:59:15 +01:00
+import static com.destroystokyo.paper.PaperConfig.saveConfig;
2021-06-11 14:02:28 +02:00
+
+public class PaperWorldConfig {
+
+ private final String worldName;
+ private final SpigotWorldConfig spigotConfig;
+ private YamlConfiguration config;
+ private boolean verbose;
+
+ public PaperWorldConfig(String worldName, SpigotWorldConfig spigotConfig) {
+ this.worldName = worldName;
+ this.spigotConfig = spigotConfig;
+ this.config = PaperConfig.config;
+ init();
+ }
+
+ public void init() {
+ this.config = PaperConfig.config; // grab updated reference
+ log("-------- World Settings For [" + worldName + "] --------");
+ PaperConfig.readConfig(PaperWorldConfig.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);
+ }
+ }
+
2022-05-07 18:47:28 +02:00
+ private void remove(String path) {
+ config.addDefault("world-settings.default." + path, null);
+ set(path, null);
+ }
+
2021-11-09 08:59:15 +01:00
+ public void removeOldValues() {
+ boolean needsSave = false;
+
+ if (needsSave) {
+ saveConfig();
+ }
+ }
+
2021-06-11 14:02:28 +02:00
+ private boolean getBoolean(String path, boolean def) {
2022-06-06 02:17:27 +02:00
+ return this.getBoolean(path, def, true);
+ }
+ private boolean getBoolean(String path, boolean def, boolean setDefault) {
+ if (setDefault) {
+ config.addDefault("world-settings.default." + path, def);
+ }
+ return config.getBoolean("world-settings." + worldName + "." + path, config.getBoolean("world-settings.default." + path, def));
2021-06-11 14:02:28 +02:00
+ }
+
+ 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) {
2021-11-09 08:59:15 +01:00
+ return getInt(path, def, true);
+ }
+
+ private int getInt(String path, int def, boolean setDefault) {
+ if (setDefault) {
+ config.addDefault("world-settings.default." + path, def);
+ }
+ return config.getInt("world-settings." + worldName + "." + path, config.getInt("world-settings.default." + path, def));
2021-06-11 14:02:28 +02:00
+ }
+
2021-09-01 11:54:41 +02:00
+ private long getLong(String path, long def) {
+ config.addDefault("world-settings.default." + path, def);
+ return config.getLong("world-settings." + worldName + "." + path, config.getLong("world-settings.default." + path));
+ }
+
2021-06-11 14:02:28 +02:00
+ private float getFloat(String path, float def) {
+ // TODO: Figure out why getFloat() always returns the default value.
+ return (float) getDouble(path, (double) def);
+ }
+
+ private <T> List<T> getList(String path, List<T> def) {
+ config.addDefault("world-settings.default." + path, def);
+ return (List<T>) 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));
+ }
2021-11-24 18:58:26 +01:00
+
+ private <T extends Enum<T>> List<T> getEnumList(String path, List<T> def, Class<T> type) {
+ config.addDefault("world-settings.default." + path, def.stream().map(Enum::name).collect(Collectors.toList()));
+ return ((List<String>) (config.getList("world-settings." + worldName + "." + path, config.getList("world-settings.default." + path)))).stream().map(s -> Enum.valueOf(type, s)).collect(Collectors.toList());
+ }
2021-06-11 14:02:28 +02:00
+}
diff --git a/src/main/java/net/minecraft/server/Main.java b/src/main/java/net/minecraft/server/Main.java
2022-06-07 20:12:34 +02:00
index 853e7c2019f5147e9681e95a82eaef0825b6341e..97dc1d188a57b9f499c9cdc2ec54535af380e5cb 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/server/Main.java
+++ b/src/main/java/net/minecraft/server/Main.java
2022-06-07 20:12:34 +02:00
@@ -110,6 +110,12 @@ public class Main {
2021-06-11 15:46:25 +02:00
DedicatedServerSettings dedicatedserversettings = new DedicatedServerSettings(optionset); // CraftBukkit - CLI argument support
2021-06-11 14:02:28 +02:00
dedicatedserversettings.forceSave();
+ // Paper start - load config files for access below if needed
+ org.bukkit.configuration.file.YamlConfiguration bukkitConfiguration = loadConfigFile((File) optionset.valueOf("bukkit-settings"));
+ org.bukkit.configuration.file.YamlConfiguration spigotConfiguration = loadConfigFile((File) optionset.valueOf("spigot-settings"));
+ org.bukkit.configuration.file.YamlConfiguration paperConfiguration = loadConfigFile((File) optionset.valueOf("paper-settings"));
+ // Paper end
+
2021-06-11 15:46:25 +02:00
Path path1 = Paths.get("eula.txt");
Eula eula = new Eula(path1);
2021-06-11 14:02:28 +02:00
2022-06-07 20:12:34 +02:00
@@ -280,6 +286,20 @@ public class Main {
2021-06-11 14:02:28 +02:00
}
+ // Paper start - load config files
+ private static org.bukkit.configuration.file.YamlConfiguration loadConfigFile(File configFile) throws Exception {
+ org.bukkit.configuration.file.YamlConfiguration config = new org.bukkit.configuration.file.YamlConfiguration();
+ if (configFile.exists()) {
+ try {
+ config.load(configFile);
+ } catch (Exception ex) {
+ throw new Exception("Failed to load configuration file: " + configFile.getName(), ex);
+ }
+ }
+ return config;
+ }
+ // Paper end
+
2021-11-23 09:57:41 +01:00
public static void forceUpgrade(LevelStorageSource.LevelStorageAccess session, DataFixer dataFixer, boolean eraseCache, BooleanSupplier continueCheck, WorldGenSettings generatorOptions) {
2021-06-11 14:02:28 +02:00
Main.LOGGER.info("Forcing world upgrade! {}", session.getLevelId()); // CraftBukkit
2021-11-23 09:57:41 +01:00
WorldUpgrader worldupgrader = new WorldUpgrader(session, dataFixer, generatorOptions, eraseCache);
2021-11-09 08:59:15 +01:00
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
2022-06-07 20:12:34 +02:00
index 6cc81495d8d09ff1fbb09f2e63a16ec4fa6138ec..e24b27eb8647a90eb83ec0f78f3bb9568161ba9b 100644
2021-11-09 08:59:15 +01:00
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
2022-06-07 20:12:34 +02:00
@@ -569,6 +569,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
2021-11-09 08:59:15 +01:00
}
this.forceDifficulty();
for (ServerLevel worldserver : this.getAllLevels()) {
+ worldserver.paperConfig.removeOldValues(); // Paper - callback for clearing old config options, after any migrations have taken place
2021-11-23 09:57:41 +01:00
this.prepareLevels(worldserver.getChunkSource().chunkMap.progressListener, worldserver);
2021-11-09 08:59:15 +01:00
worldserver.entityManager.tick(); // SPIGOT-6526: Load pending entities so they are available to the API
this.server.getPluginManager().callEvent(new org.bukkit.event.world.WorldLoadEvent(worldserver.getWorld()));
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
2022-06-07 20:12:34 +02:00
index 570db14d930e15a96621d0d24ce11a27dc38494b..a8d69168fd7aefb2ef1639ab7d57e627f0a2cd68 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
+++ b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
2022-06-07 20:12:34 +02:00
@@ -188,6 +188,15 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
2021-06-11 14:02:28 +02:00
org.spigotmc.SpigotConfig.init((java.io.File) options.valueOf("spigot-settings"));
org.spigotmc.SpigotConfig.registerCommands();
// Spigot end
+ // Paper start
+ try {
+ com.destroystokyo.paper.PaperConfig.init((java.io.File) options.valueOf("paper-settings"));
+ } catch (Exception e) {
+ DedicatedServer.LOGGER.error("Unable to load server configuration", e);
+ return false;
+ }
+ com.destroystokyo.paper.PaperConfig.registerCommands();
+ // Paper end
this.setPvpAllowed(dedicatedserverproperties.pvp);
this.setFlightAllowed(dedicatedserverproperties.allowFlight);
diff --git a/src/main/java/net/minecraft/server/level/ServerChunkCache.java b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
2022-06-07 20:12:34 +02:00
index ce88976db29b9e9524dbe45b16721ef90afb692b..d0b3fdec88ca7e8b1a57b742c1c9b785750123e8 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/server/level/ServerChunkCache.java
+++ b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
2022-06-07 20:12:34 +02:00
@@ -327,6 +327,12 @@ public class ServerChunkCache extends ChunkSource {
2021-06-11 14:02:28 +02:00
}
}
2021-06-11 15:46:25 +02:00
+ // Paper start - helper
+ public boolean isPositionTicking(Entity entity) {
2021-07-07 08:52:40 +02:00
+ return this.isPositionTicking(ChunkPos.asLong(net.minecraft.util.Mth.floor(entity.getX()) >> 4, net.minecraft.util.Mth.floor(entity.getZ()) >> 4));
2021-06-11 15:46:25 +02:00
+ }
+ // Paper end
+
2021-07-07 08:52:40 +02:00
public boolean isPositionTicking(long pos) {
2021-11-23 09:57:41 +01:00
ChunkHolder playerchunk = this.getVisibleChunkIfPresent(pos);
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/net/minecraft/world/entity/EntityType.java b/src/main/java/net/minecraft/world/entity/EntityType.java
2022-06-07 20:12:34 +02:00
index cdf8020194f2ec1fe7b65b22c8e1f5b1c23eaefa..d14757d30040c3c9030309a8bb4a37e0c9a4d8db 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/entity/EntityType.java
+++ b/src/main/java/net/minecraft/world/entity/EntityType.java
2022-06-07 20:12:34 +02:00
@@ -673,4 +673,10 @@ public class EntityType<T extends Entity> implements EntityTypeTest<Entity, T> {
2021-06-11 15:46:25 +02:00
T create(EntityType<T> type, Level world);
2021-06-11 14:02:28 +02:00
}
+
+ // Paper start
2021-11-23 09:57:41 +01:00
+ public static java.util.Set<ResourceLocation> getEntityNameList() {
2021-06-11 14:02:28 +02:00
+ return Registry.ENTITY_TYPE.keySet();
+ }
+ // Paper end
}
diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java
2022-06-07 20:12:34 +02:00
index c1194f459414dc6ca9626ab8cec48cb48cdd926b..5576da91821926cdd9c5ef09534deb843986d202 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/level/Level.java
+++ b/src/main/java/net/minecraft/world/level/Level.java
2022-06-07 20:12:34 +02:00
@@ -150,6 +150,8 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
2021-06-11 14:02:28 +02:00
public boolean populating;
public final org.spigotmc.SpigotWorldConfig spigotConfig; // Spigot
+ public final com.destroystokyo.paper.PaperWorldConfig paperConfig; // Paper
+
public final SpigotTimings.WorldTimingsHandler timings; // Spigot
public static BlockPos lastPhysicsProblem; // Spigot
private org.spigotmc.TickLimiter entityLimiter;
2022-06-07 20:12:34 +02:00
@@ -168,6 +170,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
2021-06-11 14:02:28 +02:00
2022-06-07 20:12:34 +02:00
protected Level(WritableLevelData worlddatamutable, ResourceKey<Level> resourcekey, Holder<DimensionType> holder, Supplier<ProfilerFiller> 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-06-11 14:02:28 +02:00
this.spigotConfig = new org.spigotmc.SpigotWorldConfig(((net.minecraft.world.level.storage.PrimaryLevelData) worlddatamutable).getLevelName()); // Spigot
+ this.paperConfig = new com.destroystokyo.paper.PaperWorldConfig(((net.minecraft.world.level.storage.PrimaryLevelData) worlddatamutable).getLevelName(), this.spigotConfig); // Paper
this.generator = gen;
2021-08-25 09:59:26 +02:00
this.world = new CraftWorld((ServerLevel) this, gen, biomeProvider, env);
2022-02-12 14:20:33 +01:00
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
2022-06-07 20:12:34 +02:00
index 1d94c0fbdead83155aefc8d4a16dbcb95b3c9838..cd6ef8cfba7367fec87dd238add23cfd365a5ceb 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
2022-06-07 20:12:34 +02:00
@@ -861,6 +861,7 @@ public final class CraftServer implements Server {
2021-06-11 14:02:28 +02:00
}
org.spigotmc.SpigotConfig.init((File) console.options.valueOf("spigot-settings")); // Spigot
+ com.destroystokyo.paper.PaperConfig.init((File) console.options.valueOf("paper-settings")); // Paper
2021-06-11 15:46:25 +02:00
for (ServerLevel world : this.console.getAllLevels()) {
world.serverLevelData.setDifficulty(config.difficulty);
2021-06-11 14:02:28 +02:00
world.setSpawnSettings(config.spawnMonsters, config.spawnAnimals);
2022-06-07 20:12:34 +02:00
@@ -876,12 +877,14 @@ public final class CraftServer implements Server {
2022-02-12 14:20:33 +01:00
}
2021-06-11 14:02:28 +02:00
}
world.spigotConfig.init(); // Spigot
+ world.paperConfig.init(); // Paper
}
2021-06-11 15:46:25 +02:00
this.pluginManager.clearPlugins();
2021-06-15 10:38:57 +02:00
this.commandMap.clearCommands();
2021-06-11 15:46:25 +02:00
this.reloadData();
2021-06-11 14:02:28 +02:00
org.spigotmc.SpigotConfig.registerCommands(); // Spigot
+ com.destroystokyo.paper.PaperConfig.registerCommands(); // Paper
2021-06-11 15:46:25 +02:00
this.overrideAllCommandBlockCommands = this.commandsConfiguration.getStringList("command-block-overrides").contains("*");
this.ignoreVanillaPermissions = this.commandsConfiguration.getBoolean("ignore-vanilla-permissions");
2021-06-11 14:02:28 +02:00
2022-06-07 20:12:34 +02:00
@@ -2314,4 +2317,35 @@ public final class CraftServer implements Server {
2021-06-11 15:46:25 +02:00
return this.spigot;
2021-06-11 14:02:28 +02:00
}
// Spigot end
+
+ // Paper start
+ @SuppressWarnings({"rawtypes", "unchecked"})
+ public static java.nio.file.Path dumpHeap(java.nio.file.Path dir, String name) {
+ try {
+ java.nio.file.Files.createDirectories(dir);
+
+ javax.management.MBeanServer server = java.lang.management.ManagementFactory.getPlatformMBeanServer();
+ java.nio.file.Path file;
+
+ try {
+ Class clazz = Class.forName("openj9.lang.management.OpenJ9DiagnosticsMXBean");
+ Object openj9Mbean = java.lang.management.ManagementFactory.newPlatformMXBeanProxy(server, "openj9.lang.management:type=OpenJ9Diagnostics", clazz);
+ java.lang.reflect.Method m = clazz.getMethod("triggerDumpToFile", String.class, String.class);
+ file = dir.resolve(name + ".phd");
+ m.invoke(openj9Mbean, "heap", file.toString());
+ } catch (ClassNotFoundException e) {
+ Class clazz = Class.forName("com.sun.management.HotSpotDiagnosticMXBean");
+ Object hotspotMBean = java.lang.management.ManagementFactory.newPlatformMXBeanProxy(server, "com.sun.management:type=HotSpotDiagnostic", clazz);
+ java.lang.reflect.Method m = clazz.getMethod("dumpHeap", String.class, boolean.class);
+ file = dir.resolve(name + ".hprof");
+ m.invoke(hotspotMBean, file.toString(), true);
+ }
+
+ return file;
+ } catch (Throwable t) {
+ Bukkit.getLogger().log(Level.SEVERE, "Could not write heap", t);
+ return null;
+ }
+ }
+ // Paper end
}
diff --git a/src/main/java/org/bukkit/craftbukkit/Main.java b/src/main/java/org/bukkit/craftbukkit/Main.java
2022-06-07 20:12:34 +02:00
index e5008c75054df38356af193fd049110d7d56e2d4..c694c6dfed0b3aa098b1822676e39bd3eb04b45a 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/Main.java
+++ b/src/main/java/org/bukkit/craftbukkit/Main.java
2021-12-10 15:24:07 +01:00
@@ -129,6 +129,14 @@ public class Main {
2021-06-11 14:02:28 +02:00
.defaultsTo(new File("spigot.yml"))
.describedAs("Yml file");
// Spigot End
+
+ // Paper Start
+ acceptsAll(asList("paper", "paper-settings"), "File for paper settings")
+ .withRequiredArg()
+ .ofType(File.class)
+ .defaultsTo(new File("paper.yml"))
+ .describedAs("Yml file");
+ // Paper end
}
};
2021-12-01 19:03:46 +01:00
diff --git a/src/main/java/org/spigotmc/SpigotWorldConfig.java b/src/main/java/org/spigotmc/SpigotWorldConfig.java
2022-03-01 06:43:03 +01:00
index a04da0a7d690fe3fcf10810b4e8c92a8ae027b86..feef74e3a6d50344245c4a61ece5b2194af1072f 100644
2021-12-01 19:03:46 +01:00
--- a/src/main/java/org/spigotmc/SpigotWorldConfig.java
+++ b/src/main/java/org/spigotmc/SpigotWorldConfig.java
@@ -58,8 +58,14 @@ public class SpigotWorldConfig
public int getInt(String path, int def)
{
- this.config.addDefault( "world-settings.default." + path, def );
- return this.config.getInt( "world-settings." + this.worldName + "." + path, this.config.getInt( "world-settings.default." + path ) );
+ // Paper start - get int without setting default
+ return this.getInt(path, def, true);
+ }
+ public int getInt(String path, int def, boolean setDef)
+ {
+ if (setDef) this.config.addDefault( "world-settings.default." + path, def );
+ return this.config.getInt( "world-settings." + this.worldName + "." + path, this.config.getInt( "world-settings.default." + path, def ) );
+ // Paper end
}
public <T> List getList(String path, T def)