craftbukkit/nms-patches/net/minecraft/server/Main.patch

218 lines
12 KiB
Diff
Raw Normal View History

2020-06-25 10:00:00 +10:00
--- a/net/minecraft/server/Main.java
+++ b/net/minecraft/server/Main.java
2023-12-06 03:40:00 +11:00
@@ -60,6 +60,17 @@
2022-03-01 02:00:00 +11:00
import net.minecraft.world.level.storage.WorldInfo;
import org.slf4j.Logger;
2021-03-16 09:00:00 +11:00
+// CraftBukkit start
+import com.google.common.base.Charsets;
+import java.io.InputStreamReader;
2022-03-01 02:00:00 +11:00
+import java.util.concurrent.atomic.AtomicReference;
2021-03-16 09:00:00 +11:00
+import net.minecraft.SharedConstants;
2023-03-15 03:30:00 +11:00
+import net.minecraft.server.packs.EnumResourcePackType;
2021-03-16 09:00:00 +11:00
+import net.minecraft.world.level.dimension.WorldDimension;
2023-09-22 02:40:00 +10:00
+import net.minecraft.world.level.storage.SavedFile;
+import org.bukkit.configuration.file.YamlConfiguration;
2021-03-16 09:00:00 +11:00
+// CraftBukkit end
+
public class Main {
2022-03-01 02:00:00 +11:00
private static final Logger LOGGER = LogUtils.getLogger();
2023-12-06 03:40:00 +11:00
@@ -67,8 +78,9 @@
2020-06-25 10:00:00 +10:00
public Main() {}
2021-06-11 15:00:00 +10:00
@DontObfuscate
2020-06-25 10:00:00 +10:00
- public static void main(String[] astring) {
+ public static void main(final OptionSet optionset) { // CraftBukkit - replaces main(String[] astring)
2021-11-22 09:00:00 +11:00
SharedConstants.tryDetectVersion();
2020-06-25 10:00:00 +10:00
+ /* CraftBukkit start - Replace everything
OptionParser optionparser = new OptionParser();
OptionSpec<Void> optionspec = optionparser.accepts("nogui");
OptionSpec<Void> optionspec1 = optionparser.accepts("initSettings", "Initializes 'server.properties' and 'eula.txt', then quits");
2024-04-24 01:15:00 +10:00
@@ -94,15 +106,18 @@
2020-06-25 10:00:00 +10:00
optionparser.printHelpOn(System.err);
return;
}
+ */ // CraftBukkit end
2021-11-22 09:00:00 +11:00
2024-04-24 01:15:00 +10:00
- Path path = (Path) optionset.valueOf(optionspec14);
2023-09-22 02:57:13 +10:00
+ try {
+
2023-03-15 03:30:00 +11:00
+ Path path = (Path) optionset.valueOf("pidFile"); // CraftBukkit
if (path != null) {
writePidFile(path);
}
2021-11-22 09:00:00 +11:00
CrashReport.preload();
2024-04-24 01:15:00 +10:00
- if (optionset.has(optionspec13)) {
2021-11-22 09:00:00 +11:00
+ if (optionset.has("jfrProfile")) { // CraftBukkit
JvmProfiler.INSTANCE.start(Environment.SERVER);
}
2024-04-24 01:15:00 +10:00
@@ -110,14 +125,27 @@
2022-03-01 02:00:00 +11:00
DispenserRegistry.validate();
2021-11-22 09:00:00 +11:00
SystemUtils.startTimerHackThread();
2023-03-15 03:30:00 +11:00
Path path1 = Paths.get("server.properties");
- DedicatedServerSettings dedicatedserversettings = new DedicatedServerSettings(path1);
2021-06-11 15:00:00 +10:00
+ DedicatedServerSettings dedicatedserversettings = new DedicatedServerSettings(optionset); // CraftBukkit - CLI argument support
2020-06-25 10:00:00 +10:00
2021-11-22 09:00:00 +11:00
dedicatedserversettings.forceSave();
2024-04-24 01:15:00 +10:00
RegionFileCompression.configure(dedicatedserversettings.getProperties().regionFileComression);
2023-03-15 03:30:00 +11:00
Path path2 = Paths.get("eula.txt");
EULA eula = new EULA(path2);
2020-06-25 10:00:00 +10:00
- if (optionset.has(optionspec1)) {
+ if (optionset.has("initSettings")) { // CraftBukkit
+ // CraftBukkit start - SPIGOT-5761: Create bukkit.yml and commands.yml if not present
+ File configFile = (File) optionset.valueOf("bukkit-settings");
+ YamlConfiguration configuration = YamlConfiguration.loadConfiguration(configFile);
+ configuration.options().copyDefaults(true);
+ configuration.setDefaults(YamlConfiguration.loadConfiguration(new InputStreamReader(Main.class.getClassLoader().getResourceAsStream("configurations/bukkit.yml"), Charsets.UTF_8)));
+ configuration.save(configFile);
+
+ File commandFile = (File) optionset.valueOf("commands-settings");
+ YamlConfiguration commandsConfiguration = YamlConfiguration.loadConfiguration(commandFile);
+ commandsConfiguration.options().copyDefaults(true);
+ commandsConfiguration.setDefaults(YamlConfiguration.loadConfiguration(new InputStreamReader(Main.class.getClassLoader().getResourceAsStream("configurations/commands.yml"), Charsets.UTF_8)));
+ commandsConfiguration.save(commandFile);
+ // CraftBukkit end
2023-03-15 03:30:00 +11:00
Main.LOGGER.info("Initialized '{}' and '{}'", path1.toAbsolutePath(), path2.toAbsolutePath());
2020-06-25 10:00:00 +10:00
return;
}
2024-04-24 01:15:00 +10:00
@@ -127,11 +155,13 @@
2020-06-25 10:00:00 +10:00
return;
}
2024-04-24 01:15:00 +10:00
- File file = new File((String) optionset.valueOf(optionspec9));
2020-06-25 10:00:00 +10:00
+ File file = (File) optionset.valueOf("universe"); // CraftBukkit
2022-06-08 02:00:00 +10:00
Services services = Services.create(new YggdrasilAuthenticationService(Proxy.NO_PROXY), file);
2024-04-24 01:15:00 +10:00
- String s = (String) Optional.ofNullable((String) optionset.valueOf(optionspec10)).orElse(dedicatedserversettings.getProperties().levelName);
2020-06-25 10:00:00 +10:00
+ // CraftBukkit start
2021-06-11 15:00:00 +10:00
+ String s = (String) Optional.ofNullable((String) optionset.valueOf("world")).orElse(dedicatedserversettings.getProperties().levelName);
2021-11-22 09:00:00 +11:00
Convertable convertable = Convertable.createDefault(file.toPath());
2023-06-08 01:30:00 +10:00
- Convertable.ConversionSession convertable_conversionsession = convertable.validateAndCreateAccess(s);
+ Convertable.ConversionSession convertable_conversionsession = convertable.validateAndCreateAccess(s, WorldDimension.OVERWORLD);
2023-12-06 03:40:00 +11:00
+ // CraftBukkit end
Dynamic dynamic;
2020-06-25 10:00:00 +10:00
2023-12-06 03:40:00 +11:00
if (convertable_conversionsession.hasWorldData()) {
2024-04-24 01:15:00 +10:00
@@ -172,13 +202,31 @@
2021-06-11 15:00:00 +10:00
}
2023-12-06 03:40:00 +11:00
Dynamic<?> dynamic1 = dynamic;
2024-04-24 01:15:00 +10:00
- boolean flag = optionset.has(optionspec7);
2023-12-06 03:40:00 +11:00
+ boolean flag = optionset.has("safeMode"); // CraftBukkit
2020-06-25 10:00:00 +10:00
if (flag) {
Main.LOGGER.warn("Safe mode active, only vanilla datapack will be loaded");
2020-06-26 12:24:35 +10:00
}
2023-09-22 02:40:00 +10:00
ResourcePackRepository resourcepackrepository = ResourcePackSourceVanilla.createPackRepository(convertable_conversionsession);
2020-06-26 12:24:35 +10:00
+ // CraftBukkit start
2021-11-22 09:00:00 +11:00
+ File bukkitDataPackFolder = new File(convertable_conversionsession.getLevelPath(SavedFile.DATAPACK_DIR).toFile(), "bukkit");
2020-06-26 12:24:35 +10:00
+ if (!bukkitDataPackFolder.exists()) {
+ bukkitDataPackFolder.mkdirs();
+ }
+ File mcMeta = new File(bukkitDataPackFolder, "pack.mcmeta");
+ try {
+ com.google.common.io.Files.write("{\n"
+ + " \"pack\": {\n"
+ + " \"description\": \"Data pack for resources provided by Bukkit plugins\",\n"
2023-03-15 03:30:00 +11:00
+ + " \"pack_format\": " + SharedConstants.getCurrentVersion().getPackVersion(EnumResourcePackType.SERVER_DATA) + "\n"
2020-06-26 12:24:35 +10:00
+ + " }\n"
+ + "}\n", mcMeta, com.google.common.base.Charsets.UTF_8);
+ } catch (java.io.IOException ex) {
+ throw new RuntimeException("Could not initialize Bukkit datapack", ex);
+ }
2022-12-08 03:00:00 +11:00
+ AtomicReference<WorldLoader.a> worldLoader = new AtomicReference<>();
2020-06-26 12:24:35 +10:00
+ // CraftBukkit end
2022-03-01 02:00:00 +11:00
WorldStem worldstem;
2024-04-24 01:15:00 +10:00
@@ -187,6 +235,7 @@
2022-12-08 03:00:00 +11:00
worldstem = (WorldStem) SystemUtils.blockUntilDone((executor) -> {
return WorldLoader.load(worldloader_c, (worldloader_a) -> {
+ worldLoader.set(worldloader_a); // CraftBukkit
IRegistry<WorldDimension> iregistry = worldloader_a.datapackDimensions().registryOrThrow(Registries.LEVEL_STEM);
2023-12-06 03:40:00 +11:00
if (dynamic1 != null) {
2024-04-24 01:15:00 +10:00
@@ -199,7 +248,7 @@
2022-12-08 03:00:00 +11:00
WorldOptions worldoptions;
WorldDimensions worlddimensions;
- if (optionset.has(optionspec2)) {
+ if (optionset.has("demo")) { // CraftBukkit
worldsettings = MinecraftServer.DEMO_SETTINGS;
worldoptions = WorldOptions.DEMO_OPTIONS;
worlddimensions = WorldPresets.createNormalWorldDimensions(worldloader_a.datapackWorldgen());
2024-04-24 01:15:00 +10:00
@@ -207,7 +256,7 @@
2022-12-08 03:00:00 +11:00
DedicatedServerProperties dedicatedserverproperties = dedicatedserversettings.getProperties();
worldsettings = new WorldSettings(dedicatedserverproperties.levelName, dedicatedserverproperties.gamemode, dedicatedserverproperties.hardcore, dedicatedserverproperties.difficulty, false, new GameRules(), worldloader_a.dataConfiguration());
- worldoptions = optionset.has(optionspec3) ? dedicatedserverproperties.worldOptions.withBonusChest(true) : dedicatedserverproperties.worldOptions;
+ worldoptions = optionset.has("bonusChest") ? dedicatedserverproperties.worldOptions.withBonusChest(true) : dedicatedserverproperties.worldOptions; // CraftBukkit
worlddimensions = dedicatedserverproperties.createDimensions(worldloader_a.datapackWorldgen());
}
2024-04-24 01:15:00 +10:00
@@ -223,6 +272,7 @@
2022-06-08 02:00:00 +10:00
return;
2020-08-12 07:00:00 +10:00
}
2020-06-25 10:00:00 +10:00
+ /*
2022-12-08 03:00:00 +11:00
IRegistryCustom.Dimension iregistrycustom_dimension = worldstem.registries().compositeAccess();
2024-04-24 01:15:00 +10:00
boolean flag1 = optionset.has(optionspec6);
2020-06-25 10:00:00 +10:00
2024-04-24 01:15:00 +10:00
@@ -235,20 +285,31 @@
2022-12-08 03:00:00 +11:00
SaveData savedata = worldstem.worldData();
2020-06-25 10:00:00 +10:00
2022-03-01 02:00:00 +11:00
convertable_conversionsession.saveDataTag(iregistrycustom_dimension, savedata);
2020-06-25 10:00:00 +10:00
+ */
2021-11-22 09:00:00 +11:00
final DedicatedServer dedicatedserver = (DedicatedServer) MinecraftServer.spin((thread) -> {
2024-04-24 01:15:00 +10:00
- DedicatedServer dedicatedserver1 = new DedicatedServer(thread, convertable_conversionsession, resourcepackrepository, worldstem, dedicatedserversettings, DataConverterRegistry.getDataFixer(), services, WorldLoadListenerLogger::createFromGameruleRadius);
+ DedicatedServer dedicatedserver1 = new DedicatedServer(optionset, worldLoader.get(), thread, convertable_conversionsession, resourcepackrepository, worldstem, dedicatedserversettings, DataConverterRegistry.getDataFixer(), services, WorldLoadListenerLogger::createFromGameruleRadius);
2020-06-25 10:00:00 +10:00
+ /*
2024-04-24 01:15:00 +10:00
dedicatedserver1.setPort((Integer) optionset.valueOf(optionspec11));
2021-11-22 09:00:00 +11:00
dedicatedserver1.setDemo(optionset.has(optionspec2));
2024-04-24 01:15:00 +10:00
dedicatedserver1.setId((String) optionset.valueOf(optionspec12));
- boolean flag2 = !optionset.has(optionspec) && !optionset.valuesOf(optionspec15).contains("nogui");
2020-06-25 10:00:00 +10:00
+ */
2024-04-24 01:15:00 +10:00
+ boolean flag2 = !optionset.has("nogui") && !optionset.nonOptionArguments().contains("nogui");
2020-06-25 10:00:00 +10:00
2024-04-24 01:15:00 +10:00
if (flag2 && !GraphicsEnvironment.isHeadless()) {
2021-11-22 09:00:00 +11:00
dedicatedserver1.showGui();
2020-06-25 10:00:00 +10:00
}
+ if (optionset.has("port")) {
+ int port = (Integer) optionset.valueOf("port");
+ if (port > 0) {
+ dedicatedserver1.setPort(port);
+ }
+ }
+
return dedicatedserver1;
});
+ /* CraftBukkit start
Thread thread = new Thread("Server Shutdown Thread") {
public void run() {
2021-11-22 09:00:00 +11:00
dedicatedserver.halt(true);
2024-04-24 01:15:00 +10:00
@@ -257,6 +318,7 @@
2020-06-25 10:00:00 +10:00
thread.setUncaughtExceptionHandler(new DefaultUncaughtExceptionHandler(Main.LOGGER));
Runtime.getRuntime().addShutdownHook(thread);
+ */ // CraftBukkit end
} catch (Exception exception1) {
2022-03-01 02:00:00 +11:00
Main.LOGGER.error(LogUtils.FATAL_MARKER, "Failed to start the minecraft server", exception1);
2020-06-25 10:00:00 +10:00
}
2024-04-24 01:15:00 +10:00
@@ -293,7 +355,7 @@
2020-06-25 10:00:00 +10:00
}
2024-04-24 01:15:00 +10:00
public static void forceUpgrade(Convertable.ConversionSession convertable_conversionsession, DataFixer datafixer, boolean flag, BooleanSupplier booleansupplier, IRegistryCustom iregistrycustom, boolean flag1) {
2020-06-25 10:00:00 +10:00
- Main.LOGGER.info("Forcing world upgrade!");
2021-11-22 09:00:00 +11:00
+ Main.LOGGER.info("Forcing world upgrade! {}", convertable_conversionsession.getLevelId()); // CraftBukkit
2024-04-24 01:15:00 +10:00
WorldUpgrader worldupgrader = new WorldUpgrader(convertable_conversionsession, datafixer, iregistrycustom, flag, flag1);
2020-06-25 10:00:00 +10:00
IChatBaseComponent ichatbasecomponent = null;