--- a/net/minecraft/server/Main.java +++ b/net/minecraft/server/Main.java @@ -63,40 +_,37 @@ public class Main { private static final Logger LOGGER = LogUtils.getLogger(); - @SuppressForbidden( - reason = "System.out needed before bootstrap" - ) + @SuppressWarnings("ConfusingMainMethod") // Plazma - replaced with org.bukkit.craftbukkit.Main#main + @SuppressForbidden(reason = "System.out needed before bootstrap") @DontObfuscate public static void main(final OptionSet optionSet) { // CraftBukkit - replaces main(String[] args) io.papermc.paper.util.LogManagerShutdownThread.hook(); // Paper - Improved watchdog support SharedConstants.tryDetectVersion(); - /* CraftBukkit start - Replace everything - OptionParser optionParser = new OptionParser(); - OptionSpec optionSpec = optionParser.accepts("nogui"); - OptionSpec optionSpec1 = optionParser.accepts("initSettings", "Initializes 'server.properties' and 'eula.txt', then quits"); - OptionSpec optionSpec2 = optionParser.accepts("demo"); - OptionSpec optionSpec3 = optionParser.accepts("bonusChest"); - OptionSpec optionSpec4 = optionParser.accepts("forceUpgrade"); - OptionSpec optionSpec5 = optionParser.accepts("eraseCache"); - OptionSpec optionSpec6 = optionParser.accepts("recreateRegionFiles"); - OptionSpec optionSpec7 = optionParser.accepts("safeMode", "Loads level with vanilla datapack only"); - OptionSpec optionSpec8 = optionParser.accepts("help").forHelp(); - OptionSpec optionSpec9 = optionParser.accepts("universe").withRequiredArg().defaultsTo("."); - OptionSpec optionSpec10 = optionParser.accepts("world").withRequiredArg(); - OptionSpec optionSpec11 = optionParser.accepts("port").withRequiredArg().ofType(Integer.class).defaultsTo(-1); - OptionSpec optionSpec12 = optionParser.accepts("serverId").withRequiredArg(); - OptionSpec optionSpec13 = optionParser.accepts("jfrProfile"); - OptionSpec optionSpec14 = optionParser.accepts("pidFile").withRequiredArg().withValuesConvertedBy(new PathConverter()); - OptionSpec optionSpec15 = optionParser.nonOptions(); try { - OptionSet optionSet = optionParser.parse(args); - if (optionSet.has(optionSpec8)) { - optionParser.printHelpOn(System.err); - return; + // Plazma start - Branding + System.out.println(""" + \033[38;2;215;23;133m█\033[38;2;212;24;134m█\033[38;2;209;26;134m█\033[38;2;205;27;135m█\033[38;2;202;28;136m█\033[38;2;199;30;136m█\033[38;2;196;31;137m╗\033[38;2;193;33;138m \033[38;2;190;34;138m█\033[38;2;186;35;139m█\033[38;2;183;37;140m╗\033[38;2;180;38;140m \033[38;2;177;39;141m \033[38;2;174;41;142m \033[38;2;170;42;142m \033[38;2;167;43;143m \033[38;2;164;45;144m \033[38;2;161;46;144m█\033[38;2;158;47;145m█\033[38;2;155;49;146m█\033[38;2;151;50;146m█\033[38;2;148;52;147m█\033[38;2;145;53;148m╗\033[38;2;142;54;148m \033[38;2;139;56;149m█\033[38;2;135;57;149m█\033[38;2;132;58;150m█\033[38;2;129;60;151m█\033[38;2;126;61;151m█\033[38;2;123;62;152m█\033[38;2;120;64;153m█\033[38;2;116;65;153m╗ \033[38;2;113;67;154m█\033[38;2;110;68;155m█\033[38;2;107;69;155m█\033[38;2;104;71;156m╗\033[38;2;101;72;157m \033[38;2;97;73;157m \033[38;2;94;75;158m \033[38;2;91;76;159m█\033[38;2;88;77;159m█\033[38;2;85;79;160m█\033[38;2;81;80;161m╗ \033[38;2;78;81;161m \033[38;2;75;83;162m█\033[38;2;72;84;163m█\033[38;2;69;86;163m█\033[38;2;66;87;164m█\033[38;2;62;88;165m█\033[38;2;59;90;165m╗\033[38;2;56;91;166m\s + \033[38;2;215;23;133m█\033[38;2;212;24;134m█\033[38;2;209;26;134m╔\033[38;2;205;27;135m═\033[38;2;202;28;136m═\033[38;2;199;30;136m█\033[38;2;196;31;137m█\033[38;2;193;33;138m╗ \033[38;2;190;34;138m█\033[38;2;186;35;139m█\033[38;2;183;37;140m║\033[38;2;180;38;140m \033[38;2;177;39;141m \033[38;2;174;41;142m \033[38;2;170;42;142m \033[38;2;167;43;143m \033[38;2;164;45;144m█\033[38;2;161;46;144m█\033[38;2;158;47;145m╔\033[38;2;155;49;146m═\033[38;2;151;50;146m═\033[38;2;148;52;147m█\033[38;2;145;53;148m█\033[38;2;142;54;148m╗ \033[38;2;139;56;149m╚\033[38;2;135;57;149m═\033[38;2;132;58;150m═\033[38;2;129;60;151m█\033[38;2;126;61;151m█\033[38;2;123;62;152m█\033[38;2;120;64;153m╔\033[38;2;116;65;153m╝ \033[38;2;113;67;154m█\033[38;2;110;68;155m█\033[38;2;107;69;155m█\033[38;2;104;71;156m█\033[38;2;101;72;157m╗\033[38;2;97;73;157m \033[38;2;94;75;158m█\033[38;2;91;76;159m█\033[38;2;88;77;159m█\033[38;2;85;79;160m█\033[38;2;81;80;161m║ \033[38;2;78;81;161m█\033[38;2;75;83;162m█\033[38;2;72;84;163m╔\033[38;2;69;86;163m═\033[38;2;66;87;164m═\033[38;2;62;88;165m█\033[38;2;59;90;165m█\033[38;2;56;91;166m╗ + \033[38;2;215;23;133m█\033[38;2;212;24;134m█\033[38;2;209;26;134m█\033[38;2;205;27;135m█\033[38;2;202;28;136m█\033[38;2;199;30;136m█\033[38;2;196;31;137m╔\033[38;2;193;33;138m╝ \033[38;2;190;34;138m█\033[38;2;186;35;139m█\033[38;2;183;37;140m║\033[38;2;180;38;140m \033[38;2;177;39;141m \033[38;2;174;41;142m \033[38;2;170;42;142m \033[38;2;167;43;143m \033[38;2;164;45;144m█\033[38;2;161;46;144m█\033[38;2;158;47;145m█\033[38;2;155;49;146m█\033[38;2;151;50;146m█\033[38;2;148;52;147m█\033[38;2;145;53;148m█\033[38;2;142;54;148m║ \033[38;2;139;56;149m \033[38;2;135;57;149m \033[38;2;132;58;150m█\033[38;2;129;60;151m█\033[38;2;126;61;151m█\033[38;2;123;62;152m╔\033[38;2;120;64;153m╝\033[38;2;116;65;153m \033[38;2;113;67;154m█\033[38;2;110;68;155m█\033[38;2;107;69;155m╔\033[38;2;104;71;156m█\033[38;2;101;72;157m█\033[38;2;97;73;157m█\033[38;2;94;75;158m█\033[38;2;91;76;159m╔\033[38;2;88;77;159m█\033[38;2;85;79;160m█\033[38;2;81;80;161m║ \033[38;2;78;81;161m█\033[38;2;75;83;162m█\033[38;2;72;84;163m█\033[38;2;69;86;163m█\033[38;2;66;87;164m█\033[38;2;62;88;165m█\033[38;2;59;90;165m█\033[38;2;56;91;166m║ + \033[38;2;215;23;133m█\033[38;2;212;24;134m█\033[38;2;209;26;134m╔\033[38;2;205;27;135m═\033[38;2;202;28;136m═\033[38;2;199;30;136m═\033[38;2;196;31;137m╝\033[38;2;193;33;138m \033[38;2;190;34;138m█\033[38;2;186;35;139m█\033[38;2;183;37;140m║\033[38;2;180;38;140m \033[38;2;177;39;141m \033[38;2;174;41;142m \033[38;2;170;42;142m \033[38;2;167;43;143m \033[38;2;164;45;144m█\033[38;2;161;46;144m█\033[38;2;158;47;145m╔\033[38;2;155;49;146m═\033[38;2;151;50;146m═\033[38;2;148;52;147m█\033[38;2;145;53;148m█\033[38;2;142;54;148m║ \033[38;2;139;56;149m \033[38;2;135;57;149m█\033[38;2;132;58;150m█\033[38;2;129;60;151m█\033[38;2;126;61;151m╔\033[38;2;123;62;152m╝\033[38;2;120;64;153m \033[38;2;116;65;153m \033[38;2;113;67;154m█\033[38;2;110;68;155m█\033[38;2;107;69;155m║\033[38;2;104;71;156m╚\033[38;2;101;72;157m█\033[38;2;97;73;157m█\033[38;2;94;75;158m╔\033[38;2;91;76;159m╝\033[38;2;88;77;159m█\033[38;2;85;79;160m█\033[38;2;81;80;161m║ \033[38;2;78;81;161m█\033[38;2;75;83;162m█\033[38;2;72;84;163m╔\033[38;2;69;86;163m═\033[38;2;66;87;164m═\033[38;2;62;88;165m█\033[38;2;59;90;165m█\033[38;2;56;91;166m║ + \033[38;2;215;23;133m█\033[38;2;212;24;134m█\033[38;2;209;26;134m║\033[38;2;205;27;135m \033[38;2;202;28;136m \033[38;2;199;30;136m \033[38;2;196;31;137m \033[38;2;193;33;138m \033[38;2;190;34;138m█\033[38;2;186;35;139m█\033[38;2;183;37;140m█\033[38;2;180;38;140m█\033[38;2;177;39;141m█\033[38;2;174;41;142m█\033[38;2;170;42;142m█\033[38;2;167;43;143m╗ \033[38;2;164;45;144m█\033[38;2;161;46;144m█\033[38;2;158;47;145m║\033[38;2;155;49;146m \033[38;2;151;50;146m \033[38;2;148;52;147m█\033[38;2;145;53;148m█\033[38;2;142;54;148m║ \033[38;2;139;56;149m█\033[38;2;135;57;149m█\033[38;2;132;58;150m█\033[38;2;129;60;151m█\033[38;2;126;61;151m█\033[38;2;123;62;152m█\033[38;2;120;64;153m█\033[38;2;116;65;153m╗ \033[38;2;113;67;154m█\033[38;2;110;68;155m█\033[38;2;107;69;155m║\033[38;2;104;71;156m \033[38;2;101;72;157m╚\033[38;2;97;73;157m═\033[38;2;94;75;158m╝\033[38;2;91;76;159m \033[38;2;88;77;159m█\033[38;2;85;79;160m█\033[38;2;81;80;161m║ \033[38;2;78;81;161m█\033[38;2;75;83;162m█\033[38;2;72;84;163m║\033[38;2;69;86;163m \033[38;2;66;87;164m \033[38;2;62;88;165m█\033[38;2;59;90;165m█\033[38;2;56;91;166m║ + \033[38;2;215;23;133m╚\033[38;2;212;24;134m═\033[38;2;209;26;134m╝\033[38;2;205;27;135m \033[38;2;202;28;136m \033[38;2;199;30;136m \033[38;2;196;31;137m \033[38;2;193;33;138m \033[38;2;190;34;138m╚\033[38;2;186;35;139m═\033[38;2;183;37;140m═\033[38;2;180;38;140m═\033[38;2;177;39;141m═\033[38;2;174;41;142m═\033[38;2;170;42;142m═\033[38;2;167;43;143m╝ \033[38;2;164;45;144m╚\033[38;2;161;46;144m═\033[38;2;158;47;145m╝\033[38;2;155;49;146m \033[38;2;151;50;146m \033[38;2;148;52;147m╚\033[38;2;145;53;148m═\033[38;2;142;54;148m╝ \033[38;2;139;56;149m╚\033[38;2;135;57;149m═\033[38;2;132;58;150m═\033[38;2;129;60;151m═\033[38;2;126;61;151m═\033[38;2;123;62;152m═\033[38;2;120;64;153m═\033[38;2;116;65;153m╝ \033[38;2;113;67;154m╚\033[38;2;110;68;155m═\033[38;2;107;69;155m╝\033[38;2;104;71;156m \033[38;2;101;72;157m \033[38;2;97;73;157m \033[38;2;94;75;158m \033[38;2;91;76;159m \033[38;2;88;77;159m╚\033[38;2;85;79;160m═\033[38;2;81;80;161m╝ \033[38;2;78;81;161m╚\033[38;2;75;83;162m═\033[38;2;72;84;163m╝\033[38;2;69;86;163m \033[38;2;66;87;164m \033[38;2;62;88;165m╚\033[38;2;59;90;165m═\033[38;2;56;91;166m╝\033[0m + """); + // Plazma end - Branding + + // Plazma start - Warn on startup + if (!org.plazmamc.plazma.Options.NO_WARN) { + LOGGER.warn("WARNING! Plazma may cause unexpected problems, so be sure to test it thoroughly before using it on a public server."); + if (!org.plazmamc.plazma.Options.NO_WARN_DEV) { + LOGGER.error("*********************** CAUTION ***********************"); + LOGGER.error("This version is a development version of Plazma."); + LOGGER.error("Nobody knows what kind of problem you're going to have, and there's always the possibility of unexpected problems."); + LOGGER.error("Never use this version on a public server, and after you've tested it enough before using it!"); + LOGGER.error("*******************************************************"); + } } - */ // CraftBukkit end - try { + // Plazma end - Warn on startup Path path = (Path) optionSet.valueOf("pidFile"); // CraftBukkit if (path != null) { @@ -118,16 +_,20 @@ Bootstrap.bootStrap(); Bootstrap.validate(); Util.startTimerHackThread(); - Path path1 = Paths.get("server.properties"); + + Path serverProperties = Paths.get("server.properties"); // Plazma DedicatedServerSettings dedicatedServerSettings = new DedicatedServerSettings(optionSet); // CraftBukkit - CLI argument support dedicatedServerSettings.forceSave(); RegionFileVersion.configure(dedicatedServerSettings.getProperties().regionFileComression); - Path path2 = Paths.get("eula.txt"); - Eula eula = new Eula(path2); + + Path eulaTxt = Paths.get("eula.txt"); // Plazma + Eula eula = new Eula(eulaTxt); // Plazma + // 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 + 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"); @@ -142,7 +_,7 @@ commandsConfiguration.setDefaults(org.bukkit.configuration.file.YamlConfiguration.loadConfiguration(new java.io.InputStreamReader(Main.class.getClassLoader().getResourceAsStream("configurations/commands.yml"), com.google.common.base.Charsets.UTF_8))); commandsConfiguration.save(commandFile); // CraftBukkit end - LOGGER.info("Initialized '{}' and '{}'", path1.toAbsolutePath(), path2.toAbsolutePath()); + LOGGER.info("Initialized '{}' and '{}'", serverProperties.toAbsolutePath(), eulaTxt.toAbsolutePath()); // Plazma return; } @@ -152,8 +_,7 @@ LOGGER.error("You have used the Spigot command line EULA agreement flag."); LOGGER.error("By using this setting you are indicating your agreement to Mojang's EULA (https://aka.ms/MinecraftEULA)."); LOGGER.error("If you do not agree to the above EULA please stop your server and remove this flag immediately."); - } - if (!eula.hasAgreedToEULA() && !eulaAgreed) { + } else if (!eula.hasAgreedToEULA()) { // Plazma // Spigot end LOGGER.info("You need to agree to the EULA in order to run the server. Go to eula.txt for more info."); return; @@ -171,27 +_,43 @@ } // Paper end - Detect headless JRE - org.spigotmc.SpigotConfig.disabledAdvancements = spigotConfiguration.getStringList("advancements.disabled"); // Paper - fix SPIGOT-5885, must be set early in init - // Paper start - fix SPIGOT-5824 - File file; - File userCacheFile = new File(Services.USERID_CACHE_FILE); + final File worldDir; // Plazma if (optionSet.has("universe")) { - file = (File) optionSet.valueOf("universe"); // CraftBukkit - userCacheFile = new File(file, Services.USERID_CACHE_FILE); + worldDir = (File) optionSet.valueOf("universe"); // CraftBukkit // Plazma } else { - file = new File(bukkitConfiguration.getString("settings.world-container", ".")); + worldDir = new File(bukkitConfiguration.getString("settings.world-container", ".")); // Plazma } // 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 - // CraftBukkit start - String string = Optional.ofNullable((String) optionSet.valueOf("world")).orElse(dedicatedServerSettings.getProperties().levelName); - LevelStorageSource levelStorageSource = LevelStorageSource.createDefault(file.toPath()); - LevelStorageSource.LevelStorageAccess levelStorageAccess = levelStorageSource.validateAndCreateAccess(string, LevelStem.OVERWORLD); - // CraftBukkit end - Dynamic dataTag; + + // Plazma start - Configurable usercache.json file path + final File userCacheFile; // Plazma - Moved down + if (optionSet.has("usercache")) { + userCacheFile = (File) optionSet.valueOf("usercache"); + } else { + final @Nullable String bukkit = bukkitConfiguration.getString("settings.user-cache"); + if (bukkit != null && !bukkit.isBlank()) { + userCacheFile = new File(bukkit); + } else { + userCacheFile = new File(worldDir, Services.USERID_CACHE_FILE); + } + } + // Plazma end - Configurable usercache.json file path + + org.spigotmc.SpigotConfig.disabledAdvancements = spigotConfiguration.getStringList("advancements.disabled"); // Paper - fix SPIGOT-5885, must be set early in init // Plazma - moved down + final Services services = Services.create(new com.destroystokyo.paper.profile.PaperAuthenticationService(Proxy.NO_PROXY), worldDir, userCacheFile, optionSet); // Paper - pass OptionSet to load paper config files; override authentication service; fix world-container // Plazma + + // CraftBukkit start // Plazma start - Improve variable name + final String levelPrefix = Optional.ofNullable((String) optionSet.valueOf("world")).orElse(dedicatedServerSettings.getProperties().levelName); + final LevelStorageSource levelStorageSource = LevelStorageSource.createDefault(worldDir.toPath()); + final LevelStorageSource.LevelStorageAccess levelStorageAccess = levelStorageSource.validateAndCreateAccess(levelPrefix, LevelStem.OVERWORLD); + // CraftBukkit end // Plazma end - Improve variable name + + final Dynamic dynamic; // Plazma - Moved up if (levelStorageAccess.hasWorldData()) { + Dynamic dataTag; // Plazma LevelSummary summary; + try { dataTag = levelStorageAccess.getDataTag(); summary = levelStorageAccess.getSummary(dataTag); @@ -225,163 +_,130 @@ LOGGER.info("This world was created by an incompatible version."); return; } + + dynamic = dataTag; // Plazma } else { - dataTag = null; + dynamic = null; // Plazma } - Dynamic dynamic = dataTag; - boolean hasOptionSpec = optionSet.has("safeMode"); // CraftBukkit - if (hasOptionSpec) { + final PackRepository packRepository = ServerPacksSource.createPackRepository(levelStorageAccess); // Plazma - moved up + final boolean safeMode = optionSet.has("safeMode"); // CraftBukkit // Plazma + if (safeMode) { // Plazma LOGGER.warn("Safe mode active, only vanilla datapack will be loaded"); } - PackRepository packRepository = ServerPacksSource.createPackRepository(levelStorageAccess); - // CraftBukkit start - File bukkitDataPackFolder = new File(levelStorageAccess.getLevelPath(net.minecraft.world.level.storage.LevelResource.DATAPACK_DIR).toFile(), "bukkit"); - if (!bukkitDataPackFolder.exists()) { - bukkitDataPackFolder.mkdirs(); - } - File mcMeta = new File(bukkitDataPackFolder, "pack.mcmeta"); + // CraftBukkit start // Plazma start - Improve code quality try { - com.google.common.io.Files.write("{\n" - + " \"pack\": {\n" - + " \"description\": \"Data pack for resources provided by Bukkit plugins\",\n" - + " \"pack_format\": " + SharedConstants.getCurrentVersion().getPackVersion(net.minecraft.server.packs.PackType.SERVER_DATA) + "\n" - + " }\n" - + "}\n", mcMeta, com.google.common.base.Charsets.UTF_8); + final File packDir = new File(levelStorageAccess.getLevelPath(net.minecraft.world.level.storage.LevelResource.DATAPACK_DIR).toFile(), "bukkit"); // Plazma + if (!packDir.exists() && !packDir.mkdirs()) { + throw new IOException("Unable to create Bukkit datapack folder"); + } + + final File mcMeta = new File(packDir, "pack.mcmeta"); + com.google.common.io.Files.asCharSink(mcMeta, com.google.common.base.Charsets.UTF_8).write(String.format(""" + { + "pack": { + "description": "Data pack for resources provided by Bukkit plugins", + "pack_format": %s + } + } + """, SharedConstants.getCurrentVersion().getPackVersion(net.minecraft.server.packs.PackType.SERVER_DATA))); } catch (java.io.IOException ex) { throw new RuntimeException("Could not initialize Bukkit datapack", ex); } - java.util.concurrent.atomic.AtomicReference worldLoader = new java.util.concurrent.atomic.AtomicReference<>(); - // CraftBukkit end + // CraftBukkit end // Plazma end - Improve code quality - WorldStem worldStem; + final WorldStem worldStem; // Plazma + final java.util.concurrent.atomic.AtomicReference worldLoader = new java.util.concurrent.atomic.AtomicReference<>(); // Plazma - moved down try { - WorldLoader.InitConfig initConfig = loadOrCreateConfig(dedicatedServerSettings.getProperties(), dynamic, hasOptionSpec, packRepository); - worldStem = Util.blockUntilDone( - executor -> WorldLoader.load( - initConfig, - context -> { - worldLoader.set(context); // CraftBukkit - Registry registry = context.datapackDimensions().lookupOrThrow(Registries.LEVEL_STEM); - if (dynamic != null) { - LevelDataAndDimensions levelDataAndDimensions = LevelStorageSource.getLevelDataAndDimensions( - dynamic, context.dataConfiguration(), registry, context.datapackWorldgen() - ); - return new WorldLoader.DataLoadOutput<>( - levelDataAndDimensions.worldData(), levelDataAndDimensions.dimensions().dimensionsRegistryAccess() - ); - } else { - LOGGER.info("No existing world data, creating new world"); - LevelSettings levelSettings; - WorldOptions worldOptions; - WorldDimensions worldDimensions; - if (optionSet.has("demo")) { // CraftBukkit - levelSettings = MinecraftServer.DEMO_SETTINGS; - worldOptions = WorldOptions.DEMO_OPTIONS; - worldDimensions = WorldPresets.createNormalWorldDimensions(context.datapackWorldgen()); - } else { - DedicatedServerProperties properties = dedicatedServerSettings.getProperties(); - levelSettings = new LevelSettings( - properties.levelName, - properties.gamemode, - properties.hardcore, - properties.difficulty, - false, - new GameRules(context.dataConfiguration().enabledFeatures()), - context.dataConfiguration() - ); - worldOptions = optionSet.has("bonusChest") ? properties.worldOptions.withBonusChest(true) : properties.worldOptions; // CraftBukkit - worldDimensions = properties.createDimensions(context.datapackWorldgen()); - } - - WorldDimensions.Complete complete = worldDimensions.bake(registry); - Lifecycle lifecycle = complete.lifecycle().add(context.datapackWorldgen().allRegistriesLifecycle()); - return new WorldLoader.DataLoadOutput<>( - new PrimaryLevelData(levelSettings, worldOptions, complete.specialWorldProperty(), lifecycle), - complete.dimensionsRegistryAccess() - ); - } - }, - WorldStem::new, - Util.backgroundExecutor(), - executor - ) - ) - .get(); - } catch (Exception var39) { - LOGGER.warn( - "Failed to load datapacks, can't proceed with server load. You can either fix your datapacks or reset to vanilla with --safeMode", - (Throwable)var39 - ); - return; - } - - /* - RegistryAccess.Frozen frozen = worldStem.registries().compositeAccess(); - boolean hasOptionSpec1 = optionSet.has(optionSpec6); - if (optionSet.has(optionSpec4) || hasOptionSpec1) { - forceUpgrade(levelStorageAccess, DataFixers.getDataFixer(), optionSet.has(optionSpec5), () -> true, frozen, hasOptionSpec1); - } - - WorldData worldData = worldStem.worldData(); - levelStorageAccess.saveDataTag(frozen, worldData); - */ - Class.forName(net.minecraft.world.entity.npc.VillagerTrades.class.getName()); // Paper - load this sync so it won't fail later async - final DedicatedServer dedicatedServer = MinecraftServer.spin( - thread1 -> { - DedicatedServer dedicatedServer1 = new DedicatedServer( - // CraftBukkit start - optionSet, - worldLoader.get(), - thread1, - levelStorageAccess, - packRepository, - worldStem, - dedicatedServerSettings, - DataFixers.getDataFixer(), - services, - LoggerChunkProgressListener::createFromGameruleRadius + WorldLoader.InitConfig initConfig = loadOrCreateConfig(dedicatedServerSettings.getProperties(), dynamic, safeMode, packRepository); // Plazma + worldStem = Util.blockUntilDone((executor) -> WorldLoader.load(initConfig, (context) -> { + worldLoader.set(context); // CraftBukkit + Registry registry = context.datapackDimensions().lookupOrThrow(Registries.LEVEL_STEM); + if (dynamic != null) { + LevelDataAndDimensions levelDataAndDimensions = LevelStorageSource.getLevelDataAndDimensions( + dynamic, context.dataConfiguration(), registry, context.datapackWorldgen() + ); + return new WorldLoader.DataLoadOutput<>( + levelDataAndDimensions.worldData(), levelDataAndDimensions.dimensions().dimensionsRegistryAccess() + ); + } + + LOGGER.info("No existing world data, creating new world"); + LevelSettings levelSettings; + WorldOptions worldOptions; + WorldDimensions worldDimensions; + if (optionSet.has("demo")) { // CraftBukkit + levelSettings = MinecraftServer.DEMO_SETTINGS; + worldOptions = WorldOptions.DEMO_OPTIONS; + worldDimensions = WorldPresets.createNormalWorldDimensions(context.datapackWorldgen()); + } else { + DedicatedServerProperties properties = dedicatedServerSettings.getProperties(); + levelSettings = new LevelSettings( + properties.levelName, + properties.gamemode, + properties.hardcore, + properties.difficulty, + false, + new GameRules(context.dataConfiguration().enabledFeatures()), + context.dataConfiguration() + ); + worldOptions = optionSet.has("bonusChest") ? properties.worldOptions.withBonusChest(true) : properties.worldOptions; // CraftBukkit + worldDimensions = properties.createDimensions(context.datapackWorldgen()); + } + + WorldDimensions.Complete complete = worldDimensions.bake(registry); + Lifecycle lifecycle = complete.lifecycle().add(context.datapackWorldgen().allRegistriesLifecycle()); + return new WorldLoader.DataLoadOutput<>( + new PrimaryLevelData(levelSettings, worldOptions, complete.specialWorldProperty(), lifecycle), + complete.dimensionsRegistryAccess() ); - /* - dedicatedServer1.setPort(optionSet.valueOf(optionSpec11)); - */ - // Paper start - if (optionSet.has("serverId")) { - dedicatedServer1.setId((String) optionSet.valueOf("serverId")); - } - dedicatedServer1.setDemo(optionSet.has("demo")); - // Paper end - /* - dedicatedServer1.setId(optionSet.valueOf(optionSpec12)); - */ - boolean flag = !optionSet.has("nogui") && !optionSet.nonOptionArguments().contains("nogui"); - if (flag && !GraphicsEnvironment.isHeadless()) { - dedicatedServer1.showGui(); - } - - 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") { - @Override - public void run() { - dedicatedServer.halt(true); - } - }; - thread.setUncaughtExceptionHandler(new DefaultUncaughtExceptionHandler(LOGGER)); - Runtime.getRuntime().addShutdownHook(thread); - */ // CraftBukkit end + }, WorldStem::new, Util.backgroundExecutor(), executor)).get(); + } catch (final Exception e) { // Plazma + LOGGER.warn("Failed to load datapacks, can't proceed with server load. You can either fix your datapacks or reset to vanilla with --safeMode", e); // Plazma + return; + } + + Class.forName(net.minecraft.world.entity.npc.VillagerTrades.class.getName()); // Paper - load this sync so it won't fail later async + + // Plazma start - Improve code quality + // noinspection resource + MinecraftServer.spin(thread -> { + final DedicatedServer server = new DedicatedServer( + // CraftBukkit start + optionSet, + worldLoader.get(), + thread, + levelStorageAccess, + packRepository, + worldStem, + dedicatedServerSettings, + DataFixers.getDataFixer(), + services, + LoggerChunkProgressListener::createFromGameruleRadius + ); + + // Paper start + if (optionSet.has("serverId")) { + server.setId((String) optionSet.valueOf("serverId")); + } + dedicatedServer1.setDemo(optionSet.has("demo")); + // Paper end + + if (!optionSet.has("nogui") && !optionSet.nonOptionArguments().contains("nogui") && !GraphicsEnvironment.isHeadless()) { + server.showGui(); + } + + if (optionSet.has("port")) { + int port = (Integer) optionSet.valueOf("port"); + if (port > 0) server.setPort(port); + } + + return server; + }); + // Plazma end - Improve code quality } catch (Exception var42) { - LOGGER.error(LogUtils.FATAL_MARKER, "Failed to start the minecraft server", (Throwable)var42); + LOGGER.error(LogUtils.FATAL_MARKER, "Failed to start the minecraft server", var42); // Plazma - Remove unnecessary type casting } } @@ -443,7 +_,7 @@ } else { try { Thread.sleep(1000L); - } catch (InterruptedException var12) { + } catch (InterruptedException ignore) { // Plazma - Fix IDE warning } } }