2015-05-25 12:37:24 +02:00
--- a/net/minecraft/server/MinecraftServer.java
+++ b/net/minecraft/server/MinecraftServer.java
2024-04-23 17:15:00 +02:00
@@ -168,13 +168,37 @@
2023-03-14 17:30:00 +01:00
import net.minecraft.world.phys.Vec3D;
2022-02-28 16:00:00 +01:00
import org.slf4j.Logger;
2021-03-08 22:47:33 +01:00
2016-05-10 13:47:39 +02:00
+// CraftBukkit start
2023-12-05 17:40:00 +01:00
+import com.mojang.serialization.Dynamic;
2021-03-08 22:47:33 +01:00
+import com.mojang.serialization.Lifecycle;
2022-06-07 18:00:00 +02:00
+import java.util.Random;
2016-07-15 12:08:04 +02:00
+import jline.console.ConsoleReader;
2020-06-25 02:00:00 +02:00
+import joptsimple.OptionSet;
2023-12-05 17:40:00 +01:00
+import net.minecraft.nbt.NbtException;
+import net.minecraft.nbt.ReportedNbtException;
2021-03-15 23:00:00 +01:00
+import net.minecraft.server.dedicated.DedicatedServer;
+import net.minecraft.server.dedicated.DedicatedServerProperties;
+import net.minecraft.util.datafix.DataConverterRegistry;
2022-12-07 17:00:00 +01:00
+import net.minecraft.world.level.levelgen.WorldDimensions;
2022-06-07 18:00:00 +02:00
+import net.minecraft.world.level.levelgen.presets.WorldPresets;
2023-12-05 17:40:00 +01:00
+import net.minecraft.world.level.storage.LevelDataAndDimensions;
2021-03-15 23:00:00 +01:00
+import net.minecraft.world.level.storage.WorldDataServer;
2023-12-05 17:40:00 +01:00
+import net.minecraft.world.level.storage.WorldInfo;
2023-06-07 17:30:00 +02:00
+import net.minecraft.world.level.validation.ContentValidationException;
2016-02-29 22:32:46 +01:00
+import org.bukkit.Bukkit;
2024-04-23 17:15:00 +02:00
+import org.bukkit.craftbukkit.CraftRegistry;
2016-02-29 22:32:46 +01:00
+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
2021-03-08 22:47:33 +01:00
+
2023-09-21 18:40:00 +02:00
public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTask> implements ServerInfo, ICommandListener, AutoCloseable {
2015-02-26 23:41:06 +01:00
2022-02-28 16:00:00 +01:00
public static final Logger LOGGER = LogUtils.getLogger();
2023-12-05 17:40:00 +01:00
public static final String VANILLA_BRAND = "vanilla";
private static final float AVERAGE_TICK_TIME_SMOOTHING = 0.8F;
private static final int TICK_STATS_SPAN = 100;
- private static final long OVERLOADED_THRESHOLD_NANOS = 20L * TimeRange.NANOSECONDS_PER_SECOND / 20L;
+ private static final long OVERLOADED_THRESHOLD_NANOS = 30L * TimeRange.NANOSECONDS_PER_SECOND / 20L; // CraftBukkit
private static final int OVERLOADED_TICKS_THRESHOLD = 20;
private static final long OVERLOADED_WARNING_INTERVAL_NANOS = 10L * TimeRange.NANOSECONDS_PER_SECOND;
private static final int OVERLOADED_TICKS_WARNING_INTERVAL = 100;
2024-04-23 17:15:00 +02:00
@@ -260,6 +284,19 @@
private final PotionBrewer potionBrewing;
2021-11-21 23:00:00 +01:00
private volatile boolean isSaving;
2014-11-25 22:32:16 +01:00
+ // CraftBukkit start
2022-12-07 17:00:00 +01:00
+ public final WorldLoader.a worldLoader;
2014-11-25 22:32:16 +01:00
+ public org.bukkit.craftbukkit.CraftServer server;
+ public OptionSet options;
+ public org.bukkit.command.ConsoleCommandSender console;
+ public ConsoleReader reader;
+ public static int currentTick = (int) (System.currentTimeMillis() / 50);
+ public java.util.Queue<Runnable> processQueue = new java.util.concurrent.ConcurrentLinkedQueue<Runnable>();
+ public int autosavePeriod;
2018-07-21 03:20:38 +02:00
+ public CommandDispatcher vanillaCommandDispatcher;
2019-04-25 07:33:13 +02:00
+ private boolean forceTicks;
2014-11-25 22:32:16 +01:00
+ // CraftBukkit end
+
2021-11-21 23:00:00 +01:00
public static <S extends MinecraftServer> S spin(Function<Thread, S> function) {
2020-06-25 02:00:00 +02:00
AtomicReference<S> atomicreference = new AtomicReference();
Thread thread = new Thread(() -> {
2024-04-23 17:15:00 +02:00
@@ -273,14 +310,14 @@
2021-11-21 23:00:00 +01:00
thread.setPriority(8);
}
2020-06-25 02:00:00 +02:00
- S s0 = (MinecraftServer) function.apply(thread);
+ S s0 = function.apply(thread); // CraftBukkit - decompile error
atomicreference.set(s0);
thread.start();
return s0;
}
2022-06-07 18:00:00 +02:00
- public MinecraftServer(Thread thread, Convertable.ConversionSession convertable_conversionsession, ResourcePackRepository resourcepackrepository, WorldStem worldstem, Proxy proxy, DataFixer datafixer, Services services, WorldLoadListenerFactory worldloadlistenerfactory) {
2022-12-16 01:13:10 +01:00
+ public MinecraftServer(OptionSet options, WorldLoader.a worldLoader, Thread thread, Convertable.ConversionSession convertable_conversionsession, ResourcePackRepository resourcepackrepository, WorldStem worldstem, Proxy proxy, DataFixer datafixer, Services services, WorldLoadListenerFactory worldloadlistenerfactory) {
2019-04-23 04:00:00 +02:00
super("Server");
2021-06-11 07:00:00 +02:00
this.metricsRecorder = InactiveMetricsRecorder.INSTANCE;
2021-11-21 23:00:00 +01:00
this.profiler = this.metricsRecorder.getProfiler();
2024-04-23 17:15:00 +02:00
@@ -303,7 +340,7 @@
2023-09-21 18:40:00 +02:00
this.customBossEvents = new BossBattleCustomData();
2022-12-07 17:00:00 +01:00
this.registries = worldstem.registries();
2022-06-07 18:00:00 +02:00
this.worldData = worldstem.worldData();
2022-12-07 17:00:00 +01:00
- if (!this.registries.compositeAccess().registryOrThrow(Registries.LEVEL_STEM).containsKey(WorldDimension.OVERWORLD)) {
+ if (false && !this.registries.compositeAccess().registryOrThrow(Registries.LEVEL_STEM).containsKey(WorldDimension.OVERWORLD)) { // CraftBukkit - initialised later
2022-06-07 18:00:00 +02:00
throw new IllegalStateException("Missing Overworld dimension data");
} else {
this.proxy = proxy;
2024-04-23 17:15:00 +02:00
@@ -328,6 +365,33 @@
2022-06-07 18:00:00 +02:00
this.executor = SystemUtils.backgroundExecutor();
2024-04-23 17:15:00 +02:00
this.potionBrewing = PotionBrewer.bootstrap(this.worldData.enabledFeatures());
2022-06-07 18:00:00 +02:00
}
2014-11-25 22:32:16 +01:00
+ // CraftBukkit start
+ this.options = options;
2022-12-07 17:00:00 +01:00
+ this.worldLoader = worldLoader;
2022-02-28 16:00:00 +01:00
+ this.vanillaCommandDispatcher = worldstem.dataPackResources().commands; // CraftBukkit
2014-11-25 22:32:16 +01:00
+ // 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));
2023-09-21 18:40:00 +02:00
+ // CraftBukkit end
2014-11-25 22:32:16 +01:00
}
2018-07-15 02:00:00 +02:00
2021-11-21 23:00:00 +01:00
private void readScoreboard(WorldPersistentData worldpersistentdata) {
2024-04-23 17:15:00 +02:00
@@ -336,7 +400,7 @@
2018-07-22 04:00:00 +02:00
2021-11-21 23:00:00 +01:00
protected abstract boolean initServer() throws IOException;
- protected void loadLevel() {
+ protected void loadLevel(String s) { // CraftBukkit
if (!JvmProfiler.INSTANCE.isRunning()) {
;
}
2024-04-23 17:15:00 +02:00
@@ -344,12 +408,8 @@
2021-11-21 23:00:00 +01:00
boolean flag = false;
ProfiledDuration profiledduration = JvmProfiler.INSTANCE.onWorldLoadedStarted();
- this.worldData.setModdedInfo(this.getServerModName(), this.getModdedStatus().shouldReportAsModified());
2024-04-23 17:15:00 +02:00
- WorldLoadListener worldloadlistener = this.progressListenerFactory.create(this.worldData.getGameRules().getInt(GameRules.RULE_SPAWN_CHUNK_RADIUS));
2021-11-21 23:00:00 +01:00
+ loadWorld0(s); // CraftBukkit
2018-07-22 04:00:00 +02:00
2021-11-21 23:00:00 +01:00
- this.createLevels(worldloadlistener);
- this.forceDifficulty();
- this.prepareLevels(worldloadlistener);
if (profiledduration != null) {
profiledduration.finish();
}
2024-04-23 17:15:00 +02:00
@@ -366,23 +426,217 @@
2018-07-22 04:00:00 +02:00
2023-09-21 18:40:00 +02:00
protected void forceDifficulty() {}
2018-07-22 04:00:00 +02:00
2023-09-21 18:40:00 +02:00
- protected void createLevels(WorldLoadListener worldloadlistener) {
- IWorldDataServer iworlddataserver = this.worldData.overworldData();
- boolean flag = this.worldData.isDebugWorld();
- IRegistry<WorldDimension> iregistry = this.registries.compositeAccess().registryOrThrow(Registries.LEVEL_STEM);
- WorldOptions worldoptions = this.worldData.worldGenOptions();
- long i = worldoptions.seed();
- long j = BiomeManager.obfuscateSeed(i);
- List<MobSpawner> list = ImmutableList.of(new MobSpawnerPhantom(), new MobSpawnerPatrol(), new MobSpawnerCat(), new VillageSiege(), new MobSpawnerTrader(iworlddataserver));
- WorldDimension worlddimension = (WorldDimension) iregistry.get(WorldDimension.OVERWORLD);
- WorldServer worldserver = new WorldServer(this, this.executor, this.storageSource, iworlddataserver, World.OVERWORLD, worlddimension, worldloadlistener, flag, j, list, true, (RandomSequences) null);
2021-11-21 23:00:00 +01:00
+ // CraftBukkit start
+ private void loadWorld0(String s) {
2021-06-11 07:00:00 +02:00
+ Convertable.ConversionSession worldSession = this.storageSource;
2023-09-21 18:57:13 +02:00
- this.levels.put(World.OVERWORLD, worldserver);
- WorldPersistentData worldpersistentdata = worldserver.getDataStorage();
2024-04-23 17:15:00 +02:00
+ IRegistryCustom.Dimension iregistrycustom_dimension = this.registries.compositeAccess();
+ IRegistry<WorldDimension> dimensions = iregistrycustom_dimension.registryOrThrow(Registries.LEVEL_STEM);
2022-12-07 17:00:00 +01:00
+ for (WorldDimension worldDimension : dimensions) {
+ ResourceKey<WorldDimension> dimensionKey = dimensions.getResourceKey(worldDimension).get();
2023-09-21 18:57:13 +02:00
- this.readScoreboard(worldpersistentdata);
- this.commandStorage = new PersistentCommandStorage(worldpersistentdata);
2014-11-25 22:32:16 +01:00
+ WorldServer world;
2021-04-16 02:36:05 +02:00
+ int dimension = 0;
2021-11-21 23:00:00 +01:00
+
2021-06-11 07:00:00 +02:00
+ if (dimensionKey == WorldDimension.NETHER) {
2021-11-21 23:00:00 +01:00
+ if (isNetherEnabled()) {
2014-11-25 22:32:16 +01:00
+ dimension = -1;
+ } else {
+ continue;
+ }
2021-06-11 07:00:00 +02:00
+ } else if (dimensionKey == WorldDimension.END) {
2014-11-25 22:32:16 +01:00
+ if (server.getAllowEnd()) {
+ dimension = 1;
+ } else {
+ continue;
+ }
2021-04-16 02:36:05 +02:00
+ } else if (dimensionKey != WorldDimension.OVERWORLD) {
+ dimension = -999;
2018-08-26 04:00:00 +02:00
+ }
2023-09-21 18:40:00 +02:00
+
2021-11-21 23:00:00 +01:00
+ String worldType = (dimension == -999) ? dimensionKey.location().getNamespace() + "_" + dimensionKey.location().getPath() : org.bukkit.World.Environment.getEnvironment(dimension).toString().toLowerCase();
2021-04-16 02:36:05 +02:00
+ String name = (dimensionKey == WorldDimension.OVERWORLD) ? s : s + "_" + worldType;
+ if (dimension != 0) {
2021-11-21 23:00:00 +01:00
+ File newWorld = Convertable.getStorageFolder(new File(name).toPath(), dimensionKey).toFile();
+ File oldWorld = Convertable.getStorageFolder(new File(s).toPath(), dimensionKey).toFile();
2020-06-26 01:49:40 +02:00
+ File oldLevelDat = new File(new File(s), "level.dat"); // The data folders exist on first run as they are created in the PersistentCollection constructor above, but the level.dat won't
+
+ if (!newWorld.isDirectory() && oldWorld.isDirectory() && oldLevelDat.isFile()) {
+ 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 ----");
+ }
+ }
2023-03-14 17:30:00 +01:00
+
2020-06-25 02:00:00 +02:00
+ try {
2023-06-07 17:30:00 +02:00
+ worldSession = Convertable.createDefault(server.getWorldContainer().toPath()).validateAndCreateAccess(name, dimensionKey);
+ } catch (IOException | ContentValidationException ex) {
2020-06-25 02:00:00 +02:00
+ throw new RuntimeException(ex);
+ }
+ }
2023-09-21 18:57:13 +02:00
+
2023-12-05 17:40:00 +01:00
+ Dynamic<?> dynamic;
+ if (worldSession.hasWorldData()) {
+ WorldInfo worldinfo;
+
+ try {
+ dynamic = worldSession.getDataTag();
+ worldinfo = worldSession.getSummary(dynamic);
+ } catch (NbtException | ReportedNbtException | IOException ioexception) {
+ Convertable.b convertable_b = worldSession.getLevelDirectory();
+
+ MinecraftServer.LOGGER.warn("Failed to load world data from {}", convertable_b.dataFile(), ioexception);
+ MinecraftServer.LOGGER.info("Attempting to use fallback");
+
+ try {
+ dynamic = worldSession.getDataTagFallback();
+ worldinfo = worldSession.getSummary(dynamic);
+ } catch (NbtException | ReportedNbtException | IOException ioexception1) {
+ MinecraftServer.LOGGER.error("Failed to load world data from {}", convertable_b.oldDataFile(), ioexception1);
+ MinecraftServer.LOGGER.error("Failed to load world data from {} and {}. World files may be corrupted. Shutting down.", convertable_b.dataFile(), convertable_b.oldDataFile());
+ return;
+ }
+
+ worldSession.restoreLevelDataFromOld();
+ }
+
+ if (worldinfo.requiresManualConversion()) {
+ MinecraftServer.LOGGER.info("This world must be opened in an older version (like 1.6.4) to be safely converted");
+ return;
+ }
+
+ if (!worldinfo.isCompatible()) {
+ MinecraftServer.LOGGER.info("This world was created by an incompatible version.");
+ return;
+ }
+ } else {
+ dynamic = null;
+ }
+
2021-04-16 02:36:05 +02:00
+ org.bukkit.generator.ChunkGenerator gen = this.server.getGenerator(name);
SPIGOT-5880, SPIGOT-5567: New ChunkGenerator API
## **Current API**
The current world generation API is very old and limited when you want to make more complex world generation. Resulting in some hard to fix bugs such as that you cannot modify blocks outside the chunk in the BlockPopulator (which should and was per the docs possible), or strange behavior such as SPIGOT-5880.
## **New API**
With the new API, the generation is more separate in multiple methods and is more in line with Vanilla chunk generation. The new API is designed to as future proof as possible. If for example a new generation step is added it can easily also be added as a step in API by simply creating the method for it. On the other side if a generation step gets removed, the method can easily be called after another, which is the case with surface and bedrock. The new API and changes are also fully backwards compatible with old chunk generators.
### **Changes in the new api**
**Extra generation steps:**
Noise, surface, bedrock and caves are added as steps. With those generation steps three extra methods for Vanilla generation are also added. Those new methods provide the ChunkData instead of returning one. The reason for this is, that the ChunkData is now backed by a ChunkAccess. With this, each step has the information of the step before and the Vanilla information (if chosen by setting a 'should' method to true). The old method is deprecated.
**New class BiomeProvider**
The BiomeProvider acts as Biome source and wrapper for the NMS class WorldChunkManager. With this the underlying Vanilla ChunkGeneration knows which Biome to use for the structure and decoration generation. (Fixes: SPIGOT-5880). Although the List of Biomes which is required in BiomeProvider, is currently not much in use in Vanilla, I decided to add it to future proof the API when it may be required in later versions of Minecraft.
The BiomeProvider is also separated from the ChunkGenerator for plugins which only want to change the biome map, such as single Biome worlds or if some biomes should be more present than others.
**Deprecated isParallelCapable**
Mojang has and is pushing to a more multi threaded chunk generation. This should also be the case for custom chunk generators. This is why the new API only supports multi threaded generation. This does not affect the old API, which is still checking this.
**Base height method added**
This method was added to also bring the Minecraft generator and Bukkit generator more in line. With this it is possible to return the max height of a location (before decorations). This is useful to let most structures know were to place them. This fixes SPIGOT-5567. (This fixes not all structures placement, desert pyramids for example are still way up at y-level 64, This however is more a vanilla bug and should be fixed at Mojangs end).
**WorldInfo Class**
The World object was swapped for a WorldInfo object. This is because many methods of the World object won't work during world generation and would mostly likely result in a deadlock. It contains any information a plugin should need to identify the world.
**BlockPopulator Changes**
Instead of directly manipulating a chunk, changes are now made to a new class LimitedRegion, this class provides methods to populated the chunk and its surrounding area. The wrapping is done so that the population can be moved into the place where Minecraft generates decorations. Where there is no chunk to access yet. By moving it into this place the generation is now async and the surrounding area of the chunk can also be used.
For common methods between the World and LimitedRegion a RegionAccessor was added.
By: DerFrZocker <derrieple@gmail.com>
2021-08-15 00:08:16 +02:00
+ org.bukkit.generator.BiomeProvider biomeProvider = this.server.getBiomeProvider(name);
2023-09-21 18:57:13 +02:00
+
2022-12-07 17:00:00 +01:00
+ WorldDataServer worlddata;
+ WorldLoader.a worldloader_a = this.worldLoader;
+ IRegistry<WorldDimension> iregistry = worldloader_a.datapackDimensions().registryOrThrow(Registries.LEVEL_STEM);
2023-12-05 17:40:00 +01:00
+ if (dynamic != null) {
+ LevelDataAndDimensions leveldataanddimensions = Convertable.getLevelDataAndDimensions(dynamic, worldloader_a.dataConfiguration(), iregistry, worldloader_a.datapackWorldgen());
2022-12-07 17:00:00 +01:00
+
2023-12-05 17:40:00 +01:00
+ worlddata = (WorldDataServer) leveldataanddimensions.worldData();
2022-12-07 17:00:00 +01:00
+ } else {
2020-06-25 02:00:00 +02:00
+ WorldSettings worldsettings;
2022-12-07 17:00:00 +01:00
+ WorldOptions worldoptions;
+ WorldDimensions worlddimensions;
2019-04-23 04:00:00 +02:00
+
2021-11-21 23:00:00 +01:00
+ if (this.isDemo()) {
2021-06-11 07:00:00 +02:00
+ worldsettings = MinecraftServer.DEMO_SETTINGS;
2022-12-07 17:00:00 +01:00
+ worldoptions = WorldOptions.DEMO_OPTIONS;
+ worlddimensions = WorldPresets.createNormalWorldDimensions(worldloader_a.datapackWorldgen());
2020-06-25 02:00:00 +02:00
+ } else {
2021-11-21 23:00:00 +01:00
+ DedicatedServerProperties dedicatedserverproperties = ((DedicatedServer) this).getProperties();
2020-06-25 02:00:00 +02:00
+
2022-12-07 17:00:00 +01:00
+ worldsettings = new WorldSettings(dedicatedserverproperties.levelName, dedicatedserverproperties.gamemode, dedicatedserverproperties.hardcore, dedicatedserverproperties.difficulty, false, new GameRules(), worldloader_a.dataConfiguration());
+ worldoptions = options.has("bonusChest") ? dedicatedserverproperties.worldOptions.withBonusChest(true) : dedicatedserverproperties.worldOptions;
+ worlddimensions = dedicatedserverproperties.createDimensions(worldloader_a.datapackWorldgen());
2018-08-26 04:00:00 +02:00
+ }
2019-04-23 04:00:00 +02:00
+
2022-12-07 17:00:00 +01:00
+ WorldDimensions.b worlddimensions_b = worlddimensions.bake(iregistry);
+ Lifecycle lifecycle = worlddimensions_b.lifecycle().add(worldloader_a.datapackWorldgen().allRegistriesLifecycle());
+
+ worlddata = new WorldDataServer(worldsettings, worldoptions, worlddimensions_b.specialWorldProperty(), lifecycle);
2020-06-25 02:00:00 +02: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)
+ if (options.has("forceUpgrade")) {
2021-11-21 23:00:00 +01:00
+ net.minecraft.server.Main.forceUpgrade(worldSession, DataConverterRegistry.getDataFixer(), options.has("eraseCache"), () -> {
2020-06-25 02:00:00 +02:00
+ return true;
2024-04-23 17:15:00 +02:00
+ }, iregistrycustom_dimension, options.has("recreateRegionFiles"));
2020-06-25 02:00:00 +02:00
+ }
+
2022-06-07 18:00:00 +02:00
+ WorldDataServer iworlddataserver = worlddata;
2022-12-07 17:00:00 +01:00
+ boolean flag = worlddata.isDebugWorld();
+ WorldOptions worldoptions = worlddata.worldGenOptions();
+ long i = worldoptions.seed();
2021-11-21 23:00:00 +01:00
+ long j = BiomeManager.obfuscateSeed(i);
2020-06-25 02:00:00 +02:00
+ List<MobSpawner> list = ImmutableList.of(new MobSpawnerPhantom(), new MobSpawnerPatrol(), new MobSpawnerCat(), new VillageSiege(), new MobSpawnerTrader(iworlddataserver));
2022-12-07 17:00:00 +01:00
+ WorldDimension worlddimension = (WorldDimension) dimensions.get(dimensionKey);
2020-06-25 02:00:00 +02:00
+
2022-12-07 17:00:00 +01:00
+ org.bukkit.generator.WorldInfo worldInfo = new org.bukkit.craftbukkit.generator.CraftWorldInfo(iworlddataserver, worldSession, org.bukkit.World.Environment.getEnvironment(dimension), worlddimension.type().value());
SPIGOT-5880, SPIGOT-5567: New ChunkGenerator API
## **Current API**
The current world generation API is very old and limited when you want to make more complex world generation. Resulting in some hard to fix bugs such as that you cannot modify blocks outside the chunk in the BlockPopulator (which should and was per the docs possible), or strange behavior such as SPIGOT-5880.
## **New API**
With the new API, the generation is more separate in multiple methods and is more in line with Vanilla chunk generation. The new API is designed to as future proof as possible. If for example a new generation step is added it can easily also be added as a step in API by simply creating the method for it. On the other side if a generation step gets removed, the method can easily be called after another, which is the case with surface and bedrock. The new API and changes are also fully backwards compatible with old chunk generators.
### **Changes in the new api**
**Extra generation steps:**
Noise, surface, bedrock and caves are added as steps. With those generation steps three extra methods for Vanilla generation are also added. Those new methods provide the ChunkData instead of returning one. The reason for this is, that the ChunkData is now backed by a ChunkAccess. With this, each step has the information of the step before and the Vanilla information (if chosen by setting a 'should' method to true). The old method is deprecated.
**New class BiomeProvider**
The BiomeProvider acts as Biome source and wrapper for the NMS class WorldChunkManager. With this the underlying Vanilla ChunkGeneration knows which Biome to use for the structure and decoration generation. (Fixes: SPIGOT-5880). Although the List of Biomes which is required in BiomeProvider, is currently not much in use in Vanilla, I decided to add it to future proof the API when it may be required in later versions of Minecraft.
The BiomeProvider is also separated from the ChunkGenerator for plugins which only want to change the biome map, such as single Biome worlds or if some biomes should be more present than others.
**Deprecated isParallelCapable**
Mojang has and is pushing to a more multi threaded chunk generation. This should also be the case for custom chunk generators. This is why the new API only supports multi threaded generation. This does not affect the old API, which is still checking this.
**Base height method added**
This method was added to also bring the Minecraft generator and Bukkit generator more in line. With this it is possible to return the max height of a location (before decorations). This is useful to let most structures know were to place them. This fixes SPIGOT-5567. (This fixes not all structures placement, desert pyramids for example are still way up at y-level 64, This however is more a vanilla bug and should be fixed at Mojangs end).
**WorldInfo Class**
The World object was swapped for a WorldInfo object. This is because many methods of the World object won't work during world generation and would mostly likely result in a deadlock. It contains any information a plugin should need to identify the world.
**BlockPopulator Changes**
Instead of directly manipulating a chunk, changes are now made to a new class LimitedRegion, this class provides methods to populated the chunk and its surrounding area. The wrapping is done so that the population can be moved into the place where Minecraft generates decorations. Where there is no chunk to access yet. By moving it into this place the generation is now async and the surrounding area of the chunk can also be used.
For common methods between the World and LimitedRegion a RegionAccessor was added.
By: DerFrZocker <derrieple@gmail.com>
2021-08-15 00:08:16 +02:00
+ if (biomeProvider == null && gen != null) {
+ biomeProvider = gen.getDefaultBiomeProvider(worldInfo);
+ }
+
2022-12-07 17:00:00 +01:00
+ ResourceKey<World> worldKey = ResourceKey.create(Registries.DIMENSION, dimensionKey.location());
2021-03-08 22:47:33 +01:00
+
2021-04-16 02:36:05 +02:00
+ if (dimensionKey == WorldDimension.OVERWORLD) {
2021-06-11 07:00:00 +02:00
+ this.worldData = worlddata;
2021-11-21 23:00:00 +01:00
+ this.worldData.setGameType(((DedicatedServer) this).getProperties().gamemode); // From DedicatedServer.init
2023-09-21 18:40:00 +02:00
+
2024-04-23 17:15:00 +02:00
+ WorldLoadListener worldloadlistener = this.progressListenerFactory.create(this.worldData.getGameRules().getInt(GameRules.RULE_SPAWN_CHUNK_RADIUS));
2023-09-21 18:40:00 +02:00
+
2023-06-07 17:30:00 +02:00
+ world = new WorldServer(this, this.executor, worldSession, iworlddataserver, worldKey, worlddimension, worldloadlistener, flag, j, list, true, (RandomSequences) null, org.bukkit.World.Environment.getEnvironment(dimension), gen, biomeProvider);
2021-11-21 23:00:00 +01:00
+ WorldPersistentData worldpersistentdata = world.getDataStorage();
+ this.readScoreboard(worldpersistentdata);
2014-11-25 22:32:16 +01:00
+ this.server.scoreboardManager = new org.bukkit.craftbukkit.scoreboard.CraftScoreboardManager(this, world.getScoreboard());
2021-06-11 07:00:00 +02:00
+ this.commandStorage = new PersistentCommandStorage(worldpersistentdata);
2018-08-26 04:00:00 +02:00
+ } else {
2024-04-23 17:15:00 +02:00
+ WorldLoadListener worldloadlistener = this.progressListenerFactory.create(worldData.getGameRules().getInt(GameRules.RULE_SPAWN_CHUNK_RADIUS));
2023-06-07 17:30:00 +02:00
+ world = new WorldServer(this, this.executor, worldSession, iworlddataserver, worldKey, worlddimension, worldloadlistener, flag, j, ImmutableList.of(), true, this.overworld().getRandomSequences(), org.bukkit.World.Environment.getEnvironment(dimension), gen, biomeProvider);
2018-08-26 04:00:00 +02:00
+ }
2022-06-07 18:00:00 +02:00
+
2021-11-21 23:00:00 +01:00
+ worlddata.setModdedInfo(this.getServerModName(), this.getModdedStatus().shouldReportAsModified());
2022-12-07 17:00:00 +01:00
+ this.initWorld(world, worlddata, worldData, worldoptions);
2022-07-27 20:00:00 +02:00
+
2022-08-14 02:46:41 +02:00
+ this.addLevel(world);
2021-11-21 23:00:00 +01:00
+ this.getPlayerList().addWorldborderListener(world);
2022-07-27 20:00:00 +02:00
+
2019-04-23 04:00:00 +02:00
+ if (worlddata.getCustomBossEvents() != null) {
2024-04-23 17:15:00 +02:00
+ this.getCustomBossEvents().load(worlddata.getCustomBossEvents(), this.registryAccess());
2018-07-15 02:00:00 +02:00
+ }
2019-05-04 12:54:32 +02:00
+ }
2021-11-21 23:00:00 +01:00
+ this.forceDifficulty();
+ for (WorldServer worldserver : this.getAllLevels()) {
+ this.prepareLevels(worldserver.getChunkSource().chunkMap.progressListener, worldserver);
2021-07-06 16:00:00 +02:00
+ worldserver.entityManager.tick(); // SPIGOT-6526: Load pending entities so they are available to the API
2019-05-02 07:15:53 +02:00
+ this.server.getPluginManager().callEvent(new org.bukkit.event.world.WorldLoadEvent(worldserver.getWorld()));
2022-03-04 08:53:19 +01:00
+ }
2022-08-14 02:46:41 +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));
2021-06-11 07:00:00 +02:00
+ this.connection.acceptConnections();
2021-11-21 23:00:00 +01:00
+ }
2022-12-07 17:00:00 +01:00
+
+ public void initWorld(WorldServer worldserver, IWorldDataServer iworlddataserver, SaveData saveData, WorldOptions worldoptions) {
+ boolean flag = saveData.isDebugWorld();
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()));
2021-11-21 23:00:00 +01:00
+ }
2020-06-25 02:00:00 +02:00
WorldBorder worldborder = worldserver.getWorldBorder();
2022-01-31 22:13:13 +01:00
+ worldborder.applySettings(iworlddataserver.getWorldBorder()); // CraftBukkit - move up so that WorldBorder is set during WorldInitEvent
+ this.server.getPluginManager().callEvent(new org.bukkit.event.world.WorldInitEvent(worldserver.getWorld())); // CraftBukkit - SPIGOT-5569: Call WorldInitEvent before any chunks are generated
2018-07-15 02:00:00 +02:00
2021-11-21 23:00:00 +01:00
if (!iworlddataserver.isInitialized()) {
2022-01-31 22:13:13 +01:00
try {
2024-04-23 17:15:00 +02:00
@@ -406,30 +660,8 @@
2021-11-21 23:00:00 +01:00
iworlddataserver.setInitialized(true);
2019-04-23 04:00:00 +02:00
}
2021-11-21 23:00:00 +01:00
- this.getPlayerList().addWorldborderListener(worldserver);
2021-06-11 07:00:00 +02:00
- if (this.worldData.getCustomBossEvents() != null) {
2024-04-23 17:15:00 +02:00
- this.getCustomBossEvents().load(this.worldData.getCustomBossEvents(), this.registryAccess());
2019-04-23 04:00:00 +02:00
- }
-
2023-06-07 17:30:00 +02:00
- RandomSequences randomsequences = worldserver.getRandomSequences();
2022-02-28 16:00:00 +01:00
- Iterator iterator = iregistry.entrySet().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();
2020-08-11 23:00:00 +02:00
- ResourceKey<WorldDimension> resourcekey = (ResourceKey) entry.getKey();
2019-04-23 04:00:00 +02:00
-
2020-08-11 23:00:00 +02:00
- if (resourcekey != WorldDimension.OVERWORLD) {
2022-12-07 17:00:00 +01:00
- ResourceKey<World> resourcekey1 = ResourceKey.create(Registries.DIMENSION, resourcekey.location());
2021-06-11 07:00:00 +02:00
- SecondaryWorldData secondaryworlddata = new SecondaryWorldData(this.worldData, iworlddataserver);
2023-06-07 17:30:00 +02:00
- WorldServer worldserver1 = new WorldServer(this, this.executor, this.storageSource, secondaryworlddata, resourcekey1, (WorldDimension) entry.getValue(), worldloadlistener, flag, j, ImmutableList.of(), false, randomsequences);
2020-06-25 02:00:00 +02:00
-
2021-11-21 23:00:00 +01:00
- worldborder.addListener(new IWorldBorderListener.a(worldserver1.getWorldBorder()));
2021-06-11 07:00:00 +02:00
- this.levels.put(resourcekey1, worldserver1);
2019-04-23 04:00:00 +02:00
- }
- }
-
2022-01-31 22:13:13 +01:00
- worldborder.applySettings(iworlddataserver.getWorldBorder());
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
2021-11-21 23:00:00 +01:00
private static void setInitialSpawn(WorldServer worldserver, IWorldDataServer iworlddataserver, boolean flag, boolean flag1) {
2021-06-11 07:00:00 +02:00
if (flag1) {
2024-04-23 17:15:00 +02:00
@@ -437,6 +669,21 @@
2021-11-21 23:00:00 +01:00
} else {
2022-06-07 18:00:00 +02:00
ChunkProviderServer chunkproviderserver = worldserver.getChunkSource();
ChunkCoordIntPair chunkcoordintpair = new ChunkCoordIntPair(chunkproviderserver.randomState().sampler().findSpawnPosition());
2020-06-25 02:00:00 +02:00
+ // 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()) {
2021-11-21 23:00:00 +01:00
+ throw new IllegalStateException("Cannot set spawn point for " + iworlddataserver.getLevelName() + " to be in another world (" + spawn.getWorld().getName() + ")");
2020-06-25 02:00:00 +02:00
+ } else {
2020-08-11 23:00:00 +02:00
+ iworlddataserver.setSpawn(new BlockPosition(spawn.getBlockX(), spawn.getBlockY(), spawn.getBlockZ()), spawn.getYaw());
2020-06-25 02:00:00 +02:00
+ return;
+ }
+ }
+ }
+ // CraftBukkit end
2022-06-07 18:00:00 +02:00
int i = chunkproviderserver.getGenerator().getSpawnHeight(worldserver);
2020-06-25 02:00:00 +02:00
2021-11-21 23:00:00 +01:00
if (i < worldserver.getMinBuildHeight()) {
2024-04-23 17:15:00 +02:00
@@ -495,8 +742,11 @@
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
2021-11-21 23:00:00 +01:00
- public void prepareLevels(WorldLoadListener worldloadlistener) {
- WorldServer worldserver = this.overworld();
2019-04-23 04:00:00 +02:00
+ // CraftBukkit start
2021-11-21 23:00:00 +01:00
+ public void prepareLevels(WorldLoadListener worldloadlistener, WorldServer worldserver) {
+ // WorldServer worldserver = this.overworld();
2019-04-25 07:33:13 +02:00
+ this.forceTicks = true;
2019-04-23 04:00:00 +02:00
+ // CraftBukkit end
2014-11-25 22:32:16 +01:00
2021-11-21 23:00:00 +01:00
MinecraftServer.LOGGER.info("Preparing start region for dimension {}", worldserver.dimension().location());
BlockPosition blockposition = worldserver.getSharedSpawnPos();
2024-04-23 17:15:00 +02:00
@@ -506,20 +756,22 @@
2019-04-25 07:33:13 +02:00
2023-12-05 17:40:00 +01:00
this.nextTickTimeNanos = SystemUtils.getNanos();
2024-04-23 17:15:00 +02:00
worldserver.setDefaultSpawnPos(blockposition, worldserver.getSharedSpawnAngle());
- int i = this.getGameRules().getInt(GameRules.RULE_SPAWN_CHUNK_RADIUS);
+ int i = worldserver.getGameRules().getInt(GameRules.RULE_SPAWN_CHUNK_RADIUS); // CraftBukkit - per-world
int j = i > 0 ? MathHelper.square(WorldLoadListener.calculateDiameter(i)) : 0;
2022-03-04 08:53:19 +01:00
2024-04-23 17:15:00 +02:00
while (chunkproviderserver.getTickingGenerated() < j) {
2023-12-05 17:40:00 +01:00
- this.nextTickTimeNanos = SystemUtils.getNanos() + MinecraftServer.PREPARE_LEVELS_DEFAULT_DELAY_NANOS;
2021-11-21 23:00:00 +01:00
- this.waitUntilNextTick();
2024-04-23 17:15:00 +02:00
+ // CraftBukkit start
+ // this.nextTickTimeNanos = SystemUtils.getNanos() + MinecraftServer.PREPARE_LEVELS_DEFAULT_DELAY_NANOS;
+ this.executeModerately();
2019-04-25 07:33:13 +02:00
}
2014-11-25 22:32:16 +01:00
2023-12-05 17:40:00 +01:00
- this.nextTickTimeNanos = SystemUtils.getNanos() + MinecraftServer.PREPARE_LEVELS_DEFAULT_DELAY_NANOS;
2021-11-21 23:00:00 +01:00
- this.waitUntilNextTick();
2021-06-11 07:00:00 +02:00
- Iterator iterator = this.levels.values().iterator();
2023-12-05 17:40:00 +01:00
+ // this.nextTickTimeNanos = SystemUtils.getNanos() + MinecraftServer.PREPARE_LEVELS_DEFAULT_DELAY_NANOS;
2019-04-25 07:33:13 +02:00
+ this.executeModerately();
2021-11-21 23:00:00 +01:00
+ // Iterator iterator = this.levels.values().iterator();
2022-03-04 08:53:19 +01:00
- while (iterator.hasNext()) {
- WorldServer worldserver1 = (WorldServer) iterator.next();
2019-04-23 04:00:00 +02:00
+ if (true) {
2020-06-25 02:00:00 +02:00
+ WorldServer worldserver1 = worldserver;
2019-04-23 04:00:00 +02:00
+ // CraftBukkit end
2023-09-21 18:40:00 +02:00
ForcedChunk forcedchunk = (ForcedChunk) worldserver1.getDataStorage().get(ForcedChunk.factory(), "chunks");
2019-04-23 04:00:00 +02:00
if (forcedchunk != null) {
2024-04-23 17:15:00 +02:00
@@ -534,10 +786,17 @@
2019-04-25 07:33:13 +02:00
}
}
2023-12-05 17:40:00 +01:00
- this.nextTickTimeNanos = SystemUtils.getNanos() + MinecraftServer.PREPARE_LEVELS_DEFAULT_DELAY_NANOS;
2021-11-21 23:00:00 +01:00
- this.waitUntilNextTick();
2019-04-25 07:33:13 +02:00
+ // CraftBukkit start
2023-12-05 17:40:00 +01:00
+ // this.nextTickTimeNanos = SystemUtils.getNanos() + MinecraftServer.PREPARE_LEVELS_DEFAULT_DELAY_NANOS;
2019-04-25 07:33:13 +02:00
+ this.executeModerately();
+ // CraftBukkit end
2021-11-21 23:00:00 +01:00
worldloadlistener.stop();
- this.updateMobSpawningFlags();
2019-04-25 07:33:13 +02:00
+ // CraftBukkit start
2021-11-21 23:00:00 +01:00
+ // this.updateMobSpawningFlags();
+ worldserver.setSpawnSettings(this.isSpawningMonsters(), this.isSpawningAnimals());
2020-11-06 08:46:21 +01:00
+
2019-04-25 07:33:13 +02:00
+ this.forceTicks = false;
+ // CraftBukkit end
2014-11-25 22:32:16 +01:00
}
2022-06-07 18:00:00 +02:00
public EnumGamemode getDefaultGameType() {
2024-04-23 17:15:00 +02:00
@@ -567,12 +826,16 @@
2021-06-11 07:00:00 +02:00
worldserver.save((IProgressUpdate) null, flag1, worldserver.noSave && !flag2);
2019-06-25 13:02:13 +02:00
}
2019-04-28 03:13:44 +02:00
2019-06-25 13:02:13 +02:00
+ // CraftBukkit start - moved to WorldServer.save
+ /*
2021-11-21 23:00:00 +01:00
WorldServer worldserver1 = this.overworld();
IWorldDataServer iworlddataserver = this.worldData.overworldData();
2019-04-28 03:13:44 +02:00
2021-11-21 23:00:00 +01:00
iworlddataserver.setWorldBorder(worldserver1.getWorldBorder().createSettings());
2024-04-23 17:15:00 +02:00
this.worldData.setCustomBossEvents(this.getCustomBossEvents().save(this.registryAccess()));
2022-02-28 16:00:00 +01:00
this.storageSource.saveDataTag(this.registryAccess(), this.worldData, this.getPlayerList().getSingleplayerData());
2019-06-25 13:02:13 +02:00
+ */
+ // CraftBukkit end
2021-07-06 16:00:00 +02:00
if (flag1) {
2021-11-21 23:00:00 +01:00
Iterator iterator1 = this.getAllLevels().iterator();
2019-04-28 03:13:44 +02:00
2024-04-23 17:15:00 +02:00
@@ -607,18 +870,40 @@
2021-11-21 23:00:00 +01:00
this.stopServer();
2014-11-25 22:32:16 +01:00
}
2015-02-07 11:39:00 +01:00
+ // CraftBukkit start
+ private boolean hasStopped = false;
+ private final Object stopLock = new Object();
2019-04-23 04:00:00 +02:00
+ public final boolean hasStopped() {
+ synchronized (stopLock) {
+ return hasStopped;
+ }
+ }
2015-02-07 11:39:00 +01:00
+ // CraftBukkit end
+
2021-11-21 23:00:00 +01:00
public void stopServer() {
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
2022-06-07 18:00:00 +02:00
if (this.metricsRecorder.isRecording()) {
this.cancelRecordingMetrics();
}
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
2023-09-21 18:40:00 +02:00
this.getConnection().stop();
this.isSaving = true;
if (this.playerList != null) {
2016-02-29 22:32:46 +01:00
MinecraftServer.LOGGER.info("Saving players");
2021-11-21 23:00:00 +01:00
this.playerList.saveAll();
this.playerList.removeAll();
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");
2024-04-23 17:15:00 +02:00
@@ -706,7 +991,7 @@
2023-03-14 17:30:00 +01:00
}
2023-12-05 17:40:00 +01:00
this.nextTickTimeNanos = SystemUtils.getNanos();
2023-03-14 17:30:00 +01:00
- this.statusIcon = (ServerPing.a) this.loadStatusIcon().orElse((Object) null);
+ this.statusIcon = (ServerPing.a) this.loadStatusIcon().orElse(null); // CraftBukkit - decompile error
this.status = this.buildServerStatus();
2022-06-07 18:00:00 +02:00
while (this.running) {
2024-04-23 17:15:00 +02:00
@@ -723,6 +1008,7 @@
2023-12-05 17:40:00 +01:00
if (j > MinecraftServer.OVERLOADED_THRESHOLD_NANOS + 20L * i && this.nextTickTimeNanos - this.lastOverloadWarningNanos >= MinecraftServer.OVERLOADED_WARNING_INTERVAL_NANOS + 100L * i) {
long k = j / i;
+ if (server.getWarnOnOverload()) // CraftBukkit
MinecraftServer.LOGGER.warn("Can't keep up! Is the server overloaded? Running {}ms or {} ticks behind", j / TimeRange.NANOSECONDS_PER_MILLISECOND, k);
this.nextTickTimeNanos += k * i;
this.lastOverloadWarningNanos = this.nextTickTimeNanos;
2024-04-23 17:15:00 +02:00
@@ -736,6 +1022,7 @@
2022-06-07 18:00:00 +02:00
this.debugCommandProfiler = new MinecraftServer.TimeProfiler(SystemUtils.getNanos(), this.tickCount);
}
+ MinecraftServer.currentTick = (int) (System.currentTimeMillis() / 50); // CraftBukkit
2023-12-05 17:40:00 +01:00
this.nextTickTimeNanos += i;
2022-06-07 18:00:00 +02:00
this.startMetricsRecordingTick();
this.profiler.push("tick");
2024-04-23 17:15:00 +02:00
@@ -783,6 +1070,12 @@
2022-06-07 18:00:00 +02:00
this.services.profileCache().clearExecutor();
2021-11-21 23:00:00 +01:00
}
2014-11-25 22:32:16 +01:00
+ // CraftBukkit start - Restore terminal to original settings
+ try {
+ reader.getTerminal().restore();
+ } catch (Exception ignored) {
+ }
+ // CraftBukkit end
2021-11-21 23:00:00 +01:00
this.onServerExit();
2014-11-25 22:32:16 +01:00
}
2024-04-23 17:15:00 +02:00
@@ -842,7 +1135,14 @@
2019-04-25 07:33:13 +02:00
}
2021-11-21 23:00:00 +01:00
private boolean haveTime() {
2023-12-05 17:40:00 +01:00
- return this.runningTask() || SystemUtils.getNanos() < (this.mayHaveDelayedTasks ? this.delayedTasksMaxNextTickTimeNanos : this.nextTickTimeNanos);
2019-04-25 07:33:13 +02:00
+ // CraftBukkit start
2023-12-05 17:40:00 +01:00
+ return this.forceTicks || this.runningTask() || SystemUtils.getNanos() < (this.mayHaveDelayedTasks ? this.delayedTasksMaxNextTickTimeNanos : this.nextTickTimeNanos);
2023-09-21 18:40:00 +02:00
+ }
+
2019-04-25 07:33:13 +02:00
+ private void executeModerately() {
2021-11-21 23:00:00 +01:00
+ this.runAllTasks();
2019-04-25 07:33:13 +02:00
+ java.util.concurrent.locks.LockSupport.parkNanos("executing tasks", 1000L);
2023-09-21 18:40:00 +02:00
+ // CraftBukkit end
}
2021-11-21 23:00:00 +01:00
protected void waitUntilNextTick() {
2024-04-23 17:15:00 +02:00
@@ -901,7 +1201,7 @@
2021-11-21 23:00:00 +01:00
}
}
- protected void doRunTask(TickTask ticktask) {
+ public void doRunTask(TickTask ticktask) { // CraftBukkit - decompile error
this.getProfiler().incrementCounter("runTask");
super.doRunTask(ticktask);
}
2024-04-23 17:15:00 +02:00
@@ -960,8 +1260,10 @@
2014-11-25 22:32:16 +01:00
}
2023-12-05 17:40:00 +01:00
--this.ticksUntilAutosave;
- if (this.ticksUntilAutosave <= 0) {
- this.ticksUntilAutosave = this.computeNextAutosaveInterval();
+ // CraftBukkit start
+ if (this.autosavePeriod > 0 && this.ticksUntilAutosave <= 0) {
+ this.ticksUntilAutosave = this.autosavePeriod;
+ // CraftBukkit end
2019-04-23 04:00:00 +02:00
MinecraftServer.LOGGER.debug("Autosave started");
2021-11-21 23:00:00 +01:00
this.profiler.push("save");
this.saveEverything(true, false, false);
2024-04-23 17:15:00 +02:00
@@ -1049,11 +1351,26 @@
2023-09-21 18:40:00 +02:00
this.getPlayerList().getPlayers().forEach((entityplayer) -> {
entityplayer.connection.suspendFlushing();
});
2021-06-11 07:00:00 +02:00
+ this.server.getScheduler().mainThreadHeartbeat(this.tickCount); // CraftBukkit
2021-11-21 23:00:00 +01:00
this.profiler.push("commandFunctions");
this.getFunctions().tick();
this.profiler.popPush("levels");
Iterator iterator = this.getAllLevels().iterator();
2014-11-25 22:32:16 +01:00
+ // CraftBukkit start
+ // Run tasks that are waiting on processing
+ while (!processQueue.isEmpty()) {
+ processQueue.remove().run();
+ }
+
+ // Send time updates to everyone, it will get the right time from the world the player is in.
2021-06-11 07:00:00 +02:00
+ if (this.tickCount % 20 == 0) {
2014-11-25 22:32:16 +01:00
+ for (int i = 0; i < this.getPlayerList().players.size(); ++i) {
+ EntityPlayer entityplayer = (EntityPlayer) this.getPlayerList().players.get(i);
2023-06-07 17:30:00 +02:00
+ entityplayer.connection.send(new PacketPlayOutUpdateTime(entityplayer.level().getGameTime(), entityplayer.getPlayerTime(), entityplayer.level().getGameRules().getBoolean(GameRules.RULE_DAYLIGHT))); // Add support for per player time
2014-11-25 22:32:16 +01:00
+ }
+ }
+
2019-06-21 12:00:00 +02:00
while (iterator.hasNext()) {
WorldServer worldserver = (WorldServer) iterator.next();
2024-04-23 17:15:00 +02:00
@@ -1062,11 +1379,13 @@
return s + " " + String.valueOf(worldserver.dimension().location());
2020-06-25 02:00:00 +02:00
});
+ /* Drop global time updates
2021-06-11 07:00:00 +02:00
if (this.tickCount % 20 == 0) {
2021-11-21 23:00:00 +01:00
this.profiler.push("timeSync");
2023-03-14 17:30:00 +01:00
this.synchronizeTime(worldserver);
2021-11-21 23:00:00 +01:00
this.profiler.pop();
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
2021-11-21 23:00:00 +01:00
this.profiler.push("tick");
2014-11-25 22:32:16 +01:00
2024-04-23 17:15:00 +02:00
@@ -1156,6 +1475,22 @@
2022-08-14 02:46:41 +02:00
return (WorldServer) this.levels.get(resourcekey);
}
+ // CraftBukkit start
+ public void addLevel(WorldServer level) {
+ Map<ResourceKey<World>, WorldServer> oldLevels = this.levels;
+ Map<ResourceKey<World>, WorldServer> newLevels = Maps.newLinkedHashMap(oldLevels);
+ newLevels.put(level.dimension(), level);
+ this.levels = Collections.unmodifiableMap(newLevels);
+ }
+
+ public void removeLevel(WorldServer level) {
+ Map<ResourceKey<World>, WorldServer> oldLevels = this.levels;
+ Map<ResourceKey<World>, WorldServer> newLevels = Maps.newLinkedHashMap(oldLevels);
+ newLevels.remove(level.dimension());
+ this.levels = Collections.unmodifiableMap(newLevels);
+ }
+ // CraftBukkit end
+
public Set<ResourceKey<World>> levelKeys() {
return this.levels.keySet();
}
2024-04-23 17:15:00 +02:00
@@ -1185,7 +1520,7 @@
2014-11-25 22:32:16 +01:00
2021-06-11 07:00:00 +02:00
@DontObfuscate
2014-11-25 22:32:16 +01:00
public String getServerModName() {
- return "vanilla";
+ return server.getName(); // CraftBukkit - cb > vanilla!
}
2021-11-21 23:00:00 +01:00
public SystemReport fillSystemReport(SystemReport systemreport) {
2024-04-23 17:15:00 +02:00
@@ -1527,11 +1862,11 @@
2021-11-21 23:00:00 +01:00
public CompletableFuture<Void> reloadResources(Collection<String> collection) {
2020-06-25 02:00:00 +02:00
CompletableFuture<Void> completablefuture = CompletableFuture.supplyAsync(() -> {
- Stream stream = collection.stream();
+ Stream<String> stream = collection.stream(); // CraftBukkit - decompile error
2021-06-11 07:00:00 +02:00
ResourcePackRepository resourcepackrepository = this.packRepository;
2020-06-25 02:00:00 +02:00
2021-06-11 07:00:00 +02:00
Objects.requireNonNull(this.packRepository);
2021-11-21 23:00:00 +01:00
- return (ImmutableList) stream.map(resourcepackrepository::getPack).filter(Objects::nonNull).map(ResourcePackLoader::open).collect(ImmutableList.toImmutableList());
+ return stream.map(resourcepackrepository::getPack).filter(Objects::nonNull).map(ResourcePackLoader::open).collect(ImmutableList.toImmutableList()); // CraftBukkit - decompile error
2020-06-25 02:00:00 +02:00
}, this).thenCompose((immutablelist) -> {
2022-02-28 16:00:00 +01:00
ResourceManager resourcemanager = new ResourceManager(EnumResourcePackType.SERVER_DATA, immutablelist);
2024-04-23 17:15:00 +02:00
@@ -1546,6 +1881,7 @@
2022-06-07 18:00:00 +02:00
}).thenAcceptAsync((minecraftserver_reloadableresources) -> {
2021-06-11 07:00:00 +02:00
this.resources.close();
2022-06-07 18:00:00 +02:00
this.resources = minecraftserver_reloadableresources;
2020-06-30 02:51:26 +02:00
+ this.server.syncCommands(); // SPIGOT-5884: Lost on reload
2021-11-21 23:00:00 +01:00
this.packRepository.setSelected(collection);
2024-04-23 17:15:00 +02:00
WorldDataConfiguration worlddataconfiguration = new WorldDataConfiguration(getSelectedPacks(this.packRepository, true), this.worldData.enabledFeatures());
@@ -1846,7 +2182,7 @@
final List<String> list = Lists.newArrayList();
final GameRules gamerules = this.getGameRules();
- GameRules.visitGameRuleTypes(new GameRules.GameRuleVisitor(this) {
+ GameRules.visitGameRuleTypes(new GameRules.GameRuleVisitor() { // CraftBukkit - decompile error
@Override
public <T extends GameRules.GameRuleValue<T>> void visit(GameRules.GameRuleKey<T> gamerules_gamerulekey, GameRules.GameRuleDefinition<T> gamerules_gameruledefinition) {
list.add(String.format(Locale.ROOT, "%s=%s\n", gamerules_gamerulekey.getId(), gamerules.getRule(gamerules_gamerulekey)));
@@ -1952,7 +2288,7 @@
2021-11-21 23:00:00 +01:00
try {
label51:
{
- ArrayList arraylist;
+ ArrayList<NativeModuleLister.a> arraylist; // CraftBukkit - decompile error
try {
arraylist = Lists.newArrayList(NativeModuleLister.listModules());
2024-04-23 17:15:00 +02:00
@@ -2002,6 +2338,22 @@
2014-11-25 22:32:16 +01:00
2014-11-29 01:53:49 +01:00
}
2016-02-29 22:32:46 +01:00
+ // CraftBukkit start
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() {
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
+ }
2024-04-23 17:15:00 +02:00
+
+ @Deprecated
+ public static IRegistryCustom getDefaultRegistryAccess() {
+ return CraftRegistry.getMinecraftRegistry();
+ }
2016-02-29 22:32:46 +01:00
+ // CraftBukkit end
2020-06-25 02:00:00 +02:00
+
2021-11-21 23:00:00 +01:00
private void startMetricsRecordingTick() {
2021-06-11 07:00:00 +02:00
if (this.willStartRecordingMetrics) {
2021-11-21 23:00:00 +01:00
this.metricsRecorder = ActiveMetricsRecorder.createStarted(new ServerMetricsSamplersProvider(SystemUtils.timeSource, this.isDedicatedServer()), SystemUtils.timeSource, SystemUtils.ioPool(), new MetricsPersister("server"), this.onMetricsRecordingStopped, (path) -> {
2024-04-23 17:15:00 +02:00
@@ -2132,6 +2484,11 @@
2022-07-27 20:00:00 +02:00
}
+ // CraftBukkit start
+ public final java.util.concurrent.ExecutorService chatExecutor = java.util.concurrent.Executors.newCachedThreadPool(
+ new com.google.common.util.concurrent.ThreadFactoryBuilder().setDaemon(true).setNameFormat("Async Chat Thread - #%d").build());
2023-09-21 18:40:00 +02:00
+ // CraftBukkit end
2022-07-27 20:00:00 +02:00
+
public ChatDecorator getChatDecorator() {
2023-09-21 18:40:00 +02:00
return ChatDecorator.PLAIN;
2022-07-27 20:00:00 +02:00
}