Paper/nms-patches/MinecraftServer.patch

689 lines
34 KiB
Diff
Raw Normal View History

2015-05-25 12:37:24 +02:00
--- a/net/minecraft/server/MinecraftServer.java
+++ b/net/minecraft/server/MinecraftServer.java
2020-06-25 02:00:00 +02:00
@@ -9,6 +9,8 @@
import com.mojang.authlib.GameProfileRepository;
import com.mojang.authlib.minecraft.MinecraftSessionService;
import com.mojang.datafixers.DataFixer;
+import com.mojang.serialization.DynamicOps;
+import com.mojang.serialization.Lifecycle;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufOutputStream;
import io.netty.buffer.Unpooled;
2020-06-25 09:58:10 +02:00
@@ -54,6 +56,15 @@
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
2020-06-25 09:58:10 +02:00
+import com.google.common.collect.ImmutableSet;
2016-07-15 12:08:04 +02:00
+import jline.console.ConsoleReader;
2020-06-25 02:00:00 +02:00
+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
2020-06-25 02:00:00 +02:00
public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTask> implements IMojangStatistics, ICommandListener, AutoCloseable {
2015-02-26 23:41:06 +01:00
2020-06-25 09:58:10 +02:00
@@ -73,7 +84,7 @@
public final DataFixer dataConverterManager;
private String serverIp;
2020-06-25 02:00:00 +02:00
private int serverPort;
- protected final IRegistryCustom.Dimension f;
+ public final IRegistryCustom.Dimension f;
public final Map<ResourceKey<World>, WorldServer> worldServer;
private PlayerList playerList;
2020-06-25 02:00:00 +02:00
private volatile boolean isRunning;
2020-06-26 04:24:35 +02:00
@@ -124,6 +135,20 @@
2020-06-25 02:00:00 +02:00
private final DefinedStructureManager ak;
protected SaveData saveData;
+ // CraftBukkit start
2020-06-25 02:00:00 +02:00
+ public DataPackConfiguration datapackconfiguration;
+ 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 CommandDispatcher vanillaCommandDispatcher;
+ private boolean forceTicks;
+ // CraftBukkit end
+
2020-06-25 02:00:00 +02:00
public static <S extends MinecraftServer> S a(Function<Thread, S> function) {
AtomicReference<S> atomicreference = new AtomicReference();
Thread thread = new Thread(() -> {
2020-06-26 04:24:35 +02:00
@@ -133,21 +158,21 @@
2020-06-25 02:00:00 +02:00
thread.setUncaughtExceptionHandler((thread1, throwable) -> {
MinecraftServer.LOGGER.error(throwable);
});
- S s0 = (MinecraftServer) function.apply(thread);
+ S s0 = function.apply(thread); // CraftBukkit - decompile error
atomicreference.set(s0);
thread.start();
return s0;
}
- public MinecraftServer(Thread thread, IRegistryCustom.Dimension iregistrycustom_dimension, Convertable.ConversionSession convertable_conversionsession, SaveData savedata, ResourcePackRepository<ResourcePackLoader> resourcepackrepository, Proxy proxy, DataFixer datafixer, DataPackResources datapackresources, MinecraftSessionService minecraftsessionservice, GameProfileRepository gameprofilerepository, UserCache usercache, WorldLoadListenerFactory worldloadlistenerfactory) {
+ public MinecraftServer(OptionSet options, DataPackConfiguration datapackconfiguration, Thread thread, IRegistryCustom.Dimension iregistrycustom_dimension, Convertable.ConversionSession convertable_conversionsession, SaveData savedata, ResourcePackRepository<ResourcePackLoader> resourcepackrepository, Proxy proxy, DataFixer datafixer, DataPackResources datapackresources, MinecraftSessionService minecraftsessionservice, GameProfileRepository gameprofilerepository, UserCache usercache, WorldLoadListenerFactory worldloadlistenerfactory) {
2019-04-23 04:00:00 +02:00
super("Server");
2020-06-25 02:00:00 +02:00
this.m = new GameProfilerSwitcher(SystemUtils.a, this::ag);
this.methodProfiler = GameProfilerDisabled.a;
this.serverPing = new ServerPing();
this.r = new Random();
this.serverPort = -1;
- this.worldServer = Maps.newLinkedHashMap();
+ this.worldServer = Maps.newLinkedHashMap(); // CraftBukkit - keep order, k+v already use identity methods
this.isRunning = true;
this.h = new long[100];
this.K = "";
2020-06-26 04:24:35 +02:00
@@ -173,7 +198,34 @@
2020-06-25 02:00:00 +02:00
this.ak = new DefinedStructureManager(datapackresources.h(), convertable_conversionsession, datafixer);
this.serverThread = thread;
this.executorService = SystemUtils.f();
+ // CraftBukkit start
+ this.options = options;
2020-06-25 02:00:00 +02:00
+ this.datapackconfiguration = datapackconfiguration;
+ this.vanillaCommandDispatcher = datapackresources.commandDispatcher; // CraftBukkit
+ // 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
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");
2020-06-26 04:24:35 +02:00
@@ -186,7 +238,7 @@
2018-07-22 04:00:00 +02:00
2020-06-25 02:00:00 +02:00
public static void convertWorld(Convertable.ConversionSession convertable_conversionsession) {
if (convertable_conversionsession.isConvertable()) {
- MinecraftServer.LOGGER.info("Converting map!");
+ MinecraftServer.LOGGER.info("Converting map! {}", convertable_conversionsession.getLevelName()); // CraftBukkit
convertable_conversionsession.convert(new IProgressUpdate() {
private long a = SystemUtils.getMonotonicMillis();
2018-07-22 04:00:00 +02:00
2020-06-26 04:24:35 +02:00
@@ -209,48 +261,187 @@
2018-07-22 04:00:00 +02:00
}
2020-06-25 02:00:00 +02:00
- protected void loadWorld() {
- this.loadResourcesZip();
- this.saveData.a(this.getServerModName(), this.getModded().isPresent());
2019-04-23 04:00:00 +02:00
- WorldLoadListener worldloadlistener = this.worldLoadListenerFactory.create(11);
2020-06-25 02:00:00 +02:00
+ protected void loadWorld(String s) {
+ int worldCount = 3;
2020-06-25 02:00:00 +02:00
+
+ for (int worldId = 0; worldId < worldCount; ++worldId) {
+ WorldServer world;
2020-06-25 02:00:00 +02:00
+ WorldDataServer worlddata;
+ byte dimension = 0;
2020-06-25 02:00:00 +02:00
+ ResourceKey<WorldDimension> dimensionKey = WorldDimension.OVERWORLD;
2018-08-26 04:00:00 +02:00
+
2020-06-25 02:00:00 +02:00
+ if (worldId == 1) {
+ if (getAllowNether()) {
+ dimension = -1;
2020-06-25 02:00:00 +02:00
+ dimensionKey = WorldDimension.THE_NETHER;
+ } else {
+ continue;
+ }
2018-08-26 04:00:00 +02:00
+ }
2020-06-25 02:00:00 +02:00
+
+ if (worldId == 2) {
+ if (server.getAllowEnd()) {
+ dimension = 1;
2020-06-25 02:00:00 +02:00
+ dimensionKey = WorldDimension.THE_END;
+ } else {
+ continue;
+ }
2018-08-26 04:00:00 +02:00
+ }
+
+ String worldType = org.bukkit.World.Environment.getEnvironment(dimension).toString().toLowerCase();
+ String name = (dimension == 0) ? s : s + "_" + worldType;
2020-06-25 02:00:00 +02:00
+ Convertable.ConversionSession worldSession;
+ if (dimension == 0) {
+ worldSession = this.convertable;
+ } 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 ----");
+ }
+ }
+
2020-06-25 02:00:00 +02:00
+ try {
+ worldSession = Convertable.a(server.getWorldContainer().toPath()).c(name, dimensionKey);
+ } catch (IOException ex) {
+ throw new RuntimeException(ex);
+ }
+ MinecraftServer.convertWorld(worldSession); // Run conversion now
+ }
+
+ org.bukkit.generator.ChunkGenerator gen = this.server.getGenerator(name);
2020-06-25 02:00:00 +02:00
+
+ IRegistryCustom.Dimension iregistrycustom_dimension = IRegistryCustom.b();
+
+ RegistryReadOps<NBTBase> registryreadops = RegistryReadOps.a((DynamicOps) DynamicOpsNBT.a, this.dataPackResources.h(), (IRegistryCustom) iregistrycustom_dimension);
+ worlddata = (WorldDataServer) worldSession.a((DynamicOps) registryreadops, datapackconfiguration);
+ if (worlddata == null) {
+ WorldSettings worldsettings;
+ GeneratorSettings generatorsettings;
2019-04-23 04:00:00 +02:00
+
+ if (this.isDemoMode()) {
2020-06-25 02:00:00 +02:00
+ worldsettings = MinecraftServer.c;
+ generatorsettings = GeneratorSettings.b;
+ } else {
+ DedicatedServerProperties dedicatedserverproperties = ((DedicatedServer) this).getDedicatedServerProperties();
+
+ worldsettings = new WorldSettings(dedicatedserverproperties.levelName, dedicatedserverproperties.gamemode, dedicatedserverproperties.hardcore, dedicatedserverproperties.difficulty, false, new GameRules(), datapackconfiguration);
+ generatorsettings = options.has("bonusChest") ? dedicatedserverproperties.generatorSettings.k() : dedicatedserverproperties.generatorSettings;
2018-08-26 04:00:00 +02:00
+ }
2019-04-23 04:00:00 +02:00
+
2020-06-25 02:00:00 +02:00
+ worlddata = new WorldDataServer(worldsettings, generatorsettings, Lifecycle.stable());
+ }
+ 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)
+ if (options.has("forceUpgrade")) {
+ net.minecraft.server.Main.convertWorld(worldSession, DataConverterRegistry.a(), options.has("eraseCache"), () -> {
+ return true;
2020-06-25 09:58:10 +02:00
+ }, worlddata.getGeneratorSettings().e().c().stream().map((entry) -> {
+ return ResourceKey.a(IRegistry.ad, ((ResourceKey) entry.getKey()).a());
+ }).collect(ImmutableSet.toImmutableSet()));
2020-06-25 02:00:00 +02:00
+ }
+
+ IWorldDataServer iworlddataserver = worlddata;
+ GeneratorSettings generatorsettings = worlddata.getGeneratorSettings();
+ boolean flag = generatorsettings.isDebugWorld();
+ long i = generatorsettings.getSeed();
+ long j = BiomeManager.a(i);
+ List<MobSpawner> list = ImmutableList.of(new MobSpawnerPhantom(), new MobSpawnerPatrol(), new MobSpawnerCat(), new VillageSiege(), new MobSpawnerTrader(iworlddataserver));
+ RegistryMaterials<WorldDimension> registrymaterials = generatorsettings.e();
+ WorldDimension worlddimension = (WorldDimension) registrymaterials.a(dimensionKey);
+ DimensionManager dimensionmanager;
+ ChunkGenerator chunkgenerator;
+
+ if (worlddimension == null) {
+ dimensionmanager = DimensionManager.a();
+ chunkgenerator = GeneratorSettings.a((new Random()).nextLong());
+ } else {
+ dimensionmanager = worlddimension.b();
+ chunkgenerator = worlddimension.c();
+ }
+
+ ResourceKey<DimensionManager> typeKey = (ResourceKey) this.f.a().c(dimensionmanager).orElseThrow(() -> {
+ return new IllegalStateException("Unregistered dimension type: " + dimensionmanager);
+ });
+ ResourceKey<World> worldKey = ResourceKey.a(IRegistry.ae, dimensionKey.a());
+
+ if (worldId == 0) {
+ this.saveData = worlddata;
+ this.saveData.setGameType(((DedicatedServer) this).getDedicatedServerProperties().gamemode); // From DedicatedServer.init
+
+ WorldLoadListener worldloadlistener = this.worldLoadListenerFactory.create(11);
+
+ world = new WorldServer(this, this.executorService, worldSession, iworlddataserver, worldKey, typeKey, dimensionmanager, worldloadlistener, chunkgenerator, flag, j, list, true, org.bukkit.World.Environment.getEnvironment(dimension), gen);
2019-12-10 23:00:00 +01:00
+ WorldPersistentData worldpersistentdata = world.getWorldPersistentData();
+ this.initializeScoreboards(worldpersistentdata);
+ 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 {
2019-04-23 04:00:00 +02:00
+ WorldLoadListener worldloadlistener = this.worldLoadListenerFactory.create(11);
2020-06-25 02:00:00 +02:00
+ world = new WorldServer(this, this.executorService, worldSession, iworlddataserver, worldKey, typeKey, dimensionmanager, worldloadlistener, chunkgenerator, flag, j, ImmutableList.of(), true, org.bukkit.World.Environment.getEnvironment(dimension), gen);
2018-08-26 04:00:00 +02:00
+ }
2019-04-23 04:00:00 +02:00
+
2020-06-25 02:00:00 +02:00
+ worlddata.a(this.getServerModName(), this.getModded().isPresent());
+ this.initWorld(world, worlddata, saveData, worlddata.getGeneratorSettings());
+ this.server.getPluginManager().callEvent(new org.bukkit.event.world.WorldInitEvent(world.getWorld()));
+
2020-06-25 02:00:00 +02:00
+ this.worldServer.put(world.getDimensionKey(), world);
+ this.getPlayerList().setPlayerFileData(world);
2020-06-25 02:00:00 +02:00
- this.a(worldloadlistener);
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
+ }
2020-06-25 02:00:00 +02:00
this.updateWorldSettings();
- this.loadSpawn(worldloadlistener);
2019-04-23 04:00:00 +02:00
+ for (WorldServer worldserver : this.getWorlds()) {
+ this.loadSpawn(worldserver.getChunkProvider().playerChunkMap.worldLoadListener, worldserver);
+ this.server.getPluginManager().callEvent(new org.bukkit.event.world.WorldLoadEvent(worldserver.getWorld()));
2020-06-25 02:00:00 +02:00
+ }
+
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));
+ this.serverConnection.acceptConnections();
2019-04-23 04:00:00 +02:00
+ // CraftBukkit end
2020-06-25 02:00:00 +02:00
+
}
2019-06-21 12:00:00 +02:00
2020-06-25 02:00:00 +02:00
protected void updateWorldSettings() {}
2019-12-10 23:00:00 +01:00
2020-06-25 02:00:00 +02:00
- protected void a(WorldLoadListener worldloadlistener) {
- IWorldDataServer iworlddataserver = this.saveData.G();
- GeneratorSettings generatorsettings = this.saveData.getGeneratorSettings();
+ // CraftBukkit start
2020-06-25 02:00:00 +02:00
+ public void initWorld(WorldServer worldserver, IWorldDataServer iworlddataserver, SaveData saveData, GeneratorSettings generatorsettings) {
boolean flag = generatorsettings.isDebugWorld();
- long i = generatorsettings.getSeed();
- long j = BiomeManager.a(i);
- List<MobSpawner> list = ImmutableList.of(new MobSpawnerPhantom(), new MobSpawnerPatrol(), new MobSpawnerCat(), new VillageSiege(), new MobSpawnerTrader(iworlddataserver));
- RegistryMaterials<WorldDimension> registrymaterials = generatorsettings.e();
- WorldDimension worlddimension = (WorldDimension) registrymaterials.a(WorldDimension.OVERWORLD);
- DimensionManager dimensionmanager;
- Object object;
-
- if (worlddimension == null) {
- dimensionmanager = DimensionManager.a();
- object = GeneratorSettings.a((new Random()).nextLong());
- } else {
- dimensionmanager = worlddimension.b();
- object = worlddimension.c();
2019-04-23 04:00:00 +02:00
+ // CraftBukkit start
2020-06-25 02:00:00 +02:00
+ if (worldserver.generator != null) {
+ worldserver.getWorld().getPopulators().addAll(worldserver.generator.getDefaultPopulators(worldserver.getWorld()));
}
-
- ResourceKey<DimensionManager> resourcekey = (ResourceKey) this.f.a().c((Object) dimensionmanager).orElseThrow(() -> {
- return new IllegalStateException("Unregistered dimension type: " + dimensionmanager);
- });
- WorldServer worldserver = new WorldServer(this, this.executorService, this.convertable, iworlddataserver, World.OVERWORLD, resourcekey, dimensionmanager, worldloadlistener, (ChunkGenerator) object, flag, j, list, true);
-
- this.worldServer.put(World.OVERWORLD, worldserver);
- WorldPersistentData worldpersistentdata = worldserver.getWorldPersistentData();
-
- this.initializeScoreboards(worldpersistentdata);
- this.persistentCommandStorage = new PersistentCommandStorage(worldpersistentdata);
WorldBorder worldborder = worldserver.getWorldBorder();
2018-07-15 02:00:00 +02:00
2020-06-25 02:00:00 +02:00
worldborder.a(iworlddataserver.q());
2020-06-26 04:24:35 +02:00
@@ -275,34 +466,8 @@
2019-04-23 04:00:00 +02:00
2020-06-25 02:00:00 +02:00
iworlddataserver.c(true);
2019-04-23 04:00:00 +02:00
}
-
2020-06-25 02:00:00 +02:00
- this.getPlayerList().setPlayerFileData(worldserver);
- if (this.saveData.getCustomBossEvents() != null) {
- this.getBossBattleCustomData().load(this.saveData.getCustomBossEvents());
2019-04-23 04:00:00 +02:00
- }
-
2020-06-25 02:00:00 +02:00
- Iterator iterator = registrymaterials.c().iterator();
2019-04-23 04:00:00 +02:00
-
- while (iterator.hasNext()) {
2020-06-25 02:00:00 +02:00
- Entry<ResourceKey<WorldDimension>, WorldDimension> entry = (Entry) iterator.next();
- ResourceKey<WorldDimension> resourcekey1 = (ResourceKey) entry.getKey();
2019-04-23 04:00:00 +02:00
-
2020-06-25 02:00:00 +02:00
- if (resourcekey1 != WorldDimension.OVERWORLD) {
- ResourceKey<World> resourcekey2 = ResourceKey.a(IRegistry.ae, resourcekey1.a());
- DimensionManager dimensionmanager1 = ((WorldDimension) entry.getValue()).b();
- ResourceKey<DimensionManager> resourcekey3 = (ResourceKey) this.f.a().c((Object) dimensionmanager1).orElseThrow(() -> {
- return new IllegalStateException("Unregistered dimension type: " + dimensionmanager1);
- });
- ChunkGenerator chunkgenerator = ((WorldDimension) entry.getValue()).c();
- SecondaryWorldData secondaryworlddata = new SecondaryWorldData(this.saveData, iworlddataserver);
- WorldServer worldserver1 = new WorldServer(this, this.executorService, this.convertable, secondaryworlddata, resourcekey2, resourcekey3, dimensionmanager1, worldloadlistener, chunkgenerator, flag, j, ImmutableList.of(), false);
-
- worldborder.a((IWorldBorderListener) (new IWorldBorderListener.a(worldserver1.getWorldBorder())));
- this.worldServer.put(resourcekey2, worldserver1);
2019-04-23 04:00:00 +02:00
- }
- }
-
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
2020-06-25 02:00:00 +02:00
private static void a(WorldServer worldserver, IWorldDataServer iworlddataserver, boolean flag, boolean flag1, boolean flag2) {
ChunkGenerator chunkgenerator = worldserver.getChunkProvider().getChunkGenerator();
2020-06-26 04:24:35 +02:00
@@ -317,6 +482,21 @@
2020-06-25 02:00:00 +02:00
Random random = new Random(worldserver.getSeed());
BlockPosition blockposition = worldchunkmanager.a(0, worldserver.getSeaLevel(), 0, 256, list, random);
ChunkCoordIntPair chunkcoordintpair = blockposition == null ? new ChunkCoordIntPair(0, 0) : new ChunkCoordIntPair(blockposition);
+ // CraftBukkit start
+ if (worldserver.generator != null) {
+ Random rand = new Random(worldserver.getSeed());
+ org.bukkit.Location spawn = worldserver.generator.getFixedSpawnLocation(worldserver.getWorld(), rand);
+
+ if (spawn != null) {
+ if (spawn.getWorld() != worldserver.getWorld()) {
+ throw new IllegalStateException("Cannot set spawn point for " + iworlddataserver.getName() + " to be in another world (" + spawn.getWorld().getName() + ")");
+ } else {
+ iworlddataserver.setSpawn(new BlockPosition(spawn.getBlockX(), spawn.getBlockY(), spawn.getBlockZ()));
+ return;
+ }
+ }
+ }
+ // CraftBukkit end
if (blockposition == null) {
MinecraftServer.LOGGER.warn("Unable to find spawn biome");
2020-06-26 04:24:35 +02:00
@@ -363,7 +543,7 @@
2020-06-25 02:00:00 +02:00
}
if (flag) {
- WorldGenFeatureConfigured<?, ?> worldgenfeatureconfigured = WorldGenerator.BONUS_CHEST.b((WorldGenFeatureConfiguration) WorldGenFeatureConfiguration.k);
+ WorldGenFeatureConfigured<?, ?> worldgenfeatureconfigured = WorldGenerator.BONUS_CHEST.b(WorldGenFeatureConfiguration.k); // CraftBukkit - decompile error
worldgenfeatureconfigured.a(worldserver, worldserver.getStructureManager(), chunkgenerator, worldserver.random, new BlockPosition(iworlddataserver.a(), iworlddataserver.b(), iworlddataserver.c()));
}
2020-06-26 04:24:35 +02:00
@@ -383,8 +563,15 @@
2020-06-25 02:00:00 +02:00
iworlddataserver.setGameType(EnumGamemode.SPECTATOR);
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) {
2020-06-25 02:00:00 +02:00
- WorldServer worldserver = this.D();
2019-04-23 04:00:00 +02:00
+ // CraftBukkit start
+ public void loadSpawn(WorldLoadListener worldloadlistener, WorldServer worldserver) {
+ if (!worldserver.getWorld().getKeepSpawnInMemory()) {
+ return;
+ }
+
2020-06-25 02:00:00 +02:00
+ // WorldServer worldserver = this.D();
+ this.forceTicks = true;
2019-04-23 04:00:00 +02:00
+ // CraftBukkit end
2020-06-25 02:00:00 +02:00
MinecraftServer.LOGGER.info("Preparing start region for dimension {}", worldserver.getDimensionKey().a());
2019-04-23 04:00:00 +02:00
BlockPosition blockposition = worldserver.getSpawn();
2020-06-26 04:24:35 +02:00
@@ -397,17 +584,21 @@
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;
- this.sleepForTick();
+ // CraftBukkit start
2019-05-14 02:00:00 +02:00
+ // this.nextTick = SystemUtils.getMonotonicMillis() + 10L;
+ this.executeModerately();
+ // CraftBukkit end
}
2019-05-14 02:00:00 +02:00
- this.nextTick = SystemUtils.getMonotonicMillis() + 10L;
- this.sleepForTick();
2020-06-25 02:00:00 +02:00
- Iterator iterator = this.worldServer.values().iterator();
-
2019-04-23 04:00:00 +02:00
- while (iterator.hasNext()) {
2020-06-25 02:00:00 +02:00
- WorldServer worldserver1 = (WorldServer) iterator.next();
- ForcedChunk forcedchunk = (ForcedChunk) worldserver1.getWorldPersistentData().b(ForcedChunk::new, "chunks");
+ // CraftBukkit start
2019-05-14 02:00:00 +02:00
+ // this.nextTick = SystemUtils.getMonotonicMillis() + 10L;
+ this.executeModerately();
2020-06-25 02:00:00 +02:00
+ // Iterator iterator = this.worldServer.values().iterator();
+
2019-04-23 04:00:00 +02:00
+ if (true) {
2020-06-25 02:00:00 +02:00
+ WorldServer worldserver1 = worldserver;
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) {
2020-06-25 02:00:00 +02:00
LongIterator longiterator = forcedchunk.a().iterator();
2020-06-26 04:24:35 +02:00
@@ -421,11 +612,17 @@
}
}
2019-05-14 02:00:00 +02:00
- this.nextTick = SystemUtils.getMonotonicMillis() + 10L;
- this.sleepForTick();
+ // CraftBukkit start
2019-05-14 02:00:00 +02:00
+ // this.nextTick = SystemUtils.getMonotonicMillis() + 10L;
+ this.executeModerately();
+ // CraftBukkit end
2019-04-23 04:00:00 +02:00
worldloadlistener.b();
chunkproviderserver.getLightEngine().a(5);
2020-06-25 02:00:00 +02:00
this.ba();
2019-04-23 04:00:00 +02:00
+
+ // CraftBukkit start
+ this.forceTicks = false;
+ // CraftBukkit end
}
2020-06-25 02:00:00 +02:00
protected void loadResourcesZip() {
2020-06-26 04:24:35 +02:00
@@ -470,12 +667,16 @@
2020-06-25 02:00:00 +02:00
worldserver.save((IProgressUpdate) null, flag1, worldserver.savingDisabled && !flag2);
}
+ // CraftBukkit start - moved to WorldServer.save
+ /*
2020-06-25 02:00:00 +02:00
WorldServer worldserver1 = this.D();
IWorldDataServer iworlddataserver = this.saveData.G();
2020-06-25 02:00:00 +02:00
iworlddataserver.a(worldserver1.getWorldBorder().t());
this.saveData.setCustomBossEvents(this.getBossBattleCustomData().save());
this.convertable.a(this.f, this.saveData, this.getPlayerList().save());
+ */
+ // CraftBukkit end
return flag3;
}
2020-06-26 04:24:35 +02:00
@@ -484,8 +685,29 @@
2019-04-23 04:00:00 +02:00
this.stop();
}
+ // 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;
+ }
+ }
+ // CraftBukkit end
+
2019-04-23 04:00:00 +02:00
protected void stop() {
+ // 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");
+ // 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();
}
2020-06-26 04:24:35 +02:00
@@ -494,6 +716,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
}
2018-08-26 04:00:00 +02:00
MinecraftServer.LOGGER.info("Saving worlds");
2020-06-26 04:24:35 +02:00
@@ -571,14 +794,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
2018-07-15 02:00:00 +02:00
long j = i / 50L;
+ 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;
2020-06-25 02:00:00 +02:00
GameProfilerTick gameprofilertick = GameProfilerTick.a("Server");
2020-06-26 04:24:35 +02:00
@@ -624,6 +849,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
2019-04-23 04:00:00 +02:00
this.exit();
}
2020-06-26 04:24:35 +02:00
@@ -632,8 +863,15 @@
}
private boolean canSleepForTick() {
2020-06-25 02:00:00 +02:00
- return this.isEntered() || SystemUtils.getMonotonicMillis() < (this.X ? this.W : this.nextTick);
+ // CraftBukkit start
2020-06-25 02:00:00 +02:00
+ return this.forceTicks || this.isEntered() || SystemUtils.getMonotonicMillis() < (this.X ? this.W : this.nextTick);
2019-06-21 12:00:00 +02:00
+ }
+
+ private void executeModerately() {
+ this.executeAll();
+ java.util.concurrent.locks.LockSupport.parkNanos("executing tasks", 1000L);
2019-06-21 12:00:00 +02:00
}
+ // CraftBukkit end
2019-06-21 12:00:00 +02:00
protected void sleepForTick() {
this.executeAll();
2020-06-26 04:24:35 +02:00
@@ -739,7 +977,7 @@
2019-04-23 04:00:00 +02:00
this.serverPing.b().a(agameprofile);
}
2019-04-23 04:00:00 +02:00
- if (this.ticks % 6000 == 0) {
+ 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-06-26 04:24:35 +02:00
@@ -769,22 +1007,39 @@
}
2019-04-23 04:00:00 +02:00
protected void b(BooleanSupplier booleansupplier) {
+ 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();
+ // 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
+ }
+ }
+
2019-06-21 12:00:00 +02:00
while (iterator.hasNext()) {
WorldServer worldserver = (WorldServer) iterator.next();
2020-06-25 02:00:00 +02:00
this.methodProfiler.a(() -> {
return worldserver + " " + worldserver.getDimensionKey().a();
});
+ /* 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.getDimensionKey());
this.methodProfiler.exit();
2020-01-21 22:00:00 +01:00
}
2020-06-25 02:00:00 +02:00
+ // CraftBukkit end */
2020-01-21 22:00:00 +01:00
2020-06-25 02:00:00 +02:00
this.methodProfiler.enter("tick");
2020-06-26 04:24:35 +02:00
@@ -868,7 +1123,7 @@
}
public String getServerModName() {
- return "vanilla";
+ return server.getName(); // CraftBukkit - cb > vanilla!
}
public CrashReport b(CrashReport crashreport) {
@@ -1217,16 +1472,17 @@
2020-06-25 02:00:00 +02:00
public CompletableFuture<Void> a(Collection<String> collection) {
CompletableFuture<Void> completablefuture = CompletableFuture.supplyAsync(() -> {
- Stream stream = collection.stream();
+ Stream<String> stream = collection.stream(); // CraftBukkit - decompile error
ResourcePackRepository resourcepackrepository = this.resourcePackRepository;
this.resourcePackRepository.getClass();
- return (ImmutableList) stream.map(resourcepackrepository::a).filter(Objects::nonNull).map(ResourcePackLoader::d).collect(ImmutableList.toImmutableList());
+ return stream.map(resourcepackrepository::a).filter(Objects::nonNull).map(ResourcePackLoader::d).collect(ImmutableList.toImmutableList()); // CraftBukkit - decompile error
}, this).thenCompose((immutablelist) -> {
return DataPackResources.a(immutablelist, this.j() ? CommandDispatcher.ServerType.DEDICATED : CommandDispatcher.ServerType.INTEGRATED, this.h(), this.executorService, this);
}).thenAcceptAsync((datapackresources) -> {
this.dataPackResources.close();
this.dataPackResources = datapackresources;
+ this.server.syncCommands(); // SPIGOT-5884: Lost on reload
this.resourcePackRepository.a(collection);
this.saveData.a(a(this.resourcePackRepository));
datapackresources.i();
@@ -1592,6 +1848,22 @@
2014-11-29 01:53:49 +01: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
+ }
+
2020-06-25 02:00:00 +02:00
+ public boolean isDebugging() {
+ return false;
+ }
+
2016-02-29 22:32:46 +01:00
+ @Deprecated
+ public static MinecraftServer getServer() {
+ return (Bukkit.getServer() instanceof CraftServer) ? ((CraftServer) Bukkit.getServer()).getServer() : null;
2016-02-29 22:32:46 +01:00
+ }
+ // CraftBukkit end
2020-06-25 02:00:00 +02:00
+
private void a(@Nullable GameProfilerTick gameprofilertick) {
if (this.O) {
this.O = false;