2020-06-25 02:00:00 +02:00
--- a/net/minecraft/server/Main.java
+++ b/net/minecraft/server/Main.java
2021-11-21 23:00:00 +01:00
@@ -56,6 +56,12 @@
2021-03-15 23:00:00 +01:00
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
+// CraftBukkit start
+import net.minecraft.SharedConstants;
+import net.minecraft.world.level.dimension.DimensionManager;
+import net.minecraft.world.level.dimension.WorldDimension;
+// CraftBukkit end
+
public class Main {
private static final Logger LOGGER = LogManager.getLogger();
2021-11-21 23:00:00 +01:00
@@ -63,8 +69,9 @@
2020-06-25 02:00:00 +02:00
public Main() {}
2021-06-11 07:00:00 +02:00
@DontObfuscate
2020-06-25 02:00:00 +02:00
- public static void main(String[] astring) {
+ 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");
2021-11-21 23:00:00 +01:00
@@ -89,9 +96,12 @@
2020-06-25 02:00:00 +02:00
optionparser.printHelpOn(System.err);
return;
}
+ */ // CraftBukkit end
2021-11-21 23:00:00 +01:00
+
2020-06-25 02:00:00 +02:00
+ try {
2021-11-21 23:00:00 +01:00
CrashReport.preload();
- if (optionset.has(optionspec13)) {
+ if (optionset.has("jfrProfile")) { // CraftBukkit
JvmProfiler.INSTANCE.start(Environment.SERVER);
}
@@ -100,13 +110,13 @@
SystemUtils.startTimerHackThread();
IRegistryCustom.Dimension iregistrycustom_dimension = IRegistryCustom.builtin();
2021-06-11 07:00:00 +02:00
Path path = Paths.get("server.properties");
- DedicatedServerSettings dedicatedserversettings = new DedicatedServerSettings(path);
+ 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();
2021-06-11 07:00:00 +02:00
Path path1 = Paths.get("eula.txt");
EULA eula = new EULA(path1);
2020-06-25 02:00:00 +02:00
- if (optionset.has(optionspec1)) {
+ if (optionset.has("initSettings")) { // CraftBukkit
2021-06-11 07:00:00 +02:00
Main.LOGGER.info("Initialized '{}' and '{}'", path.toAbsolutePath(), path1.toAbsolutePath());
2020-06-25 02:00:00 +02:00
return;
}
2021-11-21 23:00:00 +01:00
@@ -116,14 +126,15 @@
2020-06-25 02:00:00 +02:00
return;
}
- File file = new File((String) optionset.valueOf(optionspec9));
+ File file = (File) optionset.valueOf("universe"); // CraftBukkit
2020-11-02 21:00:00 +01:00
YggdrasilAuthenticationService yggdrasilauthenticationservice = new YggdrasilAuthenticationService(Proxy.NO_PROXY);
2020-06-25 02:00:00 +02:00
MinecraftSessionService minecraftsessionservice = yggdrasilauthenticationservice.createMinecraftSessionService();
GameProfileRepository gameprofilerepository = yggdrasilauthenticationservice.createProfileRepository();
2021-06-11 07:00:00 +02:00
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);
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);
2021-11-21 23:00:00 +01:00
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();
2020-06-25 02:00:00 +02:00
2021-11-21 23:00:00 +01:00
if (worldinfo != null) {
@@ -139,13 +150,30 @@
2021-06-11 07:00:00 +02:00
}
2021-11-21 23:00:00 +01:00
DataPackConfiguration datapackconfiguration = convertable_conversionsession.getDataPacks();
2020-06-25 02:00:00 +02:00
- boolean flag = optionset.has(optionspec6);
+ boolean flag = optionset.has("safeMode");
if (flag) {
Main.LOGGER.warn("Safe mode active, only vanilla datapack will be loaded");
2020-06-26 04:24:35 +02:00
}
2021-11-21 23:00:00 +01:00
ResourcePackRepository resourcepackrepository = new ResourcePackRepository(EnumResourcePackType.SERVER_DATA, new ResourcePackSource[]{new ResourcePackSourceVanilla(), new ResourcePackSourceFolder(convertable_conversionsession.getLevelPath(SavedFile.DATAPACK_DIR).toFile(), PackSource.WORLD)});
2020-06-26 04:24:35 +02:00
+ // CraftBukkit start
2021-11-21 23:00:00 +01:00
+ File bukkitDataPackFolder = new File(convertable_conversionsession.getLevelPath(SavedFile.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"
2021-11-21 23:00:00 +01:00
+ + " \"pack_format\": " + SharedConstants.getCurrentVersion().getPackVersion() + "\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);
+ }
+ // CraftBukkit end
2021-11-21 23:00:00 +01:00
DataPackConfiguration datapackconfiguration1 = MinecraftServer.configurePackRepository(resourcepackrepository, datapackconfiguration == null ? DataPackConfiguration.DEFAULT : datapackconfiguration, flag);
CompletableFuture completablefuture = DataPackResources.loadResources(resourcepackrepository.openAllSelected(), iregistrycustom_dimension, CommandDispatcher.ServerType.DEDICATED, dedicatedserversettings.getProperties().functionPermissionLevel, SystemUtils.backgroundExecutor(), Runnable::run);
2020-06-26 04:24:35 +02:00
2021-11-21 23:00:00 +01:00
@@ -160,6 +188,7 @@
2020-08-11 23:00:00 +02:00
}
2020-06-25 02:00:00 +02:00
2021-11-21 23:00:00 +01:00
datapackresources.updateGlobals();
2020-06-25 02:00:00 +02:00
+ /*
2021-11-21 23:00:00 +01:00
RegistryReadOps<NBTBase> registryreadops = RegistryReadOps.createAndLoad(DynamicOpsNBT.INSTANCE, datapackresources.getResourceManager(), iregistrycustom_dimension);
2020-06-25 02:00:00 +02:00
2021-11-21 23:00:00 +01:00
dedicatedserversettings.getProperties().getWorldGenSettings(iregistrycustom_dimension);
@@ -189,21 +218,32 @@
2020-06-25 02:00:00 +02:00
}
2021-11-21 23:00:00 +01:00
convertable_conversionsession.saveDataTag(iregistrycustom_dimension, (SaveData) object);
2020-06-25 02:00:00 +02:00
+ */
2021-11-21 23:00:00 +01:00
final DedicatedServer dedicatedserver = (DedicatedServer) MinecraftServer.spin((thread) -> {
- DedicatedServer dedicatedserver1 = new DedicatedServer(thread, iregistrycustom_dimension, convertable_conversionsession, resourcepackrepository, datapackresources, object, dedicatedserversettings, DataConverterRegistry.getDataFixer(), minecraftsessionservice, gameprofilerepository, usercache, WorldLoadListenerLogger::new);
+ DedicatedServer dedicatedserver1 = new DedicatedServer(optionset, datapackconfiguration1, thread, iregistrycustom_dimension, convertable_conversionsession, resourcepackrepository, datapackresources, null, dedicatedserversettings, DataConverterRegistry.getDataFixer(), minecraftsessionservice, gameprofilerepository, usercache, WorldLoadListenerLogger::new);
2020-06-25 02:00:00 +02:00
+ /*
2021-11-21 23:00:00 +01:00
dedicatedserver1.setSingleplayerName((String) optionset.valueOf(optionspec8));
2020-06-25 02:00:00 +02:00
dedicatedserver1.setPort((Integer) optionset.valueOf(optionspec11));
2021-11-21 23:00:00 +01:00
dedicatedserver1.setDemo(optionset.has(optionspec2));
dedicatedserver1.setId((String) optionset.valueOf(optionspec12));
2020-06-25 02:00:00 +02:00
- boolean flag1 = !optionset.has(optionspec) && !optionset.valuesOf(nonoptionargumentspec).contains("nogui");
+ */
+ boolean flag1 = !optionset.has("nogui") && !optionset.nonOptionArguments().contains("nogui");
if (flag1 && !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);
@@ -212,6 +252,7 @@
2020-06-25 02:00:00 +02:00
thread.setUncaughtExceptionHandler(new DefaultUncaughtExceptionHandler(Main.LOGGER));
Runtime.getRuntime().addShutdownHook(thread);
+ */ // CraftBukkit end
} catch (Exception exception1) {
Main.LOGGER.fatal("Failed to start the minecraft server", exception1);
}
2021-11-21 23:00:00 +01:00
@@ -219,7 +260,7 @@
2020-06-25 02:00:00 +02:00
}
2021-11-21 23:00:00 +01:00
public static void forceUpgrade(Convertable.ConversionSession convertable_conversionsession, DataFixer datafixer, boolean flag, BooleanSupplier booleansupplier, GeneratorSettings generatorsettings) {
2020-06-25 02:00:00 +02:00
- Main.LOGGER.info("Forcing world upgrade!");
2021-11-21 23:00:00 +01:00
+ Main.LOGGER.info("Forcing world upgrade! {}", convertable_conversionsession.getLevelId()); // CraftBukkit
WorldUpgrader worldupgrader = new WorldUpgrader(convertable_conversionsession, datafixer, generatorsettings, flag);
2020-06-25 02:00:00 +02:00
IChatBaseComponent ichatbasecomponent = null;