2020-06-25 02:00:00 +02:00
--- a/net/minecraft/server/Main.java
+++ b/net/minecraft/server/Main.java
2024-12-11 22:26:55 +01:00
@@ -38,6 +38,7 @@
import net.minecraft.server.dedicated.DedicatedServerProperties;
import net.minecraft.server.dedicated.DedicatedServerSettings;
import net.minecraft.server.level.progress.LoggerChunkProgressListener;
+import net.minecraft.server.packs.PackType;
import net.minecraft.server.packs.repository.PackRepository;
import net.minecraft.server.packs.repository.ServerPacksSource;
import net.minecraft.util.Mth;
@@ -55,22 +56,31 @@
import net.minecraft.world.level.levelgen.WorldOptions;
import net.minecraft.world.level.levelgen.presets.WorldPresets;
import net.minecraft.world.level.storage.LevelDataAndDimensions;
+import net.minecraft.world.level.storage.LevelResource;
import net.minecraft.world.level.storage.LevelStorageSource;
import net.minecraft.world.level.storage.LevelSummary;
import net.minecraft.world.level.storage.PrimaryLevelData;
-import net.minecraft.world.level.storage.WorldData;
2022-02-28 16:00:00 +01:00
import org.slf4j.Logger;
2021-03-15 23:00:00 +01:00
+// CraftBukkit start
2022-08-30 13:50:50 +02:00
+import com.google.common.base.Charsets;
+import java.io.InputStreamReader;
2022-02-28 16:00:00 +01:00
+import java.util.concurrent.atomic.AtomicReference;
2021-03-15 23:00:00 +01:00
+import net.minecraft.SharedConstants;
2022-08-30 13:50:50 +02:00
+import org.bukkit.configuration.file.YamlConfiguration;
2021-03-15 23:00:00 +01:00
+// CraftBukkit end
+
public class Main {
2022-02-28 16:00:00 +01:00
private static final Logger LOGGER = LogUtils.getLogger();
2024-12-03 17:20:00 +01:00
2020-06-25 02:00:00 +02:00
public Main() {}
2024-12-03 17:20:00 +01:00
- @SuppressForbidden(a = "System.out needed before bootstrap")
+ @SuppressForbidden(reason = "System.out needed before bootstrap") // CraftBukkit - decompile error
2021-06-11 07:00:00 +02:00
@DontObfuscate
2024-12-11 22:26:55 +01:00
- public static void main(String[] args) {
2020-06-25 02:00:00 +02:00
+ public static void main(final OptionSet optionset) { // CraftBukkit - replaces main(String[] astring)
2021-11-21 23:00:00 +01:00
SharedConstants.tryDetectVersion();
2020-06-25 02:00:00 +02: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");
2022-10-22 14:47:45 +02:00
@@ -90,50 +100,104 @@
2024-12-11 22:26:55 +01:00
OptionSpec<String> optionspec15 = optionparser.nonOptions();
try {
- OptionSet optionset = optionparser.parse(args);
+ OptionSet optionset = optionparser.parse(astring);
if (optionset.has(optionspec8)) {
2020-06-25 02:00:00 +02:00
optionparser.printHelpOn(System.err);
return;
}
+ */ // CraftBukkit end
2021-11-21 23:00:00 +01:00
2024-04-23 17:15:00 +02:00
- Path path = (Path) optionset.valueOf(optionspec14);
2023-09-21 18:57:13 +02:00
+ try {
2023-03-14 17:30:00 +01:00
2024-12-11 22:26:55 +01:00
+ Path path = (Path) optionset.valueOf("pidFile"); // CraftBukkit
+
2023-03-14 17:30:00 +01:00
if (path != null) {
2024-12-11 22:26:55 +01:00
Main.writePidFile(path);
2023-03-14 17:30:00 +01:00
}
2021-11-21 23:00:00 +01:00
CrashReport.preload();
2024-04-23 17:15:00 +02:00
- if (optionset.has(optionspec13)) {
2021-11-21 23:00:00 +01:00
+ if (optionset.has("jfrProfile")) { // CraftBukkit
JvmProfiler.INSTANCE.start(Environment.SERVER);
}
2022-07-07 05:00:31 +02:00
+ io.papermc.paper.plugin.PluginInitializerManager.load(optionset); // Paper
Bootstrap.bootStrap();
2024-12-11 22:26:55 +01:00
Bootstrap.validate();
Util.startTimerHackThread();
2023-03-14 17:30:00 +01:00
Path path1 = Paths.get("server.properties");
- DedicatedServerSettings dedicatedserversettings = new DedicatedServerSettings(path1);
2021-06-11 07:00:00 +02:00
+ DedicatedServerSettings dedicatedserversettings = new DedicatedServerSettings(optionset); // CraftBukkit - CLI argument support
2020-06-25 02:00:00 +02:00
2021-11-21 23:00:00 +01:00
dedicatedserversettings.forceSave();
2024-12-11 22:26:55 +01:00
RegionFileVersion.configure(dedicatedserversettings.getProperties().regionFileComression);
2023-03-14 17:30:00 +01:00
Path path2 = Paths.get("eula.txt");
2024-12-11 22:26:55 +01:00
Eula eula = new Eula(path2);
2022-06-09 07:20:16 +02:00
+ // Paper start - load config files early for access below if needed
+ org.bukkit.configuration.file.YamlConfiguration bukkitConfiguration = io.papermc.paper.configuration.PaperConfigurations.loadLegacyConfigFile((File) optionset.valueOf("bukkit-settings"));
+ org.bukkit.configuration.file.YamlConfiguration spigotConfiguration = io.papermc.paper.configuration.PaperConfigurations.loadLegacyConfigFile((File) optionset.valueOf("spigot-settings"));
+ // Paper end - load config files early for access below if needed
2020-06-25 02:00:00 +02:00
- if (optionset.has(optionspec1)) {
+ if (optionset.has("initSettings")) { // CraftBukkit
2022-08-30 13:50:50 +02:00
+ // 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-14 17:30:00 +01:00
Main.LOGGER.info("Initialized '{}' and '{}'", path1.toAbsolutePath(), path2.toAbsolutePath());
2020-06-25 02:00:00 +02:00
return;
}
2014-07-09 02:35:44 +02:00
- if (!eula.hasAgreedToEULA()) {
+ // Spigot Start
+ boolean eulaAgreed = Boolean.getBoolean( "com.mojang.eula.agree" );
+ if ( eulaAgreed )
+ {
+ System.err.println( "You have used the Spigot command line EULA agreement flag." );
+ System.err.println( "By using this setting you are indicating your agreement to Mojang's EULA (https://account.mojang.com/documents/minecraft_eula)." );
+ System.err.println( "If you do not agree to the above EULA please stop your server and remove this flag immediately." );
+ }
+ // Spigot End
+ if (!eula.hasAgreedToEULA() && !eulaAgreed) { // Spigot
Main.LOGGER.info("You need to agree to the EULA in order to run the server. Go to eula.txt for more info.");
2020-06-25 02:00:00 +02:00
return;
}
2024-04-23 17:15:00 +02:00
- File file = new File((String) optionset.valueOf(optionspec9));
2022-06-09 07:20:16 +02:00
- Services services = Services.create(new YggdrasilAuthenticationService(Proxy.NO_PROXY), file);
2024-04-23 17:15:00 +02:00
- String s = (String) Optional.ofNullable((String) optionset.valueOf(optionspec10)).orElse(dedicatedserversettings.getProperties().levelName);
2022-10-22 14:47:45 +02:00
+ // Paper start - Detect headless JRE
+ String awtException = io.papermc.paper.util.ServerEnvironment.awtDependencyCheck();
+ if (awtException != null) {
+ Main.LOGGER.error("You are using a headless JRE distribution.");
+ Main.LOGGER.error("This distribution is missing certain graphic libraries that the Minecraft server needs to function.");
+ Main.LOGGER.error("For instructions on how to install the non-headless JRE, see https://docs.papermc.io/misc/java-install");
+ Main.LOGGER.error("");
+ Main.LOGGER.error(awtException);
+ return;
+ }
+ // Paper end - Detect headless JRE
+
2020-07-10 19:38:12 +02:00
+ org.spigotmc.SpigotConfig.disabledAdvancements = spigotConfiguration.getStringList("advancements.disabled"); // Paper - fix SPIGOT-5885, must be set early in init
2020-07-10 20:12:33 +02:00
+ // Paper start - fix SPIGOT-5824
+ File file;
+ File userCacheFile = new File(Services.USERID_CACHE_FILE);
+ if (optionset.has("universe")) {
+ file = (File) optionset.valueOf("universe"); // CraftBukkit
+ userCacheFile = new File(file, Services.USERID_CACHE_FILE);
+ } else {
+ file = new File(bukkitConfiguration.getString("settings.world-container", "."));
+ }
+ // Paper end - fix SPIGOT-5824
+ Services services = Services.create(new com.destroystokyo.paper.profile.PaperAuthenticationService(Proxy.NO_PROXY), file, userCacheFile, optionset); // Paper - pass OptionSet to load paper config files; override authentication service; fix world-container
2020-06-25 02:00:00 +02:00
+ // CraftBukkit start
2021-06-11 07:00:00 +02:00
+ String s = (String) Optional.ofNullable((String) optionset.valueOf("world")).orElse(dedicatedserversettings.getProperties().levelName);
2024-12-11 22:26:55 +01:00
LevelStorageSource convertable = LevelStorageSource.createDefault(file.toPath());
- LevelStorageSource.LevelStorageAccess convertable_conversionsession = convertable.validateAndCreateAccess(s);
+ LevelStorageSource.LevelStorageAccess convertable_conversionsession = convertable.validateAndCreateAccess(s, LevelStem.OVERWORLD);
2023-12-05 17:40:00 +01:00
+ // CraftBukkit end
Dynamic dynamic;
2020-06-25 02:00:00 +02:00
2023-12-05 17:40:00 +01:00
if (convertable_conversionsession.hasWorldData()) {
2022-10-22 14:47:45 +02:00
@@ -174,13 +238,31 @@
2021-06-11 07:00:00 +02:00
}
2023-12-05 17:40:00 +01:00
Dynamic<?> dynamic1 = dynamic;
2024-04-23 17:15:00 +02:00
- boolean flag = optionset.has(optionspec7);
2023-12-05 17:40:00 +01:00
+ boolean flag = optionset.has("safeMode"); // CraftBukkit
2020-06-25 02:00:00 +02:00
if (flag) {
Main.LOGGER.warn("Safe mode active, only vanilla datapack will be loaded");
2020-06-26 04:24:35 +02:00
}
2024-12-11 22:26:55 +01:00
PackRepository resourcepackrepository = ServerPacksSource.createPackRepository(convertable_conversionsession);
2020-06-26 04:24:35 +02:00
+ // CraftBukkit start
2024-12-11 22:26:55 +01:00
+ File bukkitDataPackFolder = new File(convertable_conversionsession.getLevelPath(LevelResource.DATAPACK_DIR).toFile(), "bukkit");
2020-06-26 04:24:35 +02: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"
2024-12-11 22:26:55 +01:00
+ + " \"pack_format\": " + SharedConstants.getCurrentVersion().getPackVersion(PackType.SERVER_DATA) + "\n"
2020-06-26 04:24:35 +02: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);
+ }
2024-12-11 22:26:55 +01:00
+ AtomicReference<WorldLoader.DataLoadContext> worldLoader = new AtomicReference<>();
2020-06-26 04:24:35 +02:00
+ // CraftBukkit end
2022-02-28 16:00:00 +01:00
WorldStem worldstem;
2022-10-22 14:47:45 +02:00
@@ -189,6 +271,7 @@
2022-12-07 17:00:00 +01:00
2024-12-11 22:26:55 +01:00
worldstem = (WorldStem) Util.blockUntilDone((executor) -> {
2022-12-07 17:00:00 +01:00
return WorldLoader.load(worldloader_c, (worldloader_a) -> {
+ worldLoader.set(worldloader_a); // CraftBukkit
2024-12-11 22:26:55 +01:00
Registry<LevelStem> iregistry = worldloader_a.datapackDimensions().lookupOrThrow(Registries.LEVEL_STEM);
2023-12-05 17:40:00 +01:00
if (dynamic1 != null) {
2022-10-22 14:47:45 +02:00
@@ -201,7 +284,7 @@
2022-12-07 17:00:00 +01: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());
2022-10-22 14:47:45 +02:00
@@ -209,7 +292,7 @@
2022-12-07 17:00:00 +01:00
DedicatedServerProperties dedicatedserverproperties = dedicatedserversettings.getProperties();
2024-12-11 22:26:55 +01:00
worldsettings = new LevelSettings(dedicatedserverproperties.levelName, dedicatedserverproperties.gamemode, dedicatedserverproperties.hardcore, dedicatedserverproperties.difficulty, false, new GameRules(worldloader_a.dataConfiguration().enabledFeatures()), worldloader_a.dataConfiguration());
2022-12-07 17:00:00 +01:00
- 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());
}
2023-04-07 20:11:17 +02:00
@@ -225,32 +308,47 @@
2022-06-07 18:00:00 +02:00
return;
2020-08-11 23:00:00 +02:00
}
2020-06-25 02:00:00 +02:00
2024-12-11 22:26:55 +01:00
- RegistryAccess.Frozen iregistrycustom_dimension = worldstem.registries().compositeAccess();
2020-06-25 02:00:00 +02:00
+ /*
2024-12-11 22:26:55 +01:00
+ IRegistryCustom.Dimension iregistrycustom_dimension = worldstem.registries().compositeAccess();
2024-04-23 17:15:00 +02:00
boolean flag1 = optionset.has(optionspec6);
2020-06-25 02:00:00 +02:00
2024-12-11 22:26:55 +01:00
if (optionset.has(optionspec4) || flag1) {
- Main.forceUpgrade(convertable_conversionsession, DataFixers.getDataFixer(), optionset.has(optionspec5), () -> {
+ forceUpgrade(convertable_conversionsession, DataConverterRegistry.getDataFixer(), optionset.has(optionspec5), () -> {
return true;
}, iregistrycustom_dimension, flag1);
}
- WorldData savedata = worldstem.worldData();
+ SaveData savedata = worldstem.worldData();
2020-06-25 02:00:00 +02:00
2022-02-28 16:00:00 +01:00
convertable_conversionsession.saveDataTag(iregistrycustom_dimension, savedata);
2020-06-25 02:00:00 +02:00
+ */
2021-11-21 23:00:00 +01:00
final DedicatedServer dedicatedserver = (DedicatedServer) MinecraftServer.spin((thread) -> {
2024-12-11 22:26:55 +01:00
- DedicatedServer dedicatedserver1 = new DedicatedServer(thread, convertable_conversionsession, resourcepackrepository, worldstem, dedicatedserversettings, DataFixers.getDataFixer(), services, LoggerChunkProgressListener::createFromGameruleRadius);
+ DedicatedServer dedicatedserver1 = new DedicatedServer(optionset, worldLoader.get(), thread, convertable_conversionsession, resourcepackrepository, worldstem, dedicatedserversettings, DataFixers.getDataFixer(), services, LoggerChunkProgressListener::createFromGameruleRadius);
2020-06-25 02:00:00 +02:00
+ /*
2024-04-23 17:15:00 +02:00
dedicatedserver1.setPort((Integer) optionset.valueOf(optionspec11));
2023-04-07 20:11:17 +02:00
- dedicatedserver1.setDemo(optionset.has(optionspec2));
+ */
+ dedicatedserver1.setDemo(optionset.has("demo")); // Paper
+ /*
2024-04-23 17:15:00 +02:00
dedicatedserver1.setId((String) optionset.valueOf(optionspec12));
- boolean flag2 = !optionset.has(optionspec) && !optionset.valuesOf(optionspec15).contains("nogui");
2020-06-25 02:00:00 +02:00
+ */
2024-04-23 17:15:00 +02:00
+ boolean flag2 = !optionset.has("nogui") && !optionset.nonOptionArguments().contains("nogui");
2020-06-25 02:00:00 +02:00
2021-05-17 09:34:55 +02:00
+ if(!Boolean.parseBoolean(System.getenv().getOrDefault("PAPER_DISABLE_SERVER_GUI", String.valueOf(false)))) // Paper - Add environment variable to disable server gui
2024-04-23 17:15:00 +02:00
if (flag2 && !GraphicsEnvironment.isHeadless()) {
2021-11-21 23:00:00 +01:00
dedicatedserver1.showGui();
2020-06-25 02:00:00 +02: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-21 23:00:00 +01:00
dedicatedserver.halt(true);
2023-04-07 20:11:17 +02:00
@@ -259,6 +357,7 @@
2020-06-25 02:00:00 +02:00
thread.setUncaughtExceptionHandler(new DefaultUncaughtExceptionHandler(Main.LOGGER));
Runtime.getRuntime().addShutdownHook(thread);
+ */ // CraftBukkit end
} catch (Exception exception1) {
2022-02-28 16:00:00 +01:00
Main.LOGGER.error(LogUtils.FATAL_MARKER, "Failed to start the minecraft server", exception1);
2020-06-25 02:00:00 +02:00
}
2023-04-07 20:11:17 +02:00
@@ -295,7 +394,7 @@
2020-06-25 02:00:00 +02:00
}
2024-12-11 22:26:55 +01:00
public static void forceUpgrade(LevelStorageSource.LevelStorageAccess session, DataFixer dataFixer, boolean eraseCache, BooleanSupplier continueCheck, RegistryAccess dynamicRegistryManager, boolean recreateRegionFiles) {
2020-06-25 02:00:00 +02:00
- Main.LOGGER.info("Forcing world upgrade!");
2024-12-11 22:26:55 +01:00
+ Main.LOGGER.info("Forcing world upgrade! {}", session.getLevelId()); // CraftBukkit
WorldUpgrader worldupgrader = new WorldUpgrader(session, dataFixer, dynamicRegistryManager, eraseCache, recreateRegionFiles);
2020-06-25 02:00:00 +02:00
2024-10-22 17:15:00 +02:00
try {