3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-23 23:00:08 +01:00
Paper/nms-patches/MinecraftServer.patch

686 Zeilen
33 KiB
Diff

--- a/net/minecraft/server/MinecraftServer.java
+++ b/net/minecraft/server/MinecraftServer.java
@@ -47,6 +47,13 @@
import org.apache.commons.lang3.Validate;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
+// CraftBukkit start
+import jline.console.ConsoleReader;
+import org.bukkit.Bukkit;
+import org.bukkit.craftbukkit.CraftServer;
+import org.bukkit.craftbukkit.Main;
+import org.bukkit.event.server.ServerLoadEvent;
+// CraftBukkit end
public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTask> implements IMojangStatistics, ICommandListener, AutoCloseable, Runnable {
@@ -65,7 +72,7 @@
public final DataFixer dataConverterManager;
private String serverIp;
private int serverPort = -1;
- 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;
private volatile boolean isRunning = true;
private boolean isStopped;
@@ -103,7 +110,7 @@
private final GameProfileRepository gameProfileRepository;
private final UserCache userCache;
private long Y;
- 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);
});
@@ -132,7 +139,21 @@
@Nullable
private String au;
- public MinecraftServer(File file, Proxy proxy, DataFixer datafixer, CommandDispatcher commanddispatcher, YggdrasilAuthenticationService yggdrasilauthenticationservice, MinecraftSessionService minecraftsessionservice, GameProfileRepository gameprofilerepository, UserCache usercache, WorldLoadListenerFactory worldloadlistenerfactory, String s) {
+ // 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;
+ public File bukkitDataPackFolder;
+ public CommandDispatcher vanillaCommandDispatcher;
+ private boolean forceTicks;
+ // CraftBukkit end
+
+ public MinecraftServer(OptionSet options, Proxy proxy, DataFixer datafixer, CommandDispatcher commanddispatcher, YggdrasilAuthenticationService yggdrasilauthenticationservice, MinecraftSessionService minecraftsessionservice, GameProfileRepository gameprofilerepository, UserCache usercache, WorldLoadListenerFactory worldloadlistenerfactory, String s) {
super("Server");
this.ad = new ResourceManager(EnumResourcePackType.SERVER_DATA, this.serverThread);
this.resourcePackRepository = new ResourcePackRepository<>(ResourcePackLoader::new);
@@ -145,15 +166,15 @@
this.an = new CustomFunctionData(this);
this.ao = new CircularTimer();
this.proxy = proxy;
- this.commandDispatcher = commanddispatcher;
+ this.commandDispatcher = this.vanillaCommandDispatcher = commanddispatcher; // CraftBukkit
this.yggdrasilAuthenticationService = yggdrasilauthenticationservice;
this.minecraftSessionService = minecraftsessionservice;
this.gameProfileRepository = gameprofilerepository;
this.userCache = usercache;
- this.universe = file;
- this.serverConnection = new ServerConnection(this);
+ // this.universe = file; // CraftBukkit
+ this.serverConnection = new ServerConnection(this); // CraftBukkit
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
this.dataConverterManager = datafixer;
this.ad.a((IReloadListener) this.ai);
this.ad.a((IReloadListener) this.ah);
@@ -162,7 +183,32 @@
this.ad.a((IReloadListener) this.am);
this.executorService = SystemUtils.e();
this.J = s;
+ // CraftBukkit start
+ this.options = options;
+ // Try to see if we're actually running in a terminal, disable jline if not
+ if (System.console() == null && System.getProperty("jline.terminal") == null) {
+ 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
private void initializeScoreboards(WorldPersistentData worldpersistentdata) {
PersistentScoreboard persistentscoreboard = (PersistentScoreboard) worldpersistentdata.a(PersistentScoreboard::new, "scoreboard");
@@ -198,11 +244,11 @@
}
if (this.forceUpgrade) {
- MinecraftServer.LOGGER.info("Forcing world upgrade!");
- WorldData worlddata = this.getConvertable().b(this.getWorld());
+ MinecraftServer.LOGGER.info("Forcing world upgrade! {}", s); // CraftBukkit
+ WorldData worlddata = this.getConvertable().b(s); // CraftBukkit
if (worlddata != null) {
- WorldUpgrader worldupgrader = new WorldUpgrader(this.getWorld(), this.getConvertable(), worlddata, this.eraseCache);
+ WorldUpgrader worldupgrader = new WorldUpgrader(s, this.getConvertable(), worlddata, this.eraseCache); // CraftBukkit
IChatBaseComponent ichatbasecomponent = null;
while (!worldupgrader.b()) {
@@ -241,8 +287,9 @@
}
protected void a(String s, String s1, long i, WorldType worldtype, JsonElement jsonelement) {
- this.convertWorld(s);
+ // this.convertWorld(s); // CraftBukkit - moved down
this.b((IChatBaseComponent) (new ChatMessage("menu.loadingLevel", new Object[0])));
+ /* CraftBukkit start - Remove ticktime arrays and worldsettings
WorldNBTStorage worldnbtstorage = this.getConvertable().a(s, this);
this.a(this.getWorld(), worldnbtstorage);
@@ -267,24 +314,134 @@
}
this.a(worldnbtstorage.getDirectory(), worlddata);
- WorldLoadListener worldloadlistener = this.worldLoadListenerFactory.create(11);
+ */
+ int worldCount = 3;
- this.a(worldnbtstorage, worlddata, worldsettings, worldloadlistener);
- this.a(this.getDifficulty(), true);
- this.loadSpawn(worldloadlistener);
- }
+ for (int j = 0; j < worldCount; ++j) {
+ WorldServer world;
+ WorldData worlddata;
+ byte dimension = 0;
+
+ if (j == 1) {
+ if (getAllowNether()) {
+ dimension = -1;
+ } else {
+ continue;
+ }
+ }
- protected void a(WorldNBTStorage worldnbtstorage, WorldData worlddata, WorldSettings worldsettings, WorldLoadListener worldloadlistener) {
- if (this.isDemoMode()) {
- worlddata.a(MinecraftServer.c);
+ if (j == 2) {
+ if (server.getAllowEnd()) {
+ dimension = 1;
+ } else {
+ continue;
+ }
+ }
+
+ String worldType = org.bukkit.World.Environment.getEnvironment(dimension).toString().toLowerCase();
+ String name = (dimension == 0) ? s : s + "_" + worldType;
+ this.convertWorld(name); // Run conversion now
+
+ org.bukkit.generator.ChunkGenerator gen = this.server.getGenerator(name);
+ WorldSettings worldsettings = new WorldSettings(i, this.getGamemode(), this.getGenerateStructures(), this.isHardcore(), worldtype);
+ worldsettings.setGeneratorSettings(jsonelement);
+
+ if (j == 0) {
+ WorldNBTStorage worldnbtstorage = new WorldNBTStorage(server.getWorldContainer(), s1, this, this.dataConverterManager);
+ worlddata = worldnbtstorage.getWorldData();
+ if (worlddata == null) {
+ worlddata = new WorldData(worldsettings, s1);
+ }
+ 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)
+ this.a(worldnbtstorage.getDirectory(), worlddata);
+ WorldLoadListener worldloadlistener = this.worldLoadListenerFactory.create(11);
+
+ if (this.isDemoMode()) {
+ worlddata.a(MinecraftServer.c);
+ }
+ world = new WorldServer(this, this.executorService, worldnbtstorage, worlddata, DimensionManager.OVERWORLD, this.methodProfiler, worldloadlistener, org.bukkit.World.Environment.getEnvironment(dimension), gen);
+
+ this.initializeScoreboards(world.getWorldPersistentData());
+ this.server.scoreboardManager = new org.bukkit.craftbukkit.scoreboard.CraftScoreboardManager(this, world.getScoreboard());
+ } else {
+ String dim = "DIM" + dimension;
+
+ File newWorld = new File(new File(name), dim);
+ File oldWorld = new File(new File(s), dim);
+ 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()) {
+ 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(oldLevelDat, new File(new File(name), "level.dat"));
+ org.apache.commons.io.FileUtils.copyDirectory(new File(new File(s), "data"), new File(new File(name), "data"));
+ } 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 ----");
+ }
+ }
+
+ WorldNBTStorage worldnbtstorage = new WorldNBTStorage(server.getWorldContainer(), name, this, this.dataConverterManager);
+ // world =, b0 to dimension, s1 to name, added Environment and gen
+ worlddata = worldnbtstorage.getWorldData();
+ if (worlddata == null) {
+ worlddata = new WorldData(worldsettings, name);
+ }
+ 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)
+ 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);
+ }
+
+ this.initWorld(world, worlddata, worldsettings);
+ this.server.getPluginManager().callEvent(new org.bukkit.event.world.WorldInitEvent(world.getWorld()));
+
+ this.worldServer.put(world.getWorldProvider().getDimensionManager(), world);
+ this.getPlayerList().setPlayerFileData(world);
+
+ if (worlddata.getCustomBossEvents() != null) {
+ this.getBossBattleCustomData().a(worlddata.getCustomBossEvents());
+ }
+ }
+ this.a(this.getDifficulty(), true);
+ for (WorldServer worldserver : this.getWorlds()) {
+ this.loadSpawn(worldserver.getChunkProvider().playerChunkMap.worldLoadListener, worldserver);
+ this.server.getPluginManager().callEvent(new org.bukkit.event.world.WorldLoadEvent(worldserver.getWorld()));
}
- WorldServer worldserver = new WorldServer(this, this.executorService, worldnbtstorage, worlddata, DimensionManager.OVERWORLD, this.methodProfiler, worldloadlistener);
+ this.server.enablePlugins(org.bukkit.plugin.PluginLoadOrder.POSTWORLD);
+ this.server.getPluginManager().callEvent(new ServerLoadEvent(ServerLoadEvent.LoadType.STARTUP));
+ // CraftBukkit end
- this.worldServer.put(DimensionManager.OVERWORLD, worldserver);
- this.initializeScoreboards(worldserver.getWorldPersistentData());
- worldserver.getWorldBorder().b(worlddata);
- WorldServer worldserver1 = this.getWorldServer(DimensionManager.OVERWORLD);
+ }
+
+ // CraftBukkit start
+ public void initWorld(WorldServer worldserver1, WorldData worlddata, WorldSettings worldsettings) {
+ worldserver1.getWorldBorder().b(worlddata);
+
+ // CraftBukkit start
+ if (worldserver1.generator != null) {
+ worldserver1.getWorld().getPopulators().addAll(worldserver1.generator.getDefaultPopulators(worldserver1.getWorld()));
+ }
+ // CraftBukkit end
if (!worlddata.u()) {
try {
@@ -308,23 +465,8 @@
worlddata.d(true);
}
-
- this.getPlayerList().setPlayerFileData(worldserver1);
- if (worlddata.getCustomBossEvents() != null) {
- this.getBossBattleCustomData().a(worlddata.getCustomBossEvents());
- }
-
- 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));
- }
- }
-
}
+ // CraftBukkit end
private void a(WorldData worlddata) {
worlddata.f(false);
@@ -343,6 +485,25 @@
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();
List<ResourcePackLoader> list = Lists.newArrayList();
@@ -363,11 +524,18 @@
this.b(worlddata);
}
- public void loadSpawn(WorldLoadListener worldloadlistener) {
+ // CraftBukkit start
+ public void loadSpawn(WorldLoadListener worldloadlistener, WorldServer worldserver) {
+ if (!worldserver.getWorld().getKeepSpawnInMemory()) {
+ return;
+ }
+
this.b((IChatBaseComponent) (new ChatMessage("menu.generatingTerrain", new Object[0])));
- WorldServer worldserver = this.getWorldServer(DimensionManager.OVERWORLD);
+ // WorldServer worldserver = this.getWorldServer(DimensionManager.OVERWORLD);
+ this.forceTicks = true;
+ // CraftBukkit end
- MinecraftServer.LOGGER.info("Preparing start region for dimension " + DimensionManager.a(worldserver.worldProvider.getDimensionManager()));
+ MinecraftServer.LOGGER.info("Preparing start region for dimension '{}'/{}", worldserver.getWorldData().getName(), DimensionManager.a(worldserver.worldProvider.getDimensionManager().getType())); // CraftBukkit
BlockPosition blockposition = worldserver.getSpawn();
worldloadlistener.a(new ChunkCoordIntPair(blockposition));
@@ -378,17 +546,21 @@
chunkproviderserver.addTicket(TicketType.START, new ChunkCoordIntPair(blockposition), 11, Unit.INSTANCE);
while (chunkproviderserver.b() != 441) {
- this.nextTick = SystemUtils.getMonotonicMillis() + 10L;
- this.sleepForTick();
+ // CraftBukkit start
+ // this.nextTick = SystemUtils.getMonotonicMillis() + 10L;
+ this.executeModerately();
+ // CraftBukkit end
}
- this.nextTick = SystemUtils.getMonotonicMillis() + 10L;
- this.sleepForTick();
- Iterator iterator = DimensionManager.a().iterator();
-
- while (iterator.hasNext()) {
- DimensionManager dimensionmanager = (DimensionManager) iterator.next();
- ForcedChunk forcedchunk = (ForcedChunk) this.getWorldServer(dimensionmanager).getWorldPersistentData().b(ForcedChunk::new, "chunks");
+ // CraftBukkit start
+ // this.nextTick = SystemUtils.getMonotonicMillis() + 10L;
+ this.executeModerately();
+ // Iterator iterator = DimensionManager.a().iterator();
+
+ if (true) {
+ DimensionManager dimensionmanager = worldserver.worldProvider.getDimensionManager();
+ ForcedChunk forcedchunk = (ForcedChunk) worldserver.getWorldPersistentData().b(ForcedChunk::new, "chunks");
+ // CraftBukkit end
if (forcedchunk != null) {
WorldServer worldserver1 = this.getWorldServer(dimensionmanager);
@@ -403,10 +575,16 @@
}
}
- this.nextTick = SystemUtils.getMonotonicMillis() + 10L;
- this.sleepForTick();
+ // CraftBukkit start
+ // this.nextTick = SystemUtils.getMonotonicMillis() + 10L;
+ this.executeModerately();
+ // CraftBukkit end
worldloadlistener.b();
chunkproviderserver.getLightEngine().a(5);
+
+ // CraftBukkit start
+ this.forceTicks = false;
+ // CraftBukkit end
}
protected void a(String s, WorldNBTStorage worldnbtstorage) {
@@ -451,12 +629,16 @@
}
}
+ // CraftBukkit start - moved to WorldServer.save
+ /*
WorldServer worldserver1 = this.getWorldServer(DimensionManager.OVERWORLD);
WorldData worlddata = worldserver1.getWorldData();
worldserver1.getWorldBorder().a(worlddata);
worlddata.c(this.getBossBattleCustomData().c());
worldserver1.getDataManager().saveWorldData(worlddata, this.getPlayerList().r());
+ */
+ // CraftBukkit end
return flag3;
}
@@ -465,8 +647,29 @@
this.stop();
}
+ // CraftBukkit start
+ private boolean hasStopped = false;
+ private final Object stopLock = new Object();
+ public final boolean hasStopped() {
+ synchronized (stopLock) {
+ return hasStopped;
+ }
+ }
+ // CraftBukkit end
+
protected void stop() {
+ // CraftBukkit start - prevent double stopping on multiple threads
+ synchronized(stopLock) {
+ if (hasStopped) return;
+ hasStopped = true;
+ }
+ // CraftBukkit end
MinecraftServer.LOGGER.info("Stopping server");
+ // CraftBukkit start
+ if (this.server != null) {
+ this.server.disablePlugins();
+ }
+ // CraftBukkit end
if (this.getServerConnection() != null) {
this.getServerConnection().b();
}
@@ -475,6 +678,7 @@
MinecraftServer.LOGGER.info("Saving players");
this.playerList.savePlayers();
this.playerList.shutdown();
+ try { Thread.sleep(100); } catch (InterruptedException ex) {} // CraftBukkit - SPIGOT-625 - give server at least a chance to send packets
}
MinecraftServer.LOGGER.info("Saving worlds");
@@ -544,14 +748,16 @@
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
long j = i / 50L;
+ if (server.getWarnOnOverload()) // CraftBukkit
MinecraftServer.LOGGER.warn("Can't keep up! Is the server overloaded? Running {}ms or {} ticks behind", i, j);
this.nextTick += j * 50L;
this.lastOverloadTime = this.nextTick;
}
+ MinecraftServer.currentTick = (int) (System.currentTimeMillis() / 50); // CraftBukkit
this.nextTick += 50L;
if (this.S) {
this.S = false;
@@ -598,6 +804,12 @@
} 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
this.exit();
}
@@ -606,8 +818,15 @@
}
private boolean canSleepForTick() {
- return this.isEntered() || SystemUtils.getMonotonicMillis() < (this.ab ? this.aa : this.nextTick);
+ // CraftBukkit start
+ return this.forceTicks || this.isEntered() || SystemUtils.getMonotonicMillis() < (this.ab ? this.aa : this.nextTick);
+ }
+
+ private void executeModerately() {
+ this.executeAll();
+ java.util.concurrent.locks.LockSupport.parkNanos("executing tasks", 1000L);
}
+ // CraftBukkit end
protected void sleepForTick() {
this.executeAll();
@@ -708,7 +927,7 @@
this.serverPing.b().a(agameprofile);
}
- if (this.ticks % 6000 == 0) {
+ if (autosavePeriod > 0 && this.ticks % autosavePeriod == 0) { // CraftBukkit
MinecraftServer.LOGGER.debug("Autosave started");
this.methodProfiler.enter("save");
this.playerList.savePlayers();
@@ -738,23 +957,40 @@
}
protected void b(BooleanSupplier booleansupplier) {
+ this.server.getScheduler().mainThreadHeartbeat(this.ticks); // CraftBukkit
this.methodProfiler.enter("commandFunctions");
this.getFunctionData().tick();
this.methodProfiler.exitEnter("levels");
Iterator iterator = this.getWorlds().iterator();
+ // 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);
+ entityplayer.playerConnection.sendPacket(new PacketPlayOutUpdateTime(entityplayer.world.getTime(), entityplayer.getPlayerTime(), entityplayer.world.getGameRules().getBoolean(GameRules.DO_DAYLIGHT_CYCLE))); // Add support for per player time
+ }
+ }
+
while (iterator.hasNext()) {
WorldServer worldserver = (WorldServer) iterator.next();
- if (worldserver.worldProvider.getDimensionManager() == DimensionManager.OVERWORLD || this.getAllowNether()) {
+ if (true || worldserver.worldProvider.getDimensionManager() == DimensionManager.OVERWORLD || this.getAllowNether()) { // CraftBukkit
this.methodProfiler.a(() -> {
return worldserver.getWorldData().getName() + " " + IRegistry.DIMENSION_TYPE.getKey(worldserver.worldProvider.getDimensionManager());
});
+ /* Drop global time updates
if (this.ticks % 20 == 0) {
this.methodProfiler.enter("timeSync");
this.playerList.a((Packet) (new PacketPlayOutUpdateTime(worldserver.getTime(), worldserver.getDayTime(), worldserver.getGameRules().getBoolean(GameRules.DO_DAYLIGHT_CYCLE))), worldserver.worldProvider.getDimensionManager());
this.methodProfiler.exit();
}
+ // CraftBukkit end */
this.methodProfiler.enter("tick");
@@ -793,7 +1029,8 @@
this.tickables.add(runnable);
}
- public static void main(String[] astring) {
+ 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");
@@ -816,15 +1053,17 @@
optionparser.printHelpOn(System.err);
return;
}
+ */ // CraftBukkit end
+ 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;
}
@@ -836,14 +1075,15 @@
DispenserRegistry.init();
DispenserRegistry.c();
- String s = (String) optionset.valueOf(optionspec8);
+ String s = "."; // 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(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);
+ 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);
+ /* CraftBukkit start
dedicatedserver.i((String) optionset.valueOf(optionspec7));
dedicatedserver.setPort((Integer) optionset.valueOf(optionspec10));
dedicatedserver.e(optionset.has(optionspec2));
@@ -866,6 +1106,29 @@
thread.setUncaughtExceptionHandler(new DefaultUncaughtExceptionHandler(MinecraftServer.LOGGER));
Runtime.getRuntime().addShutdownHook(thread);
+ */
+
+ if (optionset.has("port")) {
+ int port = (Integer) optionset.valueOf("port");
+ if (port > 0) {
+ dedicatedserver.setPort(port);
+ }
+ }
+
+ if (optionset.has("universe")) {
+ dedicatedserver.universe = (File) optionset.valueOf("universe");
+ }
+
+ if (optionset.has("forceUpgrade")) {
+ dedicatedserver.setForceUpgrade(true);
+ }
+
+ if (optionset.has("eraseCache")) {
+ dedicatedserver.setEraseCache(true);
+ }
+
+ dedicatedserver.serverThread.start();
+ // CraftBukkit end
} catch (Exception exception) {
MinecraftServer.LOGGER.fatal("Failed to start the minecraft server", exception);
}
@@ -885,7 +1148,9 @@
}
public void startServerThread() {
+ /* CraftBukkit start - prevent abuse
this.serverThread.start();
+ // CraftBukkit end */
}
public File d(String s) {
@@ -940,7 +1205,7 @@
}
public String getServerModName() {
- return "vanilla";
+ return server.getName(); // CraftBukkit - cb > vanilla!
}
public CrashReport b(CrashReport crashreport) {
@@ -979,7 +1244,7 @@
}
public boolean E() {
- return this.universe != null;
+ return true; // CraftBukkit
}
@Override
@@ -1482,4 +1747,16 @@
}
public abstract boolean b(GameProfile gameprofile);
+
+ // CraftBukkit start
+ @Override
+ public boolean isMainThread() {
+ return super.isMainThread() || this.isStopped(); // CraftBukkit - MC-142590
+ }
+
+ @Deprecated
+ public static MinecraftServer getServer() {
+ return (Bukkit.getServer() instanceof CraftServer) ? ((CraftServer) Bukkit.getServer()).getServer() : null;
+ }
+ // CraftBukkit end
}