2015-05-25 12:37:24 +02:00
--- a/net/minecraft/server/MinecraftServer.java
+++ b/net/minecraft/server/MinecraftServer.java
2018-09-08 05:37:15 +02:00
@@ -59,6 +59,14 @@
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;
+import joptsimple.OptionSet;
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
2018-07-15 02:00:00 +02:00
public abstract class MinecraftServer implements IAsyncTaskHandler, IMojangStatistics, ICommandListener, Runnable {
2015-02-26 23:41:06 +01:00
2018-09-08 05:37:15 +02:00
@@ -129,7 +137,21 @@
2018-07-22 04:00:00 +02:00
private boolean forceUpgrade;
private float ap;
2014-11-25 22:32:16 +01:00
2018-07-15 02:00:00 +02:00
- public MinecraftServer(@Nullable File file, Proxy proxy, DataFixer datafixer, CommandDispatcher commanddispatcher, YggdrasilAuthenticationService yggdrasilauthenticationservice, MinecraftSessionService minecraftsessionservice, GameProfileRepository gameprofilerepository, UserCache usercache) {
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 final Thread primaryThread;
+ 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;
2014-11-25 22:32:16 +01:00
+ // CraftBukkit end
+
2018-07-15 02:00:00 +02:00
+ public MinecraftServer(OptionSet options, Proxy proxy, DataFixer datafixer, CommandDispatcher commanddispatcher, YggdrasilAuthenticationService yggdrasilauthenticationservice, MinecraftSessionService minecraftsessionservice, GameProfileRepository gameprofilerepository, UserCache usercache) {
this.ac = new ResourceManager(EnumResourcePackType.SERVER_DATA);
this.resourcePackRepository = new ResourcePackRepository(ResourcePackLoader::new);
this.ag = new CraftingManager();
2018-09-08 05:37:15 +02:00
@@ -140,22 +162,51 @@
2018-07-15 02:00:00 +02:00
this.al = new AdvancementDataWorld();
this.am = new CustomFunctionData(this);
2018-08-26 04:00:00 +02:00
this.c = 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
2018-07-15 02:00:00 +02:00
this.U = yggdrasilauthenticationservice;
this.V = minecraftsessionservice;
this.W = gameprofilerepository;
this.X = usercache;
2014-11-25 22:32:16 +01:00
- this.universe = file;
2018-12-13 01:00:00 +01:00
- this.serverConnection = file == null ? null : new ServerConnection(this);
2018-07-15 02:00:00 +02:00
- this.convertable = file == null ? null : new WorldLoaderServer(file.toPath(), file.toPath().resolve("../backups"), datafixer);
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
2018-07-15 02:00:00 +02:00
+ // this.convertable = file == null ? null : new WorldLoaderServer(file.toPath(), file.toPath().resolve("../backups"), datafixer); // CraftBukkit - moved to DedicatedServer.init
this.dataConverterManager = datafixer;
this.ac.a((IResourcePackListener) this.ah);
this.ac.a((IResourcePackListener) this.ag);
this.ac.a((IResourcePackListener) this.ak);
this.ac.a((IResourcePackListener) this.am);
this.ac.a((IResourcePackListener) this.al);
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));
+
+ this.serverThread = primaryThread = new Thread(this, "Server thread"); // Moved from main
}
+ public abstract PropertyManager getPropertyManager();
+ // CraftBukkit end
+
2018-07-15 02:00:00 +02:00
public abstract boolean init() throws IOException;
2018-07-22 04:00:00 +02:00
public void convertWorld(String s) {
2018-09-08 05:37:15 +02:00
@@ -180,11 +231,11 @@
2018-07-22 04:00:00 +02:00
}
if (this.forceUpgrade) {
- MinecraftServer.LOGGER.info("Forcing world upgrade!");
- WorldData worlddata = this.getConvertable().c(this.getWorld());
+ MinecraftServer.LOGGER.info("Forcing world upgrade! {}", s); // CraftBukkit
+ WorldData worlddata = this.getConvertable().c(s); // CraftBukkit
if (worlddata != null) {
- WorldUpgrader worldupgrader = new WorldUpgrader(this.getWorld(), this.getConvertable(), worlddata);
+ WorldUpgrader worldupgrader = new WorldUpgrader(s, this.getConvertable(), worlddata); // CraftBukkit
IChatBaseComponent ichatbasecomponent = null;
while (!worldupgrader.b()) {
2018-09-08 05:37:15 +02:00
@@ -223,8 +274,9 @@
2018-07-22 04:00:00 +02:00
}
public void a(String s, String s1, long i, WorldType worldtype, JsonElement jsonelement) {
- 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
2018-08-26 04:00:00 +02:00
IDataManager idatamanager = this.getConvertable().a(s, this);
2014-11-25 22:32:16 +01:00
2018-08-26 04:00:00 +02:00
this.a(this.getWorld(), idatamanager);
2018-09-08 05:37:15 +02:00
@@ -249,54 +301,144 @@
2014-11-25 22:32:16 +01:00
}
2018-07-15 02:00:00 +02:00
this.a(idatamanager.getDirectory(), worlddata);
2018-08-26 04:00:00 +02:00
- PersistentCollection persistentcollection = new PersistentCollection(idatamanager);
2014-11-25 22:32:16 +01:00
+ */
+ int worldCount = 3;
2018-08-26 04:00:00 +02:00
- this.a(idatamanager, persistentcollection, worlddata, worldsettings);
- this.a(this.getDifficulty());
- this.a(persistentcollection);
- }
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
+ }
2014-11-25 22:32:16 +01:00
2018-08-26 04:00:00 +02:00
- protected void a(IDataManager idatamanager, PersistentCollection persistentcollection, WorldData worlddata, WorldSettings worldsettings) {
- if (this.L()) {
- this.worldServer.put(DimensionManager.OVERWORLD, (new DemoWorldServer(this, idatamanager, persistentcollection, worlddata, DimensionManager.OVERWORLD, this.methodProfiler)).i_());
- } else {
- this.worldServer.put(DimensionManager.OVERWORLD, (new WorldServer(this, idatamanager, persistentcollection, worlddata, DimensionManager.OVERWORLD, this.methodProfiler)).i_());
- }
+ 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
+ }
2014-11-25 22:32:16 +01:00
2018-08-26 04:00:00 +02:00
- WorldServer worldserver = this.getWorldServer(DimensionManager.OVERWORLD);
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) {
2018-07-15 02:00:00 +02:00
+ IDataManager idatamanager = new ServerNBTManager(server.getWorldContainer(), s1, this, this.dataConverterManager);
+ worlddata = idatamanager.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)
2018-07-26 14:11:02 +02:00
+ this.a(idatamanager.getDirectory(), worlddata);
2018-08-26 04:00:00 +02:00
+ PersistentCollection persistentcollection = new PersistentCollection(idatamanager);
2014-11-25 22:32:16 +01:00
2018-08-26 04:00:00 +02:00
- worldserver.a(worldsettings);
- worldserver.addIWorldAccess(new WorldManager(this, worldserver));
- if (!this.H()) {
- worldserver.getWorldData().setGameType(this.getGamemode());
- }
+ if (this.L()) {
+ world = (WorldServer) (new DemoWorldServer(this, idatamanager, persistentcollection, worlddata, DimensionManager.OVERWORLD, this.methodProfiler)).i_();
+ } else {
+ world = (WorldServer) (new WorldServer(this, idatamanager, persistentcollection, worlddata, DimensionManager.OVERWORLD, this.methodProfiler, org.bukkit.World.Environment.getEnvironment(dimension), gen)).i_();
+ }
2018-12-13 01:00:00 +01:00
- SecondaryWorldServer secondaryworldserver = (new SecondaryWorldServer(this, idatamanager, DimensionManager.NETHER, worldserver, this.methodProfiler)).i_();
2014-11-25 22:32:16 +01:00
+ world.a(worldsettings);
+ this.server.scoreboardManager = new org.bukkit.craftbukkit.scoreboard.CraftScoreboardManager(this, world.getScoreboard());
2018-08-26 04:00:00 +02:00
+ } else {
2014-11-25 22:32:16 +01:00
+ String dim = "DIM" + dimension;
2018-08-26 04:00:00 +02:00
- this.worldServer.put(DimensionManager.NETHER, secondaryworldserver);
- secondaryworldserver.addIWorldAccess(new WorldManager(this, secondaryworldserver));
- if (!this.H()) {
- secondaryworldserver.getWorldData().setGameType(this.getGamemode());
- }
2014-11-25 22:32:16 +01:00
+ File newWorld = new File(new File(name), dim);
+ File oldWorld = new File(new File(s), dim);
2018-08-26 04:00:00 +02:00
2018-12-13 01:00:00 +01:00
- SecondaryWorldServer secondaryworldserver1 = (new SecondaryWorldServer(this, idatamanager, DimensionManager.THE_END, worldserver, this.methodProfiler)).i_();
2014-11-25 22:32:16 +01:00
+ if ((!newWorld.isDirectory()) && (oldWorld.isDirectory())) {
+ 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 {
+ com.google.common.io.Files.copy(new File(new File(s), "level.dat"), 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 ----");
+ }
+ }
2018-08-26 04:00:00 +02:00
- this.worldServer.put(DimensionManager.THE_END, secondaryworldserver1);
- secondaryworldserver1.addIWorldAccess(new WorldManager(this, secondaryworldserver1));
- if (!this.H()) {
- secondaryworldserver1.getWorldData().setGameType(this.getGamemode());
- }
2018-07-15 02:00:00 +02:00
+ IDataManager idatamanager = new ServerNBTManager(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
2018-07-15 02:00:00 +02:00
+ worlddata = idatamanager.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)
2018-12-13 01:00:00 +01:00
+ world = (WorldServer) new SecondaryWorldServer(this, idatamanager, DimensionManager.a(dimension), this.getWorldServer(DimensionManager.OVERWORLD), this.methodProfiler, worlddata, org.bukkit.World.Environment.getEnvironment(dimension), gen).i_();
2018-08-26 04:00:00 +02:00
+ }
+
2014-11-25 22:32:16 +01:00
+ this.server.getPluginManager().callEvent(new org.bukkit.event.world.WorldInitEvent(world.getWorld()));
+
+ world.addIWorldAccess(new WorldManager(this, world));
2018-08-26 04:00:00 +02:00
+ if (!this.H()) {
2014-11-25 22:32:16 +01:00
+ world.getWorldData().setGameType(this.getGamemode());
2018-08-26 04:00:00 +02:00
+ }
+
+ this.worldServer.put(world.dimension, world);
+ this.getPlayerList().setPlayerFileData(world);
2016-02-29 22:32:46 +01:00
2018-08-26 04:00:00 +02:00
- this.getPlayerList().setPlayerFileData(worldserver);
2018-07-15 02:00:00 +02:00
- if (worlddata.P() != null) {
2018-12-06 00:00:00 +01:00
- this.getBossBattleCustomData().a(worlddata.P());
2018-07-15 02:00:00 +02:00
+ if (worlddata.P() != null) {
2018-12-06 00:00:00 +01:00
+ this.getBossBattleCustomData().a(worlddata.P());
2018-07-15 02:00:00 +02:00
+ }
}
2018-08-26 04:00:00 +02:00
+ this.a(this.getDifficulty());
+ this.a(this.getWorldServer(DimensionManager.OVERWORLD).worldMaps);
2014-11-25 22:32:16 +01:00
+ // CraftBukkit end
2018-07-15 02:00:00 +02:00
2018-08-26 04:00:00 +02:00
}
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");
+ if (!mcMeta.exists()) {
+ try {
+ com.google.common.io.Files.write("{\n"
+ + " \"pack\": {\n"
+ + " \"description\": \"Data pack for resources provided by Bukkit plugins\",\n"
+ + " \"pack_format\": 1\n"
+ + " }\n"
+ + "}", mcMeta, com.google.common.base.Charsets.UTF_8);
+ } catch (IOException ex) {
+ throw new RuntimeException("Could not initialize Bukkit datapack", ex);
+ }
+ }
+ // CraftBukkit end
this.resourcePackRepository.a((ResourcePackSource) this.resourcePackFolder);
this.resourcePackRepository.a();
ArrayList arraylist = Lists.newArrayList();
2018-09-08 05:37:15 +02:00
@@ -325,42 +467,52 @@
2018-08-26 04:00:00 +02:00
boolean flag4 = true;
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);
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()));
2014-11-25 22:32:16 +01:00
- BlockPosition blockposition = worldserver.getSpawn();
2018-07-15 02:00:00 +02:00
- ArrayList arraylist = Lists.newArrayList();
- Set set = Sets.newConcurrentHashSet();
2014-11-25 22:32:16 +01:00
+ // CraftBukkit start - fire WorldLoadEvent and handle whether or not to keep the spawn in memory
2018-07-15 02:00:00 +02:00
Stopwatch stopwatch = Stopwatch.createStarted();
-
- for (int i = -192; i <= 192 && this.isRunning(); i += 16) {
- for (int j = -192; j <= 192 && this.isRunning(); j += 16) {
- arraylist.add(new ChunkCoordIntPair(blockposition.getX() + i >> 4, blockposition.getZ() + j >> 4));
2018-08-26 04:00:00 +02:00
+ for (WorldServer worldserver : this.getWorlds()) {
+ MinecraftServer.LOGGER.info("Preparing start region for level " + worldserver.dimension + " (Seed: " + worldserver.getSeed() + ")");
2014-11-25 22:32:16 +01:00
+ if (!worldserver.getWorld().getKeepSpawnInMemory()) {
+ continue;
2018-07-15 02:00:00 +02:00
}
2018-12-13 01:00:00 +01:00
- CompletableFuture completablefuture = worldserver.getChunkProvider().a((Iterable) arraylist, (chunk) -> {
2018-07-15 02:00:00 +02:00
- set.add(chunk.getPos());
- });
2014-11-25 22:32:16 +01:00
+ BlockPosition blockposition = worldserver.getSpawn();
2018-07-15 02:00:00 +02:00
+ ArrayList arraylist = Lists.newArrayList();
+ Set set = Sets.newConcurrentHashSet();
2018-08-26 04:00:00 +02:00
+
+ for (int i = -192; i <= 192 && this.isRunning(); i += 16) {
+ for (int j = -192; j <= 192 && this.isRunning(); j += 16) {
+ arraylist.add(new ChunkCoordIntPair(blockposition.getX() + i >> 4, blockposition.getZ() + j >> 4));
+ }
2018-07-15 02:00:00 +02:00
- while (!completablefuture.isDone()) {
- try {
- completablefuture.get(1L, TimeUnit.SECONDS);
- } catch (InterruptedException interruptedexception) {
- throw new RuntimeException(interruptedexception);
- } catch (ExecutionException executionexception) {
- if (executionexception.getCause() instanceof RuntimeException) {
- throw (RuntimeException) executionexception.getCause();
- }
2018-12-13 01:00:00 +01:00
+ CompletableFuture completablefuture = worldserver.getChunkProvider().a((Iterable) arraylist, (chunk) -> {
2018-07-15 02:00:00 +02:00
+ set.add(chunk.getPos());
+ });
2018-08-26 04:00:00 +02:00
+
2018-07-15 02:00:00 +02:00
+ while (!completablefuture.isDone()) {
+ try {
+ completablefuture.get(1L, TimeUnit.SECONDS);
+ } catch (InterruptedException interruptedexception) {
+ throw new RuntimeException(interruptedexception);
+ } catch (ExecutionException executionexception) {
+ if (executionexception.getCause() instanceof RuntimeException) {
+ throw (RuntimeException) executionexception.getCause();
+ }
2018-08-26 04:00:00 +02:00
- throw new RuntimeException(executionexception.getCause());
- } catch (TimeoutException timeoutexception) {
- this.a(new ChatMessage("menu.preparingSpawn", new Object[0]), set.size() * 100 / 625);
2018-07-15 02:00:00 +02:00
+ throw new RuntimeException(executionexception.getCause());
+ } catch (TimeoutException timeoutexception) {
+ this.a(new ChatMessage("menu.preparingSpawn", new Object[0]), set.size() * 100 / 625);
2014-11-25 22:32:16 +01:00
+ }
2018-07-15 02:00:00 +02:00
}
- }
2014-11-25 22:32:16 +01:00
2018-07-15 02:00:00 +02:00
- this.a(new ChatMessage("menu.preparingSpawn", new Object[0]), set.size() * 100 / 625);
+ this.a(new ChatMessage("menu.preparingSpawn", new Object[0]), set.size() * 100 / 625);
+ }
2014-11-25 22:32:16 +01:00
}
2018-08-26 04:00:00 +02:00
+ for (WorldServer world : this.getWorlds()) {
2014-11-25 22:32:16 +01:00
+ this.server.getPluginManager().callEvent(new org.bukkit.event.world.WorldLoadEvent(world.getWorld()));
+ }
+ // CraftBukkit end
2018-12-06 00:00:00 +01:00
MinecraftServer.LOGGER.info("Time elapsed: {} ms", stopwatch.elapsed(TimeUnit.MILLISECONDS));
2018-08-26 04:00:00 +02:00
Iterator iterator = DimensionManager.b().iterator();
2018-09-08 05:37:15 +02:00
@@ -419,6 +571,10 @@
2018-08-26 04:00:00 +02:00
protected void l() {
2018-07-15 02:00:00 +02:00
this.w = null;
this.x = 0;
2018-09-08 05:37:15 +02:00
+ // CraftBukkit Start
+ this.server.enablePlugins(org.bukkit.plugin.PluginLoadOrder.POSTWORLD);
+ this.server.getPluginManager().callEvent(new ServerLoadEvent(ServerLoadEvent.LoadType.STARTUP));
+ // CraftBukkit end
2014-11-25 22:32:16 +01:00
}
2016-02-29 22:32:46 +01:00
protected void saveChunks(boolean flag) {
2018-09-08 05:37:15 +02:00
@@ -442,8 +598,24 @@
2015-02-26 23:41:06 +01:00
2014-11-25 22:32:16 +01:00
}
2015-02-26 23:41:06 +01:00
- protected void stop() {
2015-02-07 11:39:00 +01:00
+ // CraftBukkit start
+ private boolean hasStopped = false;
+ private final Object stopLock = new Object();
+ // CraftBukkit end
+
2014-11-25 22:32:16 +01:00
+ public void stop() throws ExceptionWorldConflict { // CraftBukkit - added throws
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
}
2018-09-08 05:37:15 +02:00
@@ -452,6 +624,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();
this.playerList.u();
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");
2018-09-08 05:37:15 +02:00
@@ -516,11 +689,13 @@
2018-12-13 01:00:00 +01:00
if (i > 2000L && this.nextTick - this.lastOverloadTime >= 15000L) {
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.a(this::canSleepForTick);
this.nextTick += 50L;
2018-07-15 02:00:00 +02:00
2018-09-08 05:37:15 +02:00
@@ -559,6 +734,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
2018-08-26 04:00:00 +02:00
this.t();
2014-11-25 22:32:16 +01:00
}
2018-09-08 05:37:15 +02:00
@@ -627,7 +808,7 @@
2018-08-26 04:00:00 +02:00
this.m.b().a(agameprofile);
2014-11-25 22:32:16 +01:00
}
- if (this.ticks % 900 == 0) {
+ if (autosavePeriod > 0 && this.ticks % autosavePeriod == 0) { // CraftBukkit
2018-12-13 01:00:00 +01:00
this.methodProfiler.enter("save");
this.playerList.savePlayers();
2014-11-25 22:32:16 +01:00
this.saveChunks(true);
2018-09-08 05:37:15 +02:00
@@ -653,6 +834,7 @@
2016-06-30 07:20:04 +02:00
}
2018-08-26 04:00:00 +02:00
public void b(BooleanSupplier booleansupplier) {
2016-06-30 07:20:04 +02:00
+ this.server.getScheduler().mainThreadHeartbeat(this.ticks); // CraftBukkit
2018-12-13 01:00:00 +01:00
this.methodProfiler.enter("jobs");
2014-11-25 22:32:16 +01:00
2018-07-15 02:00:00 +02:00
FutureTask futuretask;
2018-09-08 05:37:15 +02:00
@@ -665,23 +847,40 @@
2018-12-13 01:00:00 +01:00
this.getFunctionData().tick();
this.methodProfiler.exitEnter("levels");
2014-11-25 22:32:16 +01:00
2018-08-26 04:00:00 +02:00
- WorldServer worldserver;
2014-11-25 22:32:16 +01:00
+ // CraftBukkit start
+ // Run tasks that are waiting on processing
+ while (!processQueue.isEmpty()) {
+ processQueue.remove().run();
+ }
+
+ org.bukkit.craftbukkit.chunkio.ChunkIOExecutor.tick();
+
+ // 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);
+ entityplayer.playerConnection.sendPacket(new PacketPlayOutUpdateTime(entityplayer.world.getTime(), entityplayer.getPlayerTime(), entityplayer.world.getGameRules().getBoolean("doDaylightCycle"))); // Add support for per player time
+ }
+ }
+
2018-08-26 04:00:00 +02:00
+ // WorldServer worldserver; // CraftBukkit - dropped down
long i;
- for (Iterator iterator = this.getWorlds().iterator(); iterator.hasNext();((long[]) this.e.computeIfAbsent(worldserver.worldProvider.getDimensionManager(), (dimensionmanager) -> {
- return new long[100];
2018-12-13 01:00:00 +01:00
- }))[this.ticks % 100] = SystemUtils.getMonotonicNanos() - i) {
2018-08-26 04:00:00 +02:00
- worldserver = (WorldServer) iterator.next();
+ // CraftBukkit - dropTickTime
+ for (Iterator iterator = this.getWorlds().iterator(); iterator.hasNext();) {
+ WorldServer worldserver = (WorldServer) iterator.next();
2018-12-13 01:00:00 +01:00
i = SystemUtils.getMonotonicNanos();
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(() -> {
2018-10-22 21:00:00 +02:00
return "dim-" + worldserver.worldProvider.getDimensionManager().getDimensionID();
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");
this.playerList.a((Packet) (new PacketPlayOutUpdateTime(worldserver.getTime(), worldserver.getDayTime(), worldserver.getGameRules().getBoolean("doDaylightCycle"))), worldserver.worldProvider.getDimensionManager());
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
2018-09-08 05:37:15 +02:00
@@ -732,10 +931,11 @@
2018-08-26 04:00:00 +02:00
this.k.add(itickable);
2014-11-25 22:32:16 +01:00
}
- public static void main(String[] astring) {
+ public static void main(final OptionSet options) { // CraftBukkit - replaces main(String[] astring)
DispenserRegistry.c();
try {
+ /* CraftBukkit start - Replace everything
boolean flag = true;
String s = null;
String s1 = ".";
2018-09-08 05:37:15 +02:00
@@ -783,13 +983,16 @@
2016-02-29 22:32:46 +01:00
++j;
}
}
+ */ // CraftBukkit end
+ String s1 = "."; // PAIL?
YggdrasilAuthenticationService yggdrasilauthenticationservice = new YggdrasilAuthenticationService(Proxy.NO_PROXY, UUID.randomUUID().toString());
MinecraftSessionService minecraftsessionservice = yggdrasilauthenticationservice.createMinecraftSessionService();
GameProfileRepository gameprofilerepository = yggdrasilauthenticationservice.createProfileRepository();
UserCache usercache = new UserCache(gameprofilerepository, new File(s1, MinecraftServer.a.getName()));
- final DedicatedServer dedicatedserver = new DedicatedServer(new File(s1), DataConverterRegistry.a(), yggdrasilauthenticationservice, minecraftsessionservice, gameprofilerepository, usercache);
+ final DedicatedServer dedicatedserver = new DedicatedServer(options, DataConverterRegistry.a(), yggdrasilauthenticationservice, minecraftsessionservice, gameprofilerepository, usercache);
+ /* CraftBukkit start
if (s != null) {
2018-07-15 02:00:00 +02:00
dedicatedserver.h(s);
2016-02-29 22:32:46 +01:00
}
2018-09-08 05:37:15 +02:00
@@ -827,6 +1030,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
+ */
+
+ if (options.has("port")) {
+ int port = (Integer) options.valueOf("port");
+ if (port > 0) {
+ dedicatedserver.setPort(port);
+ }
+ }
+
+ if (options.has("universe")) {
+ dedicatedserver.universe = (File) options.valueOf("universe");
+ }
+
+ if (options.has("world")) {
+ dedicatedserver.setWorld((String) options.valueOf("world"));
+ }
+
2018-07-22 04:00:00 +02:00
+ if (options.has("forceUpgrade")) {
+ dedicatedserver.setForceUpgrade(true);
+ }
+
2014-11-25 22:32:16 +01:00
+ dedicatedserver.primaryThread.start();
+ // CraftBukkit end
} catch (Exception exception) {
MinecraftServer.LOGGER.fatal("Failed to start the minecraft server", exception);
}
2018-09-08 05:37:15 +02:00
@@ -838,11 +1064,13 @@
2014-11-25 22:32:16 +01:00
}
2018-08-26 04:00:00 +02:00
public void v() {
2014-11-25 22:32:16 +01:00
+ /* CraftBukkit start - prevent abuse
this.serverThread = new Thread(this, "Server thread");
2018-07-15 02:00:00 +02:00
this.serverThread.setUncaughtExceptionHandler((thread, throwable) -> {
MinecraftServer.LOGGER.error(throwable);
});
2014-11-25 22:32:16 +01:00
this.serverThread.start();
+ // CraftBukkit end */
}
2018-07-15 02:00:00 +02:00
public File c(String s) {
2018-09-08 05:37:15 +02:00
@@ -882,7 +1110,7 @@
2014-11-25 22:32:16 +01:00
}
public boolean isDebugging() {
- return false;
+ return this.getPropertyManager().getBoolean("debug", false); // CraftBukkit - don't hardcode
}
2018-07-15 02:00:00 +02:00
public void f(String s) {
2018-09-08 05:37:15 +02:00
@@ -897,7 +1125,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) {
2018-09-08 05:37:15 +02:00
@@ -933,7 +1161,7 @@
2014-11-25 22:32:16 +01:00
}
2018-08-26 04:00:00 +02:00
public boolean D() {
2014-11-29 01:53:49 +01:00
- return this.universe != null;
+ return true; // CraftBukkit
}
2018-07-15 02:00:00 +02:00
public void sendMessage(IChatBaseComponent ichatbasecomponent) {
2018-09-08 05:37:15 +02:00
@@ -1073,7 +1301,7 @@
2018-08-26 04:00:00 +02:00
public abstract boolean Q();
2014-11-25 22:32:16 +01:00
public boolean getOnlineMode() {
- return this.onlineMode;
+ return server.getOnlineMode(); // CraftBukkit
}
public void setOnlineMode(boolean flag) {
2018-09-08 05:37:15 +02:00
@@ -1233,7 +1461,7 @@
2015-03-11 11:44:51 +01:00
public <V> ListenableFuture<V> a(Callable<V> callable) {
Validate.notNull(callable);
- if (!this.isMainThread() && !this.isStopped()) {
+ if (!this.isMainThread()) { // CraftBukkit && !this.isStopped()) {
ListenableFutureTask listenablefuturetask = ListenableFutureTask.create(callable);
2018-08-26 04:00:00 +02:00
this.f.add(listenablefuturetask);
2018-09-08 05:37:15 +02:00
@@ -1304,8 +1532,8 @@
2018-07-15 02:00:00 +02:00
if (!worlddata.N().contains(resourcepackloader.e()) && !arraylist.contains(resourcepackloader)) {
MinecraftServer.LOGGER.info("Found new data pack {}, loading it automatically", resourcepackloader.e());
- resourcepackloader.h().a(arraylist, resourcepackloader, (resourcepackloader) -> {
- return resourcepackloader;
+ resourcepackloader.h().a(arraylist, resourcepackloader, (resourcepackloader1) -> { // CraftBukkit - decompile error
+ return resourcepackloader1; // CraftBukkit - decompile error
}, false);
}
}
2018-09-08 05:37:15 +02:00
@@ -1314,7 +1542,7 @@
2018-07-15 02:00:00 +02:00
ArrayList arraylist1 = Lists.newArrayList();
this.resourcePackRepository.d().forEach((resourcepackloader) -> {
- list.add(resourcepackloader.d());
+ arraylist1.add(resourcepackloader.d()); // CraftBukkit - decompile error
});
this.ac.a((List) arraylist1);
worlddata.O().clear();
2018-09-08 05:37:15 +02:00
@@ -1416,4 +1644,11 @@
2018-07-22 04:00:00 +02:00
return 0;
}
2016-02-29 22:32:46 +01:00
}
+
+ // CraftBukkit start
+ @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
}