2021-06-11 12:02:28 +00: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 16:47:28 +00:00
index 0000000000000000000000000000000000000000..80a3d5890aab91e6a48d5734140187851106bde3
2021-06-11 12:02:28 +00:00
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/PaperConfig.java
2021-11-09 07:59:15 +00:00
@@ -0,0 +1,188 @@
2021-06-11 12:02:28 +00: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 09:10:53 +00:00
+ + "Docs: https://docs.papermc.io/ \n";
2021-06-11 12:02:28 +00: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 16:47:28 +00:00
+ version = getInt("config-version", 27);
+ set("config-version", 27);
2021-06-11 12:02:28 +00: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 07:59:15 +00:00
+ saveConfig();
+ }
2021-06-11 12:02:28 +00:00
+
2021-11-09 07:59:15 +00:00
+ static void saveConfig() {
2021-06-11 12:02:28 +00: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-05-07 16:47:28 +00:00
index 0000000000000000000000000000000000000000..1dc56bee6827f6552cfa93a92fe8d0b5f94ab596
2021-06-11 12:02:28 +00:00
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
2022-05-07 16:47:28 +00:00
@@ -0,0 +1,99 @@
2021-06-11 12:02:28 +00:00
+package com.destroystokyo.paper;
+
+import java.util.List;
+
2021-11-24 17:58:26 +00:00
+import java.util.stream.Collectors;
2021-06-11 12:02:28 +00: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 07:59:15 +00:00
+import static com.destroystokyo.paper.PaperConfig.saveConfig;
2021-06-11 12:02:28 +00: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 16:47:28 +00:00
+ private void remove(String path) {
+ config.addDefault("world-settings.default." + path, null);
+ set(path, null);
+ }
+
2021-11-09 07:59:15 +00:00
+ public void removeOldValues() {
+ boolean needsSave = false;
+
+ if (needsSave) {
+ saveConfig();
+ }
+ }
+
2021-06-11 12:02:28 +00:00
+ 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) {
2021-11-09 07:59:15 +00: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 12:02:28 +00:00
+ }
+
2021-09-01 09:54:41 +00: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 12:02:28 +00: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 17:58:26 +00: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 12:02:28 +00:00
+}
diff --git a/src/main/java/net/minecraft/server/Main.java b/src/main/java/net/minecraft/server/Main.java
2022-03-01 05:43:03 +00:00
index 9e4cca119722c2edc478fdd1a34af4370649aa5c..b49528d8a2c577def4f74ee694ffd53b481acb32 100644
2021-06-11 12:02:28 +00:00
--- a/src/main/java/net/minecraft/server/Main.java
+++ b/src/main/java/net/minecraft/server/Main.java
2022-03-01 05:43:03 +00:00
@@ -109,6 +109,12 @@ public class Main {
2021-06-11 13:46:25 +00:00
DedicatedServerSettings dedicatedserversettings = new DedicatedServerSettings(optionset); // CraftBukkit - CLI argument support
2021-06-11 12:02:28 +00: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 13:46:25 +00:00
Path path1 = Paths.get("eula.txt");
Eula eula = new Eula(path1);
2021-06-11 12:02:28 +00:00
2022-03-01 05:43:03 +00:00
@@ -284,6 +290,20 @@ public class Main {
2021-06-11 12:02:28 +00: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 08:57:41 +00:00
public static void forceUpgrade(LevelStorageSource.LevelStorageAccess session, DataFixer dataFixer, boolean eraseCache, BooleanSupplier continueCheck, WorldGenSettings generatorOptions) {
2021-06-11 12:02:28 +00:00
Main.LOGGER.info("Forcing world upgrade! {}", session.getLevelId()); // CraftBukkit
2021-11-23 08:57:41 +00:00
WorldUpgrader worldupgrader = new WorldUpgrader(session, dataFixer, generatorOptions, eraseCache);
2021-11-09 07:59:15 +00:00
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
2022-03-13 07:47:54 +00:00
index 6016216921232bedba84acc1f6a87a3cfbb75850..ef128de5fe17231b39edb12a7014291d03cf79ec 100644
2021-11-09 07:59:15 +00:00
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
2022-03-13 07:47:54 +00:00
@@ -601,6 +601,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
2021-11-09 07:59:15 +00: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 08:57:41 +00:00
this.prepareLevels(worldserver.getChunkSource().chunkMap.progressListener, worldserver);
2021-11-09 07:59:15 +00: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 12:02:28 +00:00
diff --git a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
2022-03-01 05:43:03 +00:00
index 882fe0e84c0607c69ad729aa7732f41554975c82..ebd94265f56ecc946ff1834ec0d45673e010453e 100644
2021-06-11 12:02:28 +00:00
--- a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
+++ b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
2022-03-01 05:43:03 +00:00
@@ -195,6 +195,15 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
2021-06-11 12:02:28 +00: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-03-29 08:32:18 +00:00
index 081c324b42cea97fce2220aa2c86d02daef7688f..7c034b62dbebbbc4c9c4ceb427b1509fe8f986e3 100644
2021-06-11 12:02:28 +00:00
--- a/src/main/java/net/minecraft/server/level/ServerChunkCache.java
+++ b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
2022-03-29 08:32:18 +00:00
@@ -326,6 +326,12 @@ public class ServerChunkCache extends ChunkSource {
2021-06-11 12:02:28 +00:00
}
}
2021-06-11 13:46:25 +00:00
+ // Paper start - helper
+ public boolean isPositionTicking(Entity entity) {
2021-07-07 06:52:40 +00: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 13:46:25 +00:00
+ }
+ // Paper end
+
2021-07-07 06:52:40 +00:00
public boolean isPositionTicking(long pos) {
2021-11-23 08:57:41 +00:00
ChunkHolder playerchunk = this.getVisibleChunkIfPresent(pos);
2021-06-11 12:02:28 +00:00
diff --git a/src/main/java/net/minecraft/world/entity/EntityType.java b/src/main/java/net/minecraft/world/entity/EntityType.java
2022-03-01 05:43:03 +00:00
index ec57266d48998ed0c656006834c82342236ea4c9..d790c37753f019b682fe00bea392359ba18bf204 100644
2021-06-11 12:02:28 +00:00
--- a/src/main/java/net/minecraft/world/entity/EntityType.java
+++ b/src/main/java/net/minecraft/world/entity/EntityType.java
2022-03-01 05:43:03 +00:00
@@ -674,4 +674,10 @@ public class EntityType<T extends Entity> implements EntityTypeTest<Entity, T> {
2021-06-11 13:46:25 +00:00
T create(EntityType<T> type, Level world);
2021-06-11 12:02:28 +00:00
}
+
+ // Paper start
2021-11-23 08:57:41 +00:00
+ public static java.util.Set<ResourceLocation> getEntityNameList() {
2021-06-11 12:02:28 +00: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-03-01 05:43:03 +00:00
index 3dce5044332ee4a8f685ab1cde02cd4c72a85b63..6ded806628f2f3fd5b357eed41990abd7e06a372 100644
2021-06-11 12:02:28 +00:00
--- a/src/main/java/net/minecraft/world/level/Level.java
+++ b/src/main/java/net/minecraft/world/level/Level.java
2022-03-01 05:43:03 +00:00
@@ -144,6 +144,8 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
2021-06-11 12:02:28 +00: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-03-01 05:43:03 +00:00
@@ -162,6 +164,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
2021-06-11 12:02:28 +00:00
2022-03-01 05:43:03 +00:00
protected Level(WritableLevelData worlddatamutable, ResourceKey<Level> resourcekey, Holder<DimensionType> holder, Supplier<ProfilerFiller> supplier, boolean flag, boolean flag1, long i, org.bukkit.generator.ChunkGenerator gen, org.bukkit.generator.BiomeProvider biomeProvider, org.bukkit.World.Environment env) {
2021-06-11 12:02:28 +00: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 07:59:26 +00:00
this.world = new CraftWorld((ServerLevel) this, gen, biomeProvider, env);
2022-02-12 13:20:33 +00:00
2021-06-11 12:02:28 +00:00
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
2022-04-16 08:29:50 +00:00
index 6657edb762d234ab388b0bf7dd52f910e0e0af8b..d29c6d0536619fab5a48fbb52115dac09e7d7ca3 100644
2021-06-11 12:02:28 +00:00
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
2022-04-16 08:29:50 +00:00
@@ -866,6 +866,7 @@ public final class CraftServer implements Server {
2021-06-11 12:02:28 +00: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 13:46:25 +00:00
for (ServerLevel world : this.console.getAllLevels()) {
world.serverLevelData.setDifficulty(config.difficulty);
2021-06-11 12:02:28 +00:00
world.setSpawnSettings(config.spawnMonsters, config.spawnAnimals);
2022-04-16 08:29:50 +00:00
@@ -881,12 +882,14 @@ public final class CraftServer implements Server {
2022-02-12 13:20:33 +00:00
}
2021-06-11 12:02:28 +00:00
}
world.spigotConfig.init(); // Spigot
+ world.paperConfig.init(); // Paper
}
2021-06-11 13:46:25 +00:00
this.pluginManager.clearPlugins();
2021-06-15 08:38:57 +00:00
this.commandMap.clearCommands();
2021-06-11 13:46:25 +00:00
this.reloadData();
2021-06-11 12:02:28 +00:00
org.spigotmc.SpigotConfig.registerCommands(); // Spigot
+ com.destroystokyo.paper.PaperConfig.registerCommands(); // Paper
2021-06-11 13:46:25 +00:00
this.overrideAllCommandBlockCommands = this.commandsConfiguration.getStringList("command-block-overrides").contains("*");
this.ignoreVanillaPermissions = this.commandsConfiguration.getBoolean("ignore-vanilla-permissions");
2021-06-11 12:02:28 +00:00
2022-04-16 08:29:50 +00:00
@@ -2331,4 +2334,35 @@ public final class CraftServer implements Server {
2021-06-11 13:46:25 +00:00
return this.spigot;
2021-06-11 12:02:28 +00: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-03-29 08:32:18 +00:00
index e75ff70c52b097af447b7a91ef2c20c08a904d92..fae37b7b353cb7b0f8d4a79407fcc219a3c45b64 100644
2021-06-11 12:02:28 +00:00
--- a/src/main/java/org/bukkit/craftbukkit/Main.java
+++ b/src/main/java/org/bukkit/craftbukkit/Main.java
2021-12-10 14:24:07 +00:00
@@ -129,6 +129,14 @@ public class Main {
2021-06-11 12:02:28 +00: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 18:03:46 +00:00
diff --git a/src/main/java/org/spigotmc/SpigotWorldConfig.java b/src/main/java/org/spigotmc/SpigotWorldConfig.java
2022-03-01 05:43:03 +00:00
index a04da0a7d690fe3fcf10810b4e8c92a8ae027b86..feef74e3a6d50344245c4a61ece5b2194af1072f 100644
2021-12-01 18:03:46 +00: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)