2015-05-25 12:37:24 +02:00
--- a/net/minecraft/server/MinecraftServer.java
+++ b/net/minecraft/server/MinecraftServer.java
2019-07-20 01:00:00 +02:00
@@ -56,6 +56,13 @@
2016-07-15 12:08:04 +02:00
import org.apache.commons.lang3.Validate;
2016-05-10 13:47:39 +02:00
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
+// CraftBukkit start
2016-07-15 12:08:04 +02:00
+import jline.console.ConsoleReader;
2016-02-29 22:32:46 +01:00
+import org.bukkit.Bukkit;
+import org.bukkit.craftbukkit.CraftServer;
2016-07-15 12:08:04 +02:00
+import org.bukkit.craftbukkit.Main;
2018-09-08 05:37:15 +02:00
+import org.bukkit.event.server.ServerLoadEvent;
2016-02-29 22:32:46 +01:00
+// CraftBukkit end
2016-07-15 12:08:04 +02:00
2019-04-23 04:00:00 +02:00
public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTask> implements IMojangStatistics, ICommandListener, AutoCloseable, Runnable {
2015-02-26 23:41:06 +01:00
2019-07-20 01:00:00 +02:00
@@ -75,7 +82,7 @@
2019-01-05 07:05:51 +01:00
public final DataFixer dataConverterManager;
private String serverIp;
2019-04-23 04:00:00 +02:00
private int serverPort = -1;
2019-01-05 07:05:51 +01:00
- public final Map<DimensionManager, WorldServer> worldServer = Maps.newIdentityHashMap();
+ public final Map<DimensionManager, WorldServer> worldServer = Maps.newLinkedHashMap(); // CraftBukkit - keep order, k+v already use identity methods
private PlayerList playerList;
2019-04-23 04:00:00 +02:00
private volatile boolean isRunning = true;
2019-01-05 07:05:51 +01:00
private boolean isStopped;
2019-07-20 01:00:00 +02:00
@@ -113,7 +120,7 @@
2019-04-23 04:00:00 +02:00
private final GameProfileRepository gameProfileRepository;
private final UserCache userCache;
2019-07-20 01:00:00 +02:00
private long Z;
2019-04-23 04:00:00 +02:00
- public final Thread serverThread = (Thread) SystemUtils.a((Object) (new Thread(this, "Server thread")), (thread) -> {
+ public final Thread serverThread = (Thread) SystemUtils.a((new Thread(this, "Server thread")), (thread) -> { // CraftBukkit - decompile error
thread.setUncaughtExceptionHandler((thread1, throwable) -> {
MinecraftServer.LOGGER.error(throwable);
});
2019-12-10 23:00:00 +01:00
@@ -145,7 +152,21 @@
2019-04-23 04:00:00 +02:00
@Nullable
2019-12-10 23:00:00 +01:00
private String ax;
2014-11-25 22:32:16 +01:00
2019-04-23 04:00:00 +02:00
- public MinecraftServer(File file, Proxy proxy, DataFixer datafixer, CommandDispatcher commanddispatcher, YggdrasilAuthenticationService yggdrasilauthenticationservice, MinecraftSessionService minecraftsessionservice, GameProfileRepository gameprofilerepository, UserCache usercache, WorldLoadListenerFactory worldloadlistenerfactory, String s) {
2014-11-25 22:32:16 +01:00
+ // CraftBukkit start
+ public org.bukkit.craftbukkit.CraftServer server;
+ public OptionSet options;
+ public org.bukkit.command.ConsoleCommandSender console;
+ public org.bukkit.command.RemoteConsoleCommandSender remoteConsole;
+ public ConsoleReader reader;
+ public static int currentTick = (int) (System.currentTimeMillis() / 50);
+ public java.util.Queue<Runnable> processQueue = new java.util.concurrent.ConcurrentLinkedQueue<Runnable>();
+ public int autosavePeriod;
2018-07-15 02:00:00 +02:00
+ public File bukkitDataPackFolder;
2018-07-21 03:20:38 +02:00
+ public CommandDispatcher vanillaCommandDispatcher;
2019-04-25 07:33:13 +02:00
+ private boolean forceTicks;
2014-11-25 22:32:16 +01:00
+ // CraftBukkit end
+
2019-04-23 04:00:00 +02:00
+ public MinecraftServer(OptionSet options, Proxy proxy, DataFixer datafixer, CommandDispatcher commanddispatcher, YggdrasilAuthenticationService yggdrasilauthenticationservice, MinecraftSessionService minecraftsessionservice, GameProfileRepository gameprofilerepository, UserCache usercache, WorldLoadListenerFactory worldloadlistenerfactory, String s) {
super("Server");
2019-07-20 01:00:00 +02:00
this.ae = new ResourceManager(EnumResourcePackType.SERVER_DATA, this.serverThread);
2018-12-25 22:00:00 +01:00
this.resourcePackRepository = new ResourcePackRepository<>(ResourcePackLoader::new);
2019-12-10 23:00:00 +01:00
@@ -159,15 +180,15 @@
this.customFunctionData = new CustomFunctionData(this);
this.circularTimer = new CircularTimer();
2019-04-23 04:00:00 +02:00
this.proxy = proxy;
2018-07-15 02:00:00 +02:00
- this.commandDispatcher = commanddispatcher;
2018-07-21 03:20:38 +02:00
+ this.commandDispatcher = this.vanillaCommandDispatcher = commanddispatcher; // CraftBukkit
2019-04-23 04:00:00 +02:00
this.yggdrasilAuthenticationService = yggdrasilauthenticationservice;
this.minecraftSessionService = minecraftsessionservice;
this.gameProfileRepository = gameprofilerepository;
this.userCache = usercache;
2014-11-25 22:32:16 +01:00
- this.universe = file;
2019-04-23 04:00:00 +02:00
- this.serverConnection = new ServerConnection(this);
2014-11-25 22:32:16 +01:00
+ // this.universe = file; // CraftBukkit
2018-12-13 01:00:00 +01:00
+ this.serverConnection = new ServerConnection(this); // CraftBukkit
2019-04-23 04:00:00 +02:00
this.worldLoadListenerFactory = worldloadlistenerfactory;
- this.convertable = new Convertable(file.toPath(), file.toPath().resolve("../backups"), datafixer);
+ // this.convertable = new Convertable(file.toPath(), file.toPath().resolve("../backups"), datafixer); // CraftBukkit - moved to DedicatedServer.init
2018-07-15 02:00:00 +02:00
this.dataConverterManager = datafixer;
2019-12-10 23:00:00 +01:00
this.ae.a((IReloadListener) this.tagRegistry);
this.ae.a((IReloadListener) this.lootPredicateManager);
@@ -177,7 +198,32 @@
this.ae.a((IReloadListener) this.advancementDataWorld);
2019-04-23 04:00:00 +02:00
this.executorService = SystemUtils.e();
2019-07-20 01:00:00 +02:00
this.K = s;
2014-11-25 22:32:16 +01:00
+ // CraftBukkit start
+ this.options = options;
+ // Try to see if we're actually running in a terminal, disable jline if not
2015-06-11 13:59:36 +02:00
+ if (System.console() == null && System.getProperty("jline.terminal") == null) {
2014-11-25 22:32:16 +01:00
+ System.setProperty("jline.terminal", "jline.UnsupportedTerminal");
+ Main.useJline = false;
+ }
+
+ try {
+ reader = new ConsoleReader(System.in, System.out);
+ reader.setExpandEvents(false); // Avoid parsing exceptions for uncommonly used event designators
+ } catch (Throwable e) {
+ try {
+ // Try again with jline disabled for Windows users without C++ 2008 Redistributable
+ System.setProperty("jline.terminal", "jline.UnsupportedTerminal");
+ System.setProperty("user.language", "en");
+ Main.useJline = false;
+ reader = new ConsoleReader(System.in, System.out);
+ reader.setExpandEvents(false);
+ } catch (IOException ex) {
+ LOGGER.warn((String) null, ex);
+ }
+ }
+ Runtime.getRuntime().addShutdownHook(new org.bukkit.craftbukkit.util.ServerShutdownThread(this));
}
+ // CraftBukkit end
2018-07-15 02:00:00 +02:00
2019-04-23 04:00:00 +02:00
private void initializeScoreboards(WorldPersistentData worldpersistentdata) {
PersistentScoreboard persistentscoreboard = (PersistentScoreboard) worldpersistentdata.a(PersistentScoreboard::new, "scoreboard");
2019-12-10 23:00:00 +01:00
@@ -213,11 +259,11 @@
2018-07-22 04:00:00 +02:00
}
if (this.forceUpgrade) {
- MinecraftServer.LOGGER.info("Forcing world upgrade!");
2019-04-23 04:00:00 +02:00
- WorldData worlddata = this.getConvertable().b(this.getWorld());
2018-07-22 04:00:00 +02:00
+ MinecraftServer.LOGGER.info("Forcing world upgrade! {}", s); // CraftBukkit
2019-04-23 04:00:00 +02:00
+ WorldData worlddata = this.getConvertable().b(s); // CraftBukkit
2018-07-22 04:00:00 +02:00
if (worlddata != null) {
2019-05-14 02:00:00 +02:00
- WorldUpgrader worldupgrader = new WorldUpgrader(this.getWorld(), this.getConvertable(), worlddata, this.eraseCache);
+ WorldUpgrader worldupgrader = new WorldUpgrader(s, this.getConvertable(), worlddata, this.eraseCache); // CraftBukkit
2018-07-22 04:00:00 +02:00
IChatBaseComponent ichatbasecomponent = null;
while (!worldupgrader.b()) {
2019-12-10 23:00:00 +01:00
@@ -256,8 +302,9 @@
2018-07-22 04:00:00 +02:00
}
2019-04-23 04:00:00 +02:00
protected void a(String s, String s1, long i, WorldType worldtype, JsonElement jsonelement) {
2018-07-22 04:00:00 +02:00
- this.convertWorld(s);
+ // this.convertWorld(s); // CraftBukkit - moved down
2018-07-15 02:00:00 +02:00
this.b((IChatBaseComponent) (new ChatMessage("menu.loadingLevel", new Object[0])));
2014-11-25 22:32:16 +01:00
+ /* CraftBukkit start - Remove ticktime arrays and worldsettings
2019-04-23 04:00:00 +02:00
WorldNBTStorage worldnbtstorage = this.getConvertable().a(s, this);
2014-11-25 22:32:16 +01:00
2019-04-23 04:00:00 +02:00
this.a(this.getWorld(), worldnbtstorage);
2020-01-21 22:00:00 +01:00
@@ -283,27 +330,137 @@
2018-07-15 02:00:00 +02:00
2020-01-21 22:00:00 +01:00
worlddata.a(this.getServerModName(), this.q().isPresent());
2019-04-23 04:00:00 +02:00
this.a(worldnbtstorage.getDirectory(), worlddata);
- WorldLoadListener worldloadlistener = this.worldLoadListenerFactory.create(11);
2014-11-25 22:32:16 +01:00
+ */
+ int worldCount = 3;
2019-04-23 04:00:00 +02:00
- this.a(worldnbtstorage, worlddata, worldsettings, worldloadlistener);
- this.a(this.getDifficulty(), true);
- this.loadSpawn(worldloadlistener);
2018-08-26 04:00:00 +02:00
- }
2014-11-25 22:32:16 +01:00
+ for (int j = 0; j < worldCount; ++j) {
+ WorldServer world;
2018-07-15 02:00:00 +02:00
+ WorldData worlddata;
2014-11-25 22:32:16 +01:00
+ byte dimension = 0;
2018-08-26 04:00:00 +02:00
+
+ if (j == 1) {
2014-11-25 22:32:16 +01:00
+ if (getAllowNether()) {
+ dimension = -1;
+ } else {
+ continue;
+ }
2018-08-26 04:00:00 +02:00
+ }
2019-12-10 23:00:00 +01:00
- protected void a(WorldNBTStorage worldnbtstorage, WorldData worlddata, WorldSettings worldsettings, WorldLoadListener worldloadlistener) {
- if (this.isDemoMode()) {
- worlddata.a(MinecraftServer.c);
2018-08-26 04:00:00 +02:00
+ if (j == 2) {
2014-11-25 22:32:16 +01:00
+ if (server.getAllowEnd()) {
+ dimension = 1;
+ } else {
+ continue;
+ }
2018-08-26 04:00:00 +02:00
+ }
2019-04-25 07:33:13 +02:00
+
2014-11-25 22:32:16 +01:00
+ String worldType = org.bukkit.World.Environment.getEnvironment(dimension).toString().toLowerCase();
+ String name = (dimension == 0) ? s : s + "_" + worldType;
2018-07-22 04:00:00 +02:00
+ this.convertWorld(name); // Run conversion now
2014-11-25 22:32:16 +01:00
+
+ org.bukkit.generator.ChunkGenerator gen = this.server.getGenerator(name);
+ WorldSettings worldsettings = new WorldSettings(i, this.getGamemode(), this.getGenerateStructures(), this.isHardcore(), worldtype);
2018-07-15 02:00:00 +02:00
+ worldsettings.setGeneratorSettings(jsonelement);
2014-11-25 22:32:16 +01:00
+
2018-08-26 04:00:00 +02:00
+ if (j == 0) {
2019-04-23 04:00:00 +02:00
+ WorldNBTStorage worldnbtstorage = new WorldNBTStorage(server.getWorldContainer(), s1, this, this.dataConverterManager);
+ worlddata = worldnbtstorage.getWorldData();
2014-11-25 22:32:16 +01:00
+ if (worlddata == null) {
+ worlddata = new WorldData(worldsettings, s1);
+ }
2014-11-29 20:33:33 +01:00
+ worlddata.checkName(s1); // CraftBukkit - Migration did not rewrite the level.dat; This forces 1.8 to take the last loaded world as respawn (in this case the end)
2019-04-23 04:00:00 +02:00
+ this.a(worldnbtstorage.getDirectory(), worlddata);
+ WorldLoadListener worldloadlistener = this.worldLoadListenerFactory.create(11);
+
+ if (this.isDemoMode()) {
+ worlddata.a(MinecraftServer.c);
2018-08-26 04:00:00 +02:00
+ }
2019-04-23 04:00:00 +02:00
+ world = new WorldServer(this, this.executorService, worldnbtstorage, worlddata, DimensionManager.OVERWORLD, this.methodProfiler, worldloadlistener, org.bukkit.World.Environment.getEnvironment(dimension), gen);
+
2019-12-10 23:00:00 +01:00
+ WorldPersistentData worldpersistentdata = world.getWorldPersistentData();
+ this.initializeScoreboards(worldpersistentdata);
2014-11-25 22:32:16 +01:00
+ this.server.scoreboardManager = new org.bukkit.craftbukkit.scoreboard.CraftScoreboardManager(this, world.getScoreboard());
2019-12-10 23:00:00 +01:00
+ this.persistentCommandStorage = new PersistentCommandStorage(worldpersistentdata);
2018-08-26 04:00:00 +02:00
+ } else {
2014-11-25 22:32:16 +01:00
+ String dim = "DIM" + dimension;
2019-05-04 12:54:32 +02:00
+
2018-12-25 22:00:00 +01:00
+ File newWorld = new File(new File(name), dim);
+ File oldWorld = new File(new File(s), dim);
2019-01-05 07:03:12 +01:00
+ File oldLevelDat = new File(new File(s), "level.dat"); // The data folders exist on first run as they are created in the PersistentCollection constructor above, but the level.dat won't
+
+ if (!newWorld.isDirectory() && oldWorld.isDirectory() && oldLevelDat.isFile()) {
2014-11-25 22:32:16 +01:00
+ MinecraftServer.LOGGER.info("---- Migration of old " + worldType + " folder required ----");
+ MinecraftServer.LOGGER.info("Unfortunately due to the way that Minecraft implemented multiworld support in 1.6, Bukkit requires that you move your " + worldType + " folder to a new location in order to operate correctly.");
+ MinecraftServer.LOGGER.info("We will move this folder for you, but it will mean that you need to move it back should you wish to stop using Bukkit in the future.");
+ MinecraftServer.LOGGER.info("Attempting to move " + oldWorld + " to " + newWorld + "...");
+
+ if (newWorld.exists()) {
+ MinecraftServer.LOGGER.warn("A file or folder already exists at " + newWorld + "!");
+ MinecraftServer.LOGGER.info("---- Migration of old " + worldType + " folder failed ----");
+ } else if (newWorld.getParentFile().mkdirs()) {
+ if (oldWorld.renameTo(newWorld)) {
+ MinecraftServer.LOGGER.info("Success! To restore " + worldType + " in the future, simply move " + newWorld + " to " + oldWorld);
+ // Migrate world data too.
+ try {
2019-01-05 07:03:12 +01:00
+ com.google.common.io.Files.copy(oldLevelDat, new File(new File(name), "level.dat"));
2016-06-30 07:13:32 +02:00
+ org.apache.commons.io.FileUtils.copyDirectory(new File(new File(s), "data"), new File(new File(name), "data"));
2014-11-25 22:32:16 +01:00
+ } catch (IOException exception) {
+ MinecraftServer.LOGGER.warn("Unable to migrate world data.");
+ }
+ MinecraftServer.LOGGER.info("---- Migration of old " + worldType + " folder complete ----");
+ } else {
+ MinecraftServer.LOGGER.warn("Could not move folder " + oldWorld + " to " + newWorld + "!");
+ MinecraftServer.LOGGER.info("---- Migration of old " + worldType + " folder failed ----");
+ }
+ } else {
+ MinecraftServer.LOGGER.warn("Could not create path for " + newWorld + "!");
+ MinecraftServer.LOGGER.info("---- Migration of old " + worldType + " folder failed ----");
+ }
+ }
2019-12-10 23:00:00 +01:00
+
2019-04-23 04:00:00 +02:00
+ WorldNBTStorage worldnbtstorage = new WorldNBTStorage(server.getWorldContainer(), name, this, this.dataConverterManager);
2014-11-25 22:32:16 +01:00
+ // world =, b0 to dimension, s1 to name, added Environment and gen
2019-04-23 04:00:00 +02:00
+ worlddata = worldnbtstorage.getWorldData();
2014-11-25 22:32:16 +01:00
+ if (worlddata == null) {
+ worlddata = new WorldData(worldsettings, name);
+ }
2014-11-29 20:33:33 +01:00
+ worlddata.checkName(name); // CraftBukkit - Migration did not rewrite the level.dat; This forces 1.8 to take the last loaded world as respawn (in this case the end)
2019-04-23 04:00:00 +02:00
+ WorldLoadListener worldloadlistener = this.worldLoadListenerFactory.create(11);
+ world = new SecondaryWorldServer(this.getWorldServer(DimensionManager.OVERWORLD), this, this.executorService, worldnbtstorage, DimensionManager.a(dimension), this.methodProfiler, worldloadlistener, worlddata, org.bukkit.World.Environment.getEnvironment(dimension), gen);
2018-08-26 04:00:00 +02:00
+ }
2019-04-23 04:00:00 +02:00
+
2019-05-07 01:36:36 +02:00
+ this.initWorld(world, worlddata, worldsettings);
2019-01-05 07:03:12 +01:00
+ this.server.getPluginManager().callEvent(new org.bukkit.event.world.WorldInitEvent(world.getWorld()));
+
2019-05-12 03:15:48 +02:00
+ this.worldServer.put(world.getWorldProvider().getDimensionManager(), world);
2019-01-05 07:03:12 +01:00
+ this.getPlayerList().setPlayerFileData(world);
2019-04-23 04:00:00 +02:00
+
+ if (worlddata.getCustomBossEvents() != null) {
2019-12-10 23:00:00 +01:00
+ this.getBossBattleCustomData().load(worlddata.getCustomBossEvents());
2018-07-15 02:00:00 +02:00
+ }
2019-05-04 12:54:32 +02:00
+ }
2019-04-23 04:00:00 +02:00
+ this.a(this.getDifficulty(), true);
+ for (WorldServer worldserver : this.getWorlds()) {
+ this.loadSpawn(worldserver.getChunkProvider().playerChunkMap.worldLoadListener, worldserver);
2019-05-02 07:15:53 +02:00
+ this.server.getPluginManager().callEvent(new org.bukkit.event.world.WorldLoadEvent(worldserver.getWorld()));
2019-05-04 12:54:32 +02:00
}
- WorldServer worldserver = new WorldServer(this, this.executorService, worldnbtstorage, worlddata, DimensionManager.OVERWORLD, this.methodProfiler, worldloadlistener);
2019-04-23 04:00:00 +02:00
+ this.server.enablePlugins(org.bukkit.plugin.PluginLoadOrder.POSTWORLD);
+ this.server.getPluginManager().callEvent(new ServerLoadEvent(ServerLoadEvent.LoadType.STARTUP));
2019-07-30 12:45:45 +02:00
+ this.serverConnection.acceptConnections();
2019-04-23 04:00:00 +02:00
+ // CraftBukkit end
2019-06-21 12:00:00 +02:00
- this.worldServer.put(DimensionManager.OVERWORLD, worldserver);
2019-12-10 23:00:00 +01:00
- WorldPersistentData worldpersistentdata = worldserver.getWorldPersistentData();
+ }
- this.initializeScoreboards(worldpersistentdata);
- this.persistentCommandStorage = new PersistentCommandStorage(worldpersistentdata);
2019-06-21 12:00:00 +02:00
- worldserver.getWorldBorder().b(worlddata);
- WorldServer worldserver1 = this.getWorldServer(DimensionManager.OVERWORLD);
2019-06-25 13:02:13 +02:00
+ // CraftBukkit start
+ public void initWorld(WorldServer worldserver1, WorldData worlddata, WorldSettings worldsettings) {
+ worldserver1.getWorldBorder().b(worlddata);
+
2019-04-23 04:00:00 +02:00
+ // CraftBukkit start
+ if (worldserver1.generator != null) {
+ worldserver1.getWorld().getPopulators().addAll(worldserver1.generator.getDefaultPopulators(worldserver1.getWorld()));
+ }
2014-11-25 22:32:16 +01:00
+ // CraftBukkit end
2018-07-15 02:00:00 +02:00
2019-06-21 12:00:00 +02:00
if (!worlddata.u()) {
2019-04-23 04:00:00 +02:00
try {
2020-01-21 22:00:00 +01:00
@@ -327,23 +484,8 @@
2019-04-23 04:00:00 +02:00
worlddata.d(true);
}
-
- this.getPlayerList().setPlayerFileData(worldserver1);
- if (worlddata.getCustomBossEvents() != null) {
2019-12-10 23:00:00 +01:00
- this.getBossBattleCustomData().load(worlddata.getCustomBossEvents());
2019-04-23 04:00:00 +02:00
- }
-
- Iterator iterator = DimensionManager.a().iterator();
-
- while (iterator.hasNext()) {
- DimensionManager dimensionmanager = (DimensionManager) iterator.next();
-
- if (dimensionmanager != DimensionManager.OVERWORLD) {
- this.worldServer.put(dimensionmanager, new SecondaryWorldServer(worldserver1, this, this.executorService, worldnbtstorage, dimensionmanager, this.methodProfiler, worldloadlistener));
- }
- }
-
2018-08-26 04:00:00 +02:00
}
2019-04-23 04:00:00 +02:00
+ // CraftBukkit end
2018-08-26 04:00:00 +02:00
2019-04-23 04:00:00 +02:00
private void a(WorldData worlddata) {
worlddata.f(false);
2020-01-21 22:00:00 +01:00
@@ -362,6 +504,23 @@
2018-07-15 02:00:00 +02:00
protected void a(File file, WorldData worlddata) {
this.resourcePackRepository.a((ResourcePackSource) (new ResourcePackSourceVanilla()));
this.resourcePackFolder = new ResourcePackSourceFolder(new File(file, "datapacks"));
+ // CraftBukkit start
+ bukkitDataPackFolder = new File(new File(file, "datapacks"), "bukkit");
+ if (!bukkitDataPackFolder.exists()) {
+ bukkitDataPackFolder.mkdirs();
+ }
+ File mcMeta = new File(bukkitDataPackFolder, "pack.mcmeta");
2019-07-22 04:34:03 +02:00
+ try {
+ com.google.common.io.Files.write("{\n"
+ + " \"pack\": {\n"
+ + " \"description\": \"Data pack for resources provided by Bukkit plugins\",\n"
2019-12-10 23:00:00 +01:00
+ + " \"pack_format\": " + SharedConstants.getGameVersion().getPackVersion() + "\n"
2019-07-22 04:34:03 +02:00
+ + " }\n"
+ + "}\n", mcMeta, com.google.common.base.Charsets.UTF_8);
+ } catch (IOException ex) {
+ throw new RuntimeException("Could not initialize Bukkit datapack", ex);
2018-07-15 02:00:00 +02:00
+ }
+ // CraftBukkit end
this.resourcePackRepository.a((ResourcePackSource) this.resourcePackFolder);
this.resourcePackRepository.a();
2018-12-25 22:00:00 +01:00
List<ResourcePackLoader> list = Lists.newArrayList();
2020-01-21 22:00:00 +01:00
@@ -383,11 +542,18 @@
this.bb();
2019-04-23 04:00:00 +02:00
}
2018-08-26 04:00:00 +02:00
2019-04-23 04:00:00 +02:00
- public void loadSpawn(WorldLoadListener worldloadlistener) {
+ // CraftBukkit start
+ public void loadSpawn(WorldLoadListener worldloadlistener, WorldServer worldserver) {
2019-05-02 07:15:53 +02:00
+ if (!worldserver.getWorld().getKeepSpawnInMemory()) {
+ return;
+ }
+
2018-07-15 02:00:00 +02:00
this.b((IChatBaseComponent) (new ChatMessage("menu.generatingTerrain", new Object[0])));
2018-08-26 04:00:00 +02:00
- WorldServer worldserver = this.getWorldServer(DimensionManager.OVERWORLD);
2019-04-23 04:00:00 +02:00
+ // WorldServer worldserver = this.getWorldServer(DimensionManager.OVERWORLD);
2019-04-25 07:33:13 +02:00
+ this.forceTicks = true;
2019-04-23 04:00:00 +02:00
+ // CraftBukkit end
2014-11-25 22:32:16 +01:00
2018-08-26 04:00:00 +02:00
- MinecraftServer.LOGGER.info("Preparing start region for dimension " + DimensionManager.a(worldserver.worldProvider.getDimensionManager()));
2019-05-12 03:15:48 +02:00
+ MinecraftServer.LOGGER.info("Preparing start region for dimension '{}'/{}", worldserver.getWorldData().getName(), DimensionManager.a(worldserver.worldProvider.getDimensionManager().getType())); // CraftBukkit
2019-04-23 04:00:00 +02:00
BlockPosition blockposition = worldserver.getSpawn();
2018-07-15 02:00:00 +02:00
2019-04-23 04:00:00 +02:00
worldloadlistener.a(new ChunkCoordIntPair(blockposition));
2020-01-21 22:00:00 +01:00
@@ -398,17 +564,21 @@
2019-04-25 07:33:13 +02:00
chunkproviderserver.addTicket(TicketType.START, new ChunkCoordIntPair(blockposition), 11, Unit.INSTANCE);
while (chunkproviderserver.b() != 441) {
2019-05-14 02:00:00 +02:00
- this.nextTick = SystemUtils.getMonotonicMillis() + 10L;
2019-04-25 07:33:13 +02:00
- this.sleepForTick();
+ // CraftBukkit start
2019-05-14 02:00:00 +02:00
+ // this.nextTick = SystemUtils.getMonotonicMillis() + 10L;
2019-04-25 07:33:13 +02:00
+ this.executeModerately();
+ // CraftBukkit end
}
2014-11-25 22:32:16 +01:00
2019-05-14 02:00:00 +02:00
- this.nextTick = SystemUtils.getMonotonicMillis() + 10L;
2019-04-25 07:33:13 +02:00
- this.sleepForTick();
2019-04-23 04:00:00 +02:00
- Iterator iterator = DimensionManager.a().iterator();
2019-04-25 07:33:13 +02:00
-
2019-04-23 04:00:00 +02:00
- while (iterator.hasNext()) {
- DimensionManager dimensionmanager = (DimensionManager) iterator.next();
2019-04-27 12:09:40 +02:00
- ForcedChunk forcedchunk = (ForcedChunk) this.getWorldServer(dimensionmanager).getWorldPersistentData().b(ForcedChunk::new, "chunks");
2019-04-25 07:33:13 +02:00
+ // CraftBukkit start
2019-05-14 02:00:00 +02:00
+ // this.nextTick = SystemUtils.getMonotonicMillis() + 10L;
2019-04-25 07:33:13 +02:00
+ this.executeModerately();
+ // Iterator iterator = DimensionManager.a().iterator();
+
2019-04-23 04:00:00 +02:00
+ if (true) {
+ DimensionManager dimensionmanager = worldserver.worldProvider.getDimensionManager();
2019-04-27 12:09:40 +02:00
+ ForcedChunk forcedchunk = (ForcedChunk) worldserver.getWorldPersistentData().b(ForcedChunk::new, "chunks");
2019-04-23 04:00:00 +02:00
+ // CraftBukkit end
if (forcedchunk != null) {
2019-04-27 12:09:40 +02:00
WorldServer worldserver1 = this.getWorldServer(dimensionmanager);
2020-01-21 22:00:00 +01:00
@@ -423,10 +593,16 @@
2019-04-25 07:33:13 +02:00
}
}
2019-05-14 02:00:00 +02:00
- this.nextTick = SystemUtils.getMonotonicMillis() + 10L;
2019-04-25 07:33:13 +02:00
- this.sleepForTick();
+ // CraftBukkit start
2019-05-14 02:00:00 +02:00
+ // this.nextTick = SystemUtils.getMonotonicMillis() + 10L;
2019-04-25 07:33:13 +02:00
+ this.executeModerately();
+ // CraftBukkit end
2019-04-23 04:00:00 +02:00
worldloadlistener.b();
chunkproviderserver.getLightEngine().a(5);
+
2019-04-25 07:33:13 +02:00
+ // CraftBukkit start
+ this.forceTicks = false;
+ // CraftBukkit end
2014-11-25 22:32:16 +01:00
}
2019-04-23 04:00:00 +02:00
protected void a(String s, WorldNBTStorage worldnbtstorage) {
2020-01-21 22:00:00 +01:00
@@ -473,12 +649,16 @@
2019-04-28 03:13:44 +02:00
}
2019-06-25 13:02:13 +02:00
}
2019-04-28 03:13:44 +02:00
2019-06-25 13:02:13 +02:00
+ // CraftBukkit start - moved to WorldServer.save
+ /*
WorldServer worldserver1 = this.getWorldServer(DimensionManager.OVERWORLD);
2019-04-28 03:13:44 +02:00
WorldData worlddata = worldserver1.getWorldData();
2019-12-10 23:00:00 +01:00
worldserver1.getWorldBorder().save(worlddata);
worlddata.setCustomBossEvents(this.getBossBattleCustomData().save());
worldserver1.getDataManager().saveWorldData(worlddata, this.getPlayerList().save());
2019-06-25 13:02:13 +02:00
+ */
+ // CraftBukkit end
2019-04-28 03:13:44 +02:00
return flag3;
}
2020-01-21 22:00:00 +01:00
@@ -487,8 +667,29 @@
2019-04-23 04:00:00 +02:00
this.stop();
2014-11-25 22:32:16 +01:00
}
2015-02-07 11:39:00 +01:00
+ // CraftBukkit start
+ private boolean hasStopped = false;
+ private final Object stopLock = new Object();
2019-04-23 04:00:00 +02:00
+ public final boolean hasStopped() {
+ synchronized (stopLock) {
+ return hasStopped;
+ }
+ }
2015-02-07 11:39:00 +01:00
+ // CraftBukkit end
+
2019-04-23 04:00:00 +02:00
protected void stop() {
2015-02-07 11:39:00 +01:00
+ // CraftBukkit start - prevent double stopping on multiple threads
+ synchronized(stopLock) {
+ if (hasStopped) return;
+ hasStopped = true;
+ }
+ // CraftBukkit end
2016-02-29 22:32:46 +01:00
MinecraftServer.LOGGER.info("Stopping server");
2016-03-01 20:33:41 +01:00
+ // CraftBukkit start
+ if (this.server != null) {
+ this.server.disablePlugins();
+ }
+ // CraftBukkit end
2018-07-15 02:00:00 +02:00
if (this.getServerConnection() != null) {
this.getServerConnection().b();
2016-03-01 20:33:41 +01:00
}
2020-01-21 22:00:00 +01:00
@@ -497,6 +698,7 @@
2016-02-29 22:32:46 +01:00
MinecraftServer.LOGGER.info("Saving players");
2018-12-13 01:00:00 +01:00
this.playerList.savePlayers();
2019-04-23 04:00:00 +02:00
this.playerList.shutdown();
2016-02-29 22:32:46 +01:00
+ try { Thread.sleep(100); } catch (InterruptedException ex) {} // CraftBukkit - SPIGOT-625 - give server at least a chance to send packets
}
2015-09-15 11:52:51 +02:00
2018-08-26 04:00:00 +02:00
MinecraftServer.LOGGER.info("Saving worlds");
2020-01-21 22:00:00 +01:00
@@ -566,14 +768,16 @@
2019-05-19 04:07:37 +02:00
while (this.isRunning) {
long i = SystemUtils.getMonotonicMillis() - this.nextTick;
- if (i > 2000L && this.nextTick - this.lastOverloadTime >= 15000L) {
+ if (i > 5000L && this.nextTick - this.lastOverloadTime >= 30000L) { // CraftBukkit
2018-07-15 02:00:00 +02:00
long j = i / 50L;
2014-11-25 22:32:16 +01:00
+ if (server.getWarnOnOverload()) // CraftBukkit
2018-12-06 00:00:00 +01:00
MinecraftServer.LOGGER.warn("Can't keep up! Is the server overloaded? Running {}ms or {} ticks behind", i, j);
2018-12-13 01:00:00 +01:00
this.nextTick += j * 50L;
this.lastOverloadTime = this.nextTick;
2018-07-15 02:00:00 +02:00
}
+ MinecraftServer.currentTick = (int) (System.currentTimeMillis() / 50); // CraftBukkit
2018-12-13 01:00:00 +01:00
this.nextTick += 50L;
2019-07-20 01:00:00 +02:00
if (this.T) {
this.T = false;
2020-01-21 22:00:00 +01:00
@@ -620,6 +824,12 @@
2014-11-25 22:32:16 +01:00
} catch (Throwable throwable1) {
MinecraftServer.LOGGER.error("Exception stopping the server", throwable1);
} finally {
+ // CraftBukkit start - Restore terminal to original settings
+ try {
+ reader.getTerminal().restore();
+ } catch (Exception ignored) {
+ }
+ // CraftBukkit end
2019-04-23 04:00:00 +02:00
this.exit();
2014-11-25 22:32:16 +01:00
}
2020-01-21 22:00:00 +01:00
@@ -628,8 +838,15 @@
2019-04-25 07:33:13 +02:00
}
private boolean canSleepForTick() {
2019-07-20 01:00:00 +02:00
- return this.isEntered() || SystemUtils.getMonotonicMillis() < (this.ac ? this.ab : this.nextTick);
2019-04-25 07:33:13 +02:00
+ // CraftBukkit start
2019-07-20 01:00:00 +02:00
+ return this.forceTicks || this.isEntered() || SystemUtils.getMonotonicMillis() < (this.ac ? this.ab : this.nextTick);
2019-06-21 12:00:00 +02:00
+ }
+
2019-04-25 07:33:13 +02:00
+ private void executeModerately() {
+ this.executeAll();
+ java.util.concurrent.locks.LockSupport.parkNanos("executing tasks", 1000L);
2019-06-21 12:00:00 +02:00
}
2019-04-25 07:33:13 +02:00
+ // CraftBukkit end
2019-06-21 12:00:00 +02:00
2019-04-25 07:33:13 +02:00
protected void sleepForTick() {
this.executeAll();
2020-01-21 22:00:00 +01:00
@@ -735,7 +952,7 @@
2019-04-23 04:00:00 +02:00
this.serverPing.b().a(agameprofile);
2014-11-25 22:32:16 +01:00
}
2019-04-23 04:00:00 +02:00
- if (this.ticks % 6000 == 0) {
2014-11-25 22:32:16 +01:00
+ if (autosavePeriod > 0 && this.ticks % autosavePeriod == 0) { // CraftBukkit
2019-04-23 04:00:00 +02:00
MinecraftServer.LOGGER.debug("Autosave started");
2018-12-13 01:00:00 +01:00
this.methodProfiler.enter("save");
this.playerList.savePlayers();
2020-01-21 22:00:00 +01:00
@@ -765,23 +982,40 @@
2016-06-30 07:20:04 +02:00
}
2019-04-23 04:00:00 +02:00
protected void b(BooleanSupplier booleansupplier) {
2016-06-30 07:20:04 +02:00
+ this.server.getScheduler().mainThreadHeartbeat(this.ticks); // CraftBukkit
2019-04-23 04:00:00 +02:00
this.methodProfiler.enter("commandFunctions");
2018-12-13 01:00:00 +01:00
this.getFunctionData().tick();
this.methodProfiler.exitEnter("levels");
2019-06-21 12:00:00 +02:00
Iterator iterator = this.getWorlds().iterator();
2014-11-25 22:32:16 +01:00
+ // CraftBukkit start
+ // Run tasks that are waiting on processing
+ while (!processQueue.isEmpty()) {
+ processQueue.remove().run();
+ }
+
+ // Send time updates to everyone, it will get the right time from the world the player is in.
+ if (this.ticks % 20 == 0) {
+ for (int i = 0; i < this.getPlayerList().players.size(); ++i) {
+ EntityPlayer entityplayer = (EntityPlayer) this.getPlayerList().players.get(i);
2019-06-21 12:00:00 +02:00
+ entityplayer.playerConnection.sendPacket(new PacketPlayOutUpdateTime(entityplayer.world.getTime(), entityplayer.getPlayerTime(), entityplayer.world.getGameRules().getBoolean(GameRules.DO_DAYLIGHT_CYCLE))); // Add support for per player time
2014-11-25 22:32:16 +01:00
+ }
+ }
+
2019-06-21 12:00:00 +02:00
while (iterator.hasNext()) {
WorldServer worldserver = (WorldServer) iterator.next();
2018-08-26 04:00:00 +02:00
- if (worldserver.worldProvider.getDimensionManager() == DimensionManager.OVERWORLD || this.getAllowNether()) {
+ if (true || worldserver.worldProvider.getDimensionManager() == DimensionManager.OVERWORLD || this.getAllowNether()) { // CraftBukkit
2017-08-03 15:00:00 +02:00
this.methodProfiler.a(() -> {
2019-04-23 04:00:00 +02:00
return worldserver.getWorldData().getName() + " " + IRegistry.DIMENSION_TYPE.getKey(worldserver.worldProvider.getDimensionManager());
2017-08-03 15:00:00 +02:00
});
2014-11-25 22:32:16 +01:00
+ /* Drop global time updates
if (this.ticks % 20 == 0) {
2018-12-13 01:00:00 +01:00
this.methodProfiler.enter("timeSync");
2019-06-21 12:00:00 +02:00
this.playerList.a((Packet) (new PacketPlayOutUpdateTime(worldserver.getTime(), worldserver.getDayTime(), worldserver.getGameRules().getBoolean(GameRules.DO_DAYLIGHT_CYCLE))), worldserver.worldProvider.getDimensionManager());
2018-12-13 01:00:00 +01:00
this.methodProfiler.exit();
2014-11-25 22:32:16 +01:00
}
+ // CraftBukkit end */
2018-12-13 01:00:00 +01:00
this.methodProfiler.enter("tick");
2014-11-25 22:32:16 +01:00
2020-01-21 22:00:00 +01:00
@@ -824,7 +1058,8 @@
2019-04-23 04:00:00 +02:00
this.tickables.add(runnable);
2014-11-25 22:32:16 +01:00
}
- public static void main(String[] astring) {
2019-04-23 04:00:00 +02:00
+ public static void main(final OptionSet optionset) { // CraftBukkit - replaces main(String[] astring)
+ /* 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");
2020-01-21 22:00:00 +01:00
@@ -847,15 +1082,17 @@
2019-04-23 04:00:00 +02:00
optionparser.printHelpOn(System.err);
return;
2016-02-29 22:32:46 +01:00
}
+ */ // CraftBukkit end
2019-04-23 04:00:00 +02:00
+ try {
java.nio.file.Path java_nio_file_path = Paths.get("server.properties");
- DedicatedServerSettings dedicatedserversettings = new DedicatedServerSettings(java_nio_file_path);
+ DedicatedServerSettings dedicatedserversettings = new DedicatedServerSettings(optionset); // CraftBukkit - CLI argument support
dedicatedserversettings.save();
java.nio.file.Path java_nio_file_path1 = Paths.get("eula.txt");
EULA eula = new EULA(java_nio_file_path1);
- if (optionset.has(optionspec1)) {
+ if (optionset.has("initSettings")) { // CraftBukkit
MinecraftServer.LOGGER.info("Initialized '" + java_nio_file_path.toAbsolutePath().toString() + "' and '" + java_nio_file_path1.toAbsolutePath().toString() + "'");
return;
}
2020-01-21 22:00:00 +01:00
@@ -868,14 +1105,16 @@
CrashReport.h();
2019-04-23 04:00:00 +02:00
DispenserRegistry.init();
DispenserRegistry.c();
- String s = (String) optionset.valueOf(optionspec8);
2020-01-22 00:36:35 +01:00
+ File s = (File) optionset.valueOf("universe"); // CraftBukkit
2016-02-29 22:32:46 +01:00
YggdrasilAuthenticationService yggdrasilauthenticationservice = new YggdrasilAuthenticationService(Proxy.NO_PROXY, UUID.randomUUID().toString());
MinecraftSessionService minecraftsessionservice = yggdrasilauthenticationservice.createMinecraftSessionService();
GameProfileRepository gameprofilerepository = yggdrasilauthenticationservice.createProfileRepository();
2019-04-23 04:00:00 +02:00
UserCache usercache = new UserCache(gameprofilerepository, new File(s, MinecraftServer.b.getName()));
- String s1 = (String) Optional.ofNullable(optionset.valueOf(optionspec9)).orElse(dedicatedserversettings.getProperties().levelName);
- final DedicatedServer dedicatedserver = new DedicatedServer(new File(s), dedicatedserversettings, DataConverterRegistry.a(), yggdrasilauthenticationservice, minecraftsessionservice, gameprofilerepository, usercache, WorldLoadListenerLogger::new, s1);
2020-01-21 22:00:00 +01:00
+ // CraftBukkit start
2019-04-23 04:00:00 +02:00
+ String s1 = (String) Optional.ofNullable(optionset.valueOf("world")).orElse(dedicatedserversettings.getProperties().levelName);
+ final DedicatedServer dedicatedserver = new DedicatedServer(optionset, dedicatedserversettings, DataConverterRegistry.a(), yggdrasilauthenticationservice, minecraftsessionservice, gameprofilerepository, usercache, WorldLoadListenerLogger::new, s1);
2016-02-29 22:32:46 +01:00
2020-01-21 22:00:00 +01:00
+ /*
2019-04-23 04:00:00 +02:00
dedicatedserver.i((String) optionset.valueOf(optionspec7));
dedicatedserver.setPort((Integer) optionset.valueOf(optionspec10));
dedicatedserver.e(optionset.has(optionspec2));
2020-01-21 22:00:00 +01:00
@@ -883,12 +1122,14 @@
dedicatedserver.setForceUpgrade(optionset.has(optionspec4));
dedicatedserver.setEraseCache(optionset.has(optionspec5));
dedicatedserver.c((String) optionset.valueOf(optionspec11));
- boolean flag = !optionset.has(optionspec) && !optionset.valuesOf(nonoptionargumentspec).contains("nogui");
+ */
+ boolean flag = !optionset.has("nogui") && !optionset.nonOptionArguments().contains("nogui");
if (flag && !GraphicsEnvironment.isHeadless()) {
dedicatedserver.bc();
}
+ /*
dedicatedserver.startServerThread();
Thread thread = new Thread("Server Shutdown Thread") {
public void run() {
@@ -898,6 +1139,29 @@
2018-07-15 02:00:00 +02:00
thread.setUncaughtExceptionHandler(new DefaultUncaughtExceptionHandler(MinecraftServer.LOGGER));
Runtime.getRuntime().addShutdownHook(thread);
2014-11-25 22:32:16 +01:00
+ */
+
2019-04-23 04:00:00 +02:00
+ if (optionset.has("port")) {
+ int port = (Integer) optionset.valueOf("port");
2014-11-25 22:32:16 +01:00
+ if (port > 0) {
+ dedicatedserver.setPort(port);
+ }
+ }
+
2019-04-23 04:00:00 +02:00
+ if (optionset.has("universe")) {
+ dedicatedserver.universe = (File) optionset.valueOf("universe");
2014-11-25 22:32:16 +01:00
+ }
+
2019-04-23 04:00:00 +02:00
+ if (optionset.has("forceUpgrade")) {
2018-07-22 04:00:00 +02:00
+ dedicatedserver.setForceUpgrade(true);
+ }
+
2019-05-04 12:54:32 +02:00
+ if (optionset.has("eraseCache")) {
2019-05-14 02:00:00 +02:00
+ dedicatedserver.setEraseCache(true);
2019-05-04 12:54:32 +02:00
+ }
+
2019-04-23 04:00:00 +02:00
+ dedicatedserver.serverThread.start();
2014-11-25 22:32:16 +01:00
+ // CraftBukkit end
} catch (Exception exception) {
MinecraftServer.LOGGER.fatal("Failed to start the minecraft server", exception);
}
2020-01-21 22:00:00 +01:00
@@ -917,7 +1181,9 @@
2014-11-25 22:32:16 +01:00
}
2019-04-23 04:00:00 +02:00
public void startServerThread() {
2014-11-25 22:32:16 +01:00
+ /* CraftBukkit start - prevent abuse
this.serverThread.start();
+ // CraftBukkit end */
}
2019-04-23 04:00:00 +02:00
public File d(String s) {
2020-01-21 22:00:00 +01:00
@@ -972,7 +1238,7 @@
2014-11-25 22:32:16 +01:00
}
public String getServerModName() {
- return "vanilla";
+ return server.getName(); // CraftBukkit - cb > vanilla!
}
public CrashReport b(CrashReport crashreport) {
2020-01-21 22:00:00 +01:00
@@ -1013,7 +1279,7 @@
public abstract Optional<String> q();
2014-11-25 22:32:16 +01:00
2020-01-21 22:00:00 +01:00
public boolean K() {
2014-11-29 01:53:49 +01:00
- return this.universe != null;
+ return true; // CraftBukkit
}
2019-04-23 04:00:00 +02:00
@Override
2020-01-21 22:00:00 +01:00
@@ -1729,4 +1995,16 @@
private void bb() {
2019-12-10 23:00:00 +01:00
Block.REGISTRY_ID.forEach(IBlockData::c);
2019-07-20 01:00:00 +02:00
}
2016-02-29 22:32:46 +01:00
+
+ // CraftBukkit start
2019-04-23 04:00:00 +02:00
+ @Override
+ public boolean isMainThread() {
+ return super.isMainThread() || this.isStopped(); // CraftBukkit - MC-142590
+ }
+
2016-02-29 22:32:46 +01:00
+ @Deprecated
+ public static MinecraftServer getServer() {
2016-03-25 00:20:27 +01:00
+ return (Bukkit.getServer() instanceof CraftServer) ? ((CraftServer) Bukkit.getServer()).getServer() : null;
2016-02-29 22:32:46 +01:00
+ }
+ // CraftBukkit end
}