--- a/net/minecraft/server/Main.java +++ b/net/minecraft/server/Main.java @@ -57,6 +57,12 @@ import net.minecraft.world.level.storage.WorldInfo; import org.slf4j.Logger; +// CraftBukkit start +import java.util.concurrent.atomic.AtomicReference; +import net.minecraft.SharedConstants; +import net.minecraft.world.level.dimension.WorldDimension; +// CraftBukkit end + public class Main { private static final Logger LOGGER = LogUtils.getLogger(); @@ -64,8 +70,9 @@ public Main() {} @DontObfuscate - public static void main(String[] astring) { + public static void main(final OptionSet optionset) { // CraftBukkit - replaces main(String[] astring) 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"); @@ -90,9 +97,12 @@ optionparser.printHelpOn(System.err); return; } + */ // CraftBukkit end + + try { CrashReport.preload(); - if (optionset.has(optionspec13)) { + if (optionset.has("jfrProfile")) { // CraftBukkit JvmProfiler.INSTANCE.start(Environment.SERVER); } @@ -100,13 +110,13 @@ DispenserRegistry.validate(); SystemUtils.startTimerHackThread(); Path path = Paths.get("server.properties"); - DedicatedServerSettings dedicatedserversettings = new DedicatedServerSettings(path); + DedicatedServerSettings dedicatedserversettings = new DedicatedServerSettings(optionset); // CraftBukkit - CLI argument support dedicatedserversettings.forceSave(); Path path1 = Paths.get("eula.txt"); EULA eula = new EULA(path1); - if (optionset.has(optionspec1)) { + if (optionset.has("initSettings")) { // CraftBukkit Main.LOGGER.info("Initialized '{}' and '{}'", path.toAbsolutePath(), path1.toAbsolutePath()); return; } @@ -116,14 +126,15 @@ return; } - File file = new File((String) optionset.valueOf(optionspec9)); + File file = (File) optionset.valueOf("universe"); // CraftBukkit YggdrasilAuthenticationService yggdrasilauthenticationservice = new YggdrasilAuthenticationService(Proxy.NO_PROXY); MinecraftSessionService minecraftsessionservice = yggdrasilauthenticationservice.createMinecraftSessionService(); GameProfileRepository gameprofilerepository = yggdrasilauthenticationservice.createProfileRepository(); UserCache usercache = new UserCache(gameprofilerepository, new File(file, MinecraftServer.USERID_CACHE_FILE.getName())); - String s = (String) Optional.ofNullable((String) optionset.valueOf(optionspec10)).orElse(dedicatedserversettings.getProperties().levelName); + // CraftBukkit start + String s = (String) Optional.ofNullable((String) optionset.valueOf("world")).orElse(dedicatedserversettings.getProperties().levelName); Convertable convertable = Convertable.createDefault(file.toPath()); - Convertable.ConversionSession convertable_conversionsession = convertable.createAccess(s); + Convertable.ConversionSession convertable_conversionsession = convertable.createAccess(s, WorldDimension.OVERWORLD); WorldInfo worldinfo = convertable_conversionsession.getSummary(); if (worldinfo != null) { @@ -138,13 +149,32 @@ } } - boolean flag = optionset.has(optionspec6); + boolean flag = optionset.has("safeMode"); if (flag) { Main.LOGGER.warn("Safe mode active, only vanilla datapack will be loaded"); } ResourcePackRepository resourcepackrepository = new ResourcePackRepository(EnumResourcePackType.SERVER_DATA, new ResourcePackSource[]{new ResourcePackSourceVanilla(), new ResourcePackSourceFolder(convertable_conversionsession.getLevelPath(SavedFile.DATAPACK_DIR).toFile(), PackSource.WORLD)}); + // CraftBukkit start + File bukkitDataPackFolder = new File(convertable_conversionsession.getLevelPath(SavedFile.DATAPACK_DIR).toFile(), "bukkit"); + 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" + + " \"pack_format\": " + SharedConstants.getCurrentVersion().getPackVersion() + "\n" + + " }\n" + + "}\n", mcMeta, com.google.common.base.Charsets.UTF_8); + } catch (java.io.IOException ex) { + throw new RuntimeException("Could not initialize Bukkit datapack", ex); + } + AtomicReference config = new AtomicReference<>(); + AtomicReference> ops = new AtomicReference<>(); + // CraftBukkit end WorldStem worldstem; @@ -158,6 +188,12 @@ }, (iresourcemanager, datapackconfiguration) -> { IRegistryCustom.e iregistrycustom_e = IRegistryCustom.builtinCopy(); DynamicOps dynamicops = RegistryOps.createAndLoad(DynamicOpsNBT.INSTANCE, iregistrycustom_e, iresourcemanager); + // CraftBukkit start + config.set(datapackconfiguration); + ops.set(dynamicops); + return Pair.of(null, iregistrycustom_e.freeze()); + // CraftBukkit end + /* SaveData savedata = convertable_conversionsession.getDataTag(dynamicops, datapackconfiguration, iregistrycustom_e.allElementsLifecycle()); if (savedata != null) { @@ -180,6 +216,7 @@ return Pair.of(worlddataserver, iregistrycustom_e.freeze()); } + */ }, SystemUtils.backgroundExecutor(), Runnable::run).get(); } catch (Exception exception) { Main.LOGGER.warn("Failed to load datapacks, can't proceed with server load. You can either fix your datapacks or reset to vanilla with --safeMode", exception); @@ -188,6 +225,7 @@ } worldstem.updateGlobals(); + /* IRegistryCustom.Dimension iregistrycustom_dimension = worldstem.registryAccess(); dedicatedserversettings.getProperties().getWorldGenSettings(iregistrycustom_dimension); @@ -200,21 +238,32 @@ } convertable_conversionsession.saveDataTag(iregistrycustom_dimension, savedata); + */ final DedicatedServer dedicatedserver = (DedicatedServer) MinecraftServer.spin((thread) -> { - DedicatedServer dedicatedserver1 = new DedicatedServer(thread, convertable_conversionsession, resourcepackrepository, worldstem, dedicatedserversettings, DataConverterRegistry.getDataFixer(), minecraftsessionservice, gameprofilerepository, usercache, WorldLoadListenerLogger::new); + DedicatedServer dedicatedserver1 = new DedicatedServer(optionset, config.get(), ops.get(), thread, convertable_conversionsession, resourcepackrepository, worldstem, dedicatedserversettings, DataConverterRegistry.getDataFixer(), minecraftsessionservice, gameprofilerepository, usercache, WorldLoadListenerLogger::new); + /* dedicatedserver1.setSingleplayerName((String) optionset.valueOf(optionspec8)); dedicatedserver1.setPort((Integer) optionset.valueOf(optionspec11)); dedicatedserver1.setDemo(optionset.has(optionspec2)); dedicatedserver1.setId((String) optionset.valueOf(optionspec12)); - boolean flag1 = !optionset.has(optionspec) && !optionset.valuesOf(nonoptionargumentspec).contains("nogui"); + */ + boolean flag1 = !optionset.has("nogui") && !optionset.nonOptionArguments().contains("nogui"); if (flag1 && !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") { public void run() { dedicatedserver.halt(true); @@ -223,6 +272,7 @@ thread.setUncaughtExceptionHandler(new DefaultUncaughtExceptionHandler(Main.LOGGER)); Runtime.getRuntime().addShutdownHook(thread); + */ // CraftBukkit end } catch (Exception exception1) { Main.LOGGER.error(LogUtils.FATAL_MARKER, "Failed to start the minecraft server", exception1); } @@ -230,7 +280,7 @@ } public static void forceUpgrade(Convertable.ConversionSession convertable_conversionsession, DataFixer datafixer, boolean flag, BooleanSupplier booleansupplier, GeneratorSettings generatorsettings) { - Main.LOGGER.info("Forcing world upgrade!"); + Main.LOGGER.info("Forcing world upgrade! {}", convertable_conversionsession.getLevelId()); // CraftBukkit WorldUpgrader worldupgrader = new WorldUpgrader(convertable_conversionsession, datafixer, generatorsettings, flag); IChatBaseComponent ichatbasecomponent = null;