2015-05-25 12:37:24 +02:00
--- a/net/minecraft/server/MinecraftServer.java
+++ b/net/minecraft/server/MinecraftServer.java
2024-12-11 22:26:55 +01:00
@@ -84,17 +84,6 @@
import net.minecraft.obfuscate.DontObfuscate;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
-import net.minecraft.server.bossevents.CustomBossEvents;
-import net.minecraft.server.level.DemoMode;
-import net.minecraft.server.level.PlayerRespawnLogic;
-import net.minecraft.server.level.ServerChunkCache;
-import net.minecraft.server.level.ServerLevel;
-import net.minecraft.server.level.ServerPlayer;
-import net.minecraft.server.level.ServerPlayerGameMode;
-import net.minecraft.server.level.progress.ChunkProgressListener;
-import net.minecraft.server.level.progress.ChunkProgressListenerFactory;
-import net.minecraft.server.network.ServerConnectionListener;
-import net.minecraft.server.network.TextFilter;
import net.minecraft.server.packs.PackType;
import net.minecraft.server.packs.repository.Pack;
import net.minecraft.server.packs.repository.PackRepository;
@@ -116,6 +105,7 @@
import net.minecraft.util.RandomSource;
import net.minecraft.util.SignatureValidator;
import net.minecraft.util.TimeUtil;
+import net.minecraft.util.datafix.DataFixers;
import net.minecraft.util.debugchart.RemoteDebugSampleType;
import net.minecraft.util.debugchart.SampleLogger;
import net.minecraft.util.debugchart.TpsDebugDimensions;
2021-01-29 17:54:03 +01:00
@@ -156,37 +146,73 @@
2024-12-11 22:26:55 +01:00
import net.minecraft.world.level.biome.BiomeManager;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.FuelValues;
-import net.minecraft.world.level.border.BorderChangeListener;
import net.minecraft.world.level.border.WorldBorder;
import net.minecraft.world.level.chunk.storage.ChunkIOErrorReporter;
import net.minecraft.world.level.chunk.storage.RegionStorageInfo;
import net.minecraft.world.level.dimension.LevelStem;
-import net.minecraft.world.level.levelgen.Heightmap;
-import net.minecraft.world.level.levelgen.PatrolSpawner;
-import net.minecraft.world.level.levelgen.PhantomSpawner;
import net.minecraft.world.level.levelgen.WorldOptions;
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplateManager;
+import net.minecraft.world.level.storage.WorldData;
+import org.slf4j.Logger;
+
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;
2024-06-13 17:05:00 +02:00
+import java.io.File;
2022-06-07 18:00:00 +02:00
+import java.util.Random;
2017-06-09 19:03:43 +02:00
+// import jline.console.ConsoleReader; // Paper
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;
2024-12-11 22:26:55 +01:00
+import net.minecraft.server.bossevents.CustomBossEvents;
2021-03-15 23:00:00 +01:00
+import net.minecraft.server.dedicated.DedicatedServer;
+import net.minecraft.server.dedicated.DedicatedServerProperties;
2024-12-11 22:26:55 +01:00
+import net.minecraft.server.level.DemoMode;
+import net.minecraft.server.level.PlayerRespawnLogic;
+import net.minecraft.server.level.ServerChunkCache;
+import net.minecraft.server.level.ServerLevel;
+import net.minecraft.server.level.ServerPlayer;
+import net.minecraft.server.level.ServerPlayerGameMode;
+import net.minecraft.server.level.progress.ChunkProgressListener;
+import net.minecraft.server.level.progress.ChunkProgressListenerFactory;
+import net.minecraft.server.network.ServerConnectionListener;
+import net.minecraft.server.network.TextFilter;
+import net.minecraft.world.level.levelgen.Heightmap;
+import net.minecraft.world.level.levelgen.PatrolSpawner;
+import net.minecraft.world.level.levelgen.PhantomSpawner;
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;
2024-12-11 22:26:55 +01:00
import net.minecraft.world.level.storage.CommandStorage;
-import net.minecraft.world.level.storage.DerivedLevelData;
import net.minecraft.world.level.storage.DimensionDataStorage;
import net.minecraft.world.level.storage.LevelData;
2023-12-05 17:40:00 +01:00
+import net.minecraft.world.level.storage.LevelDataAndDimensions;
2024-12-11 22:26:55 +01:00
import net.minecraft.world.level.storage.LevelResource;
import net.minecraft.world.level.storage.LevelStorageSource;
+import net.minecraft.world.level.storage.LevelSummary;
import net.minecraft.world.level.storage.PlayerDataStorage;
+import net.minecraft.world.level.storage.PrimaryLevelData;
import net.minecraft.world.level.storage.ServerLevelData;
-import net.minecraft.world.level.storage.WorldData;
2023-06-07 17:30:00 +02:00
+import net.minecraft.world.level.validation.ContentValidationException;
2024-12-11 22:26:55 +01:00
import net.minecraft.world.phys.Vec2;
import net.minecraft.world.phys.Vec3;
-import org.slf4j.Logger;
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
2015-02-26 23:41:06 +01:00
2013-01-10 06:18:11 +01:00
+import org.bukkit.craftbukkit.SpigotTimings; // Spigot
+
2024-12-11 22:26:55 +01:00
public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTask> implements ServerInfo, ChunkIOErrorReporter, CommandSource {
2013-01-10 06:18:11 +01:00
public static final Logger LOGGER = LogUtils.getLogger();
2021-01-29 17:54:03 +01:00
+ public static final net.kyori.adventure.text.logger.slf4j.ComponentLogger COMPONENT_LOGGER = net.kyori.adventure.text.logger.slf4j.ComponentLogger.logger(LOGGER.getName()); // Paper
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;
2024-12-11 22:26:55 +01:00
- private static final long OVERLOADED_THRESHOLD_NANOS = 20L * TimeUtil.NANOSECONDS_PER_SECOND / 20L;
+ private static final long OVERLOADED_THRESHOLD_NANOS = 30L * TimeUtil.NANOSECONDS_PER_SECOND / 20L; // CraftBukkit
2023-12-05 17:40:00 +01:00
private static final int OVERLOADED_TICKS_THRESHOLD = 20;
2024-12-11 22:26:55 +01:00
private static final long OVERLOADED_WARNING_INTERVAL_NANOS = 10L * TimeUtil.NANOSECONDS_PER_SECOND;
2023-12-05 17:40:00 +01:00
private static final int OVERLOADED_TICKS_WARNING_INTERVAL = 100;
2021-01-29 17:54:03 +01:00
@@ -232,8 +258,7 @@
private boolean preventProxyConnections;
private boolean pvp;
private boolean allowFlight;
- @Nullable
- private String motd;
+ private net.kyori.adventure.text.Component motd; // Paper - Adventure
private int playerIdleTimeout;
private final long[] tickTimesNanos;
private long aggregatedTickTimesNanos;
2016-03-02 06:09:29 +01:00
@@ -277,6 +302,26 @@
2024-10-22 17:15:00 +02:00
private final SuppressedExceptionCollector suppressedExceptions;
private final DiscontinuousFrame tickFrame;
2017-06-09 19:03:43 +02:00
2014-11-25 22:32:16 +01:00
+ // CraftBukkit start
2024-12-11 22:26:55 +01:00
+ public final WorldLoader.DataLoadContext worldLoader;
2014-11-25 22:32:16 +01:00
+ public org.bukkit.craftbukkit.CraftServer server;
+ public OptionSet options;
+ public org.bukkit.command.ConsoleCommandSender console;
2016-03-02 06:09:29 +01:00
+ public static int currentTick; // Paper - improve tick loop
2014-11-25 22:32:16 +01:00
+ public java.util.Queue<Runnable> processQueue = new java.util.concurrent.ConcurrentLinkedQueue<Runnable>();
+ public int autosavePeriod;
2024-12-11 22:26:55 +01:00
+ public Commands vanillaCommandDispatcher;
2019-04-25 07:33:13 +02:00
+ private boolean forceTicks;
2014-11-25 22:32:16 +01:00
+ // CraftBukkit end
2017-01-26 22:50:51 +01:00
+ // Spigot start
+ public static final int TPS = 20;
+ public static final int TICK_TIME = 1000000000 / MinecraftServer.TPS;
2016-03-02 06:09:29 +01:00
+ private static final int SAMPLE_INTERVAL = 20; // Paper - improve server tick loop
+ @Deprecated(forRemoval = true) // Paper
2017-01-26 22:50:51 +01:00
+ public final double[] recentTps = new double[ 3 ];
+ // Spigot end
2022-06-09 07:20:16 +02:00
+ public final io.papermc.paper.configuration.PaperConfigurations paperConfigurations; // Paper - add paper configuration files
2017-06-09 19:03:43 +02:00
+
2024-12-11 22:26:55 +01:00
public static <S extends MinecraftServer> S spin(Function<Thread, S> serverFactory) {
2020-06-25 02:00:00 +02:00
AtomicReference<S> atomicreference = new AtomicReference();
2017-06-09 19:03:43 +02:00
Thread thread = new Thread(() -> {
2016-03-02 06:09:29 +01:00
@@ -290,14 +335,14 @@
2021-11-21 23:00:00 +01:00
thread.setPriority(8);
}
2024-12-11 22:26:55 +01:00
- S s0 = (MinecraftServer) serverFactory.apply(thread);
+ S s0 = serverFactory.apply(thread); // CraftBukkit - decompile error
2020-06-25 02:00:00 +02:00
atomicreference.set(s0);
thread.start();
return s0;
}
2024-12-11 22:26:55 +01:00
- public MinecraftServer(Thread serverThread, LevelStorageSource.LevelStorageAccess session, PackRepository dataPackManager, WorldStem saveLoader, Proxy proxy, DataFixer dataFixer, Services apiServices, ChunkProgressListenerFactory worldGenerationProgressListenerFactory) {
+ public MinecraftServer(OptionSet options, WorldLoader.DataLoadContext worldLoader, Thread thread, LevelStorageSource.LevelStorageAccess convertable_conversionsession, PackRepository resourcepackrepository, WorldStem worldstem, Proxy proxy, DataFixer datafixer, Services services, ChunkProgressListenerFactory worldloadlistenerfactory) {
2019-04-23 04:00:00 +02:00
super("Server");
2021-06-11 07:00:00 +02:00
this.metricsRecorder = InactiveMetricsRecorder.INSTANCE;
2024-10-22 17:15:00 +02:00
this.onMetricsRecordingStopped = (methodprofilerresults) -> {
2016-03-02 06:09:29 +01:00
@@ -319,36 +364,68 @@
2024-12-11 22:26:55 +01:00
this.scoreboard = new ServerScoreboard(this);
this.customBossEvents = new CustomBossEvents();
2024-10-22 17:15:00 +02:00
this.suppressedExceptions = new SuppressedExceptionCollector();
2024-12-11 22:26:55 +01:00
- this.registries = saveLoader.registries();
- this.worldData = saveLoader.worldData();
- if (!this.registries.compositeAccess().lookupOrThrow(Registries.LEVEL_STEM).containsKey(LevelStem.OVERWORLD)) {
+ this.registries = worldstem.registries();
+ this.worldData = worldstem.worldData();
+ if (false && !this.registries.compositeAccess().lookupOrThrow(Registries.LEVEL_STEM).containsKey(LevelStem.OVERWORLD)) { // CraftBukkit - initialised later
2022-06-07 18:00:00 +02:00
throw new IllegalStateException("Missing Overworld dimension data");
} else {
this.proxy = proxy;
2024-12-11 22:26:55 +01:00
- this.packRepository = dataPackManager;
- this.resources = new MinecraftServer.ReloadableResources(saveLoader.resourceManager(), saveLoader.dataPackResources());
- this.services = apiServices;
- if (apiServices.profileCache() != null) {
- apiServices.profileCache().setExecutor(this);
+ this.packRepository = resourcepackrepository;
+ this.resources = new MinecraftServer.ReloadableResources(worldstem.resourceManager(), worldstem.dataPackResources());
+ this.services = services;
+ if (services.profileCache() != null) {
+ services.profileCache().setExecutor(this);
}
2013-12-13 01:58:58 +01:00
- this.connection = new ServerConnectionListener(this);
+ // this.connection = new ServerConnection(this); // Spigot
2024-12-11 22:26:55 +01:00
this.tickRateManager = new ServerTickRateManager(this);
- this.progressListenerFactory = worldGenerationProgressListenerFactory;
- this.storageSource = session;
- this.playerDataStorage = session.createPlayerStorage();
- this.fixerUpper = dataFixer;
+ this.progressListenerFactory = worldloadlistenerfactory;
+ this.storageSource = convertable_conversionsession;
+ this.playerDataStorage = convertable_conversionsession.createPlayerStorage();
+ this.fixerUpper = datafixer;
this.functionManager = new ServerFunctionManager(this, this.resources.managers.getFunctionLibrary());
HolderGetter<Block> holdergetter = this.registries.compositeAccess().lookupOrThrow(Registries.BLOCK).filterFeatures(this.worldData.enabledFeatures());
- this.structureTemplateManager = new StructureTemplateManager(saveLoader.resourceManager(), session, dataFixer, holdergetter);
- this.serverThread = serverThread;
+ this.structureTemplateManager = new StructureTemplateManager(worldstem.resourceManager(), convertable_conversionsession, datafixer, holdergetter);
+ this.serverThread = thread;
this.executor = Util.backgroundExecutor();
this.potionBrewing = PotionBrewing.bootstrap(this.worldData.enabledFeatures());
this.resources.managers.getRecipeManager().finalizeRecipeLoading(this.worldData.enabledFeatures());
2024-10-22 17:15:00 +02:00
this.fuelValues = FuelValues.vanillaBurnTimes(this.registries.compositeAccess(), this.worldData.enabledFeatures());
this.tickFrame = TracyClient.createDiscontinuousFrame("Server Tick");
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
2017-06-09 19:03:43 +02:00
+ // Paper start - Handled by TerminalConsoleAppender
2014-11-25 22:32:16 +01:00
+ // Try to see if we're actually running in a terminal, disable jline if not
2017-06-09 19:03:43 +02:00
+ /*
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 {
2024-12-11 22:26:55 +01:00
+ this.reader = new ConsoleReader(System.in, System.out);
+ this.reader.setExpandEvents(false); // Avoid parsing exceptions for uncommonly used event designators
2014-11-25 22:32:16 +01:00
+ } 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;
2024-12-11 22:26:55 +01:00
+ this.reader = new ConsoleReader(System.in, System.out);
+ this.reader.setExpandEvents(false);
2014-11-25 22:32:16 +01:00
+ } catch (IOException ex) {
2024-12-11 22:26:55 +01:00
+ MinecraftServer.LOGGER.warn((String) null, ex);
2014-11-25 22:32:16 +01:00
+ }
+ }
2017-06-09 19:03:43 +02:00
+ */
+ // Paper end
2014-11-25 22:32:16 +01:00
+ Runtime.getRuntime().addShutdownHook(new org.bukkit.craftbukkit.util.ServerShutdownThread(this));
2023-09-21 18:40:00 +02:00
+ // CraftBukkit end
2022-06-09 07:20:16 +02:00
+ this.paperConfigurations = services.paperConfigurations(); // Paper - add paper configuration files
2014-11-25 22:32:16 +01:00
}
2018-07-15 02:00:00 +02:00
2024-12-11 22:26:55 +01:00
private void readScoreboard(DimensionDataStorage persistentStateManager) {
2016-03-02 06:09:29 +01:00
@@ -357,7 +434,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()) {
;
}
2016-03-02 06:09:29 +01:00
@@ -365,12 +442,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-12-11 22:26:55 +01:00
- ChunkProgressListener worldloadlistener = this.progressListenerFactory.create(this.worldData.getGameRules().getInt(GameRules.RULE_SPAWN_CHUNK_RADIUS));
+ this.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) {
2024-12-03 17:20:00 +01:00
profiledduration.finish(true);
2021-11-21 23:00:00 +01:00
}
2016-03-02 06:09:29 +01:00
@@ -387,23 +460,218 @@
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
2024-12-11 22:26:55 +01:00
- protected void createLevels(ChunkProgressListener worldGenerationProgressListener) {
- ServerLevelData iworlddataserver = this.worldData.overworldData();
2023-09-21 18:40:00 +02:00
- boolean flag = this.worldData.isDebugWorld();
2024-12-11 22:26:55 +01:00
- Registry<LevelStem> iregistry = this.registries.compositeAccess().lookupOrThrow(Registries.LEVEL_STEM);
2023-09-21 18:40:00 +02:00
- WorldOptions worldoptions = this.worldData.worldGenOptions();
- long i = worldoptions.seed();
- long j = BiomeManager.obfuscateSeed(i);
2024-12-11 22:26:55 +01:00
- List<CustomSpawner> list = ImmutableList.of(new PhantomSpawner(), new PatrolSpawner(), new CatSpawner(), new VillageSiege(), new WanderingTraderSpawner(iworlddataserver));
- LevelStem worlddimension = (LevelStem) iregistry.getValue(LevelStem.OVERWORLD);
- ServerLevel worldserver = new ServerLevel(this, this.executor, this.storageSource, iworlddataserver, Level.OVERWORLD, worlddimension, worldGenerationProgressListener, flag, j, list, true, (RandomSequences) null);
2021-11-21 23:00:00 +01:00
+ // CraftBukkit start
+ private void loadWorld0(String s) {
2024-12-11 22:26:55 +01:00
+ LevelStorageSource.LevelStorageAccess worldSession = this.storageSource;
2023-09-21 18:57:13 +02:00
2024-12-11 22:26:55 +01:00
- this.levels.put(Level.OVERWORLD, worldserver);
- DimensionDataStorage worldpersistentdata = worldserver.getDataStorage();
+ RegistryAccess.Frozen iregistrycustom_dimension = this.registries.compositeAccess();
+ Registry<LevelStem> dimensions = iregistrycustom_dimension.lookupOrThrow(Registries.LEVEL_STEM);
+ for (LevelStem worldDimension : dimensions) {
+ ResourceKey<LevelStem> dimensionKey = dimensions.getResourceKey(worldDimension).get();
2023-09-21 18:57:13 +02:00
- this.readScoreboard(worldpersistentdata);
2024-12-11 22:26:55 +01:00
- this.commandStorage = new CommandStorage(worldpersistentdata);
+ ServerLevel world;
2021-04-16 02:36:05 +02:00
+ int dimension = 0;
2021-11-21 23:00:00 +01:00
+
2024-12-11 22:26:55 +01:00
+ if (dimensionKey == LevelStem.NETHER) {
+ if (this.server.getAllowNether()) {
2014-11-25 22:32:16 +01:00
+ dimension = -1;
+ } else {
+ continue;
+ }
2024-12-11 22:26:55 +01:00
+ } else if (dimensionKey == LevelStem.END) {
+ if (this.server.getAllowEnd()) {
2014-11-25 22:32:16 +01:00
+ dimension = 1;
+ } else {
+ continue;
+ }
2024-12-11 22:26:55 +01:00
+ } else if (dimensionKey != LevelStem.OVERWORLD) {
2021-04-16 02:36:05 +02:00
+ dimension = -999;
2018-08-26 04:00:00 +02:00
+ }
2023-09-21 18:40:00 +02:00
+
2024-06-02 23:18:17 +02:00
+ String worldType = (dimension == -999) ? dimensionKey.location().getNamespace() + "_" + dimensionKey.location().getPath() : org.bukkit.World.Environment.getEnvironment(dimension).toString().toLowerCase(Locale.ROOT);
2024-12-11 22:26:55 +01:00
+ String name = (dimensionKey == LevelStem.OVERWORLD) ? s : s + "_" + worldType;
2021-04-16 02:36:05 +02:00
+ if (dimension != 0) {
2024-12-11 22:26:55 +01:00
+ File newWorld = LevelStorageSource.getStorageFolder(new File(name).toPath(), dimensionKey).toFile();
+ File oldWorld = LevelStorageSource.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 {
2024-12-11 22:26:55 +01:00
+ worldSession = LevelStorageSource.createDefault(this.server.getWorldContainer().toPath()).validateAndCreateAccess(name, dimensionKey);
2023-06-07 17:30:00 +02:00
+ } 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()) {
2024-12-11 22:26:55 +01:00
+ LevelSummary worldinfo;
2023-12-05 17:40:00 +01:00
+
+ try {
+ dynamic = worldSession.getDataTag();
+ worldinfo = worldSession.getSummary(dynamic);
+ } catch (NbtException | ReportedNbtException | IOException ioexception) {
2024-12-11 22:26:55 +01:00
+ LevelStorageSource.LevelDirectory convertable_b = worldSession.getLevelDirectory();
2023-12-05 17:40:00 +01:00
+
+ 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
+
2024-12-11 22:26:55 +01:00
+ PrimaryLevelData worlddata;
+ WorldLoader.DataLoadContext worldloader_a = this.worldLoader;
+ Registry<LevelStem> iregistry = worldloader_a.datapackDimensions().lookupOrThrow(Registries.LEVEL_STEM);
2023-12-05 17:40:00 +01:00
+ if (dynamic != null) {
2024-12-11 22:26:55 +01:00
+ LevelDataAndDimensions leveldataanddimensions = LevelStorageSource.getLevelDataAndDimensions(dynamic, worldloader_a.dataConfiguration(), iregistry, worldloader_a.datapackWorldgen());
2022-12-07 17:00:00 +01:00
+
2024-12-11 22:26:55 +01:00
+ worlddata = (PrimaryLevelData) leveldataanddimensions.worldData();
2022-12-07 17:00:00 +01:00
+ } else {
2024-12-11 22:26:55 +01:00
+ LevelSettings 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
+
2024-12-11 22:26:55 +01:00
+ worldsettings = new LevelSettings(dedicatedserverproperties.levelName, dedicatedserverproperties.gamemode, dedicatedserverproperties.hardcore, dedicatedserverproperties.difficulty, false, new GameRules(worldloader_a.dataConfiguration().enabledFeatures()), worldloader_a.dataConfiguration());
+ worldoptions = this.options.has("bonusChest") ? dedicatedserverproperties.worldOptions.withBonusChest(true) : dedicatedserverproperties.worldOptions;
2022-12-07 17:00:00 +01:00
+ worlddimensions = dedicatedserverproperties.createDimensions(worldloader_a.datapackWorldgen());
2018-08-26 04:00:00 +02:00
+ }
2019-04-23 04:00:00 +02:00
+
2024-12-11 22:26:55 +01:00
+ WorldDimensions.Complete worlddimensions_b = worlddimensions.bake(iregistry);
2022-12-07 17:00:00 +01:00
+ Lifecycle lifecycle = worlddimensions_b.lifecycle().add(worldloader_a.datapackWorldgen().allRegistriesLifecycle());
+
2024-12-11 22:26:55 +01:00
+ worlddata = new PrimaryLevelData(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)
2024-12-11 22:26:55 +01:00
+ if (this.options.has("forceUpgrade")) {
+ net.minecraft.server.Main.forceUpgrade(worldSession, DataFixers.getDataFixer(), this.options.has("eraseCache"), () -> {
2020-06-25 02:00:00 +02:00
+ return true;
2024-12-11 22:26:55 +01:00
+ }, iregistrycustom_dimension, this.options.has("recreateRegionFiles"));
2020-06-25 02:00:00 +02:00
+ }
+
2024-12-11 22:26:55 +01:00
+ PrimaryLevelData 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);
2024-12-11 22:26:55 +01:00
+ List<CustomSpawner> list = ImmutableList.of(new PhantomSpawner(), new PatrolSpawner(), new CatSpawner(), new VillageSiege(), new WanderingTraderSpawner(iworlddataserver));
+ LevelStem worlddimension = (LevelStem) dimensions.getValue(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);
+ }
+
2024-12-11 22:26:55 +01:00
+ ResourceKey<Level> worldKey = ResourceKey.create(Registries.DIMENSION, dimensionKey.location());
2021-03-08 22:47:33 +01:00
+
2024-12-11 22:26:55 +01:00
+ if (dimensionKey == LevelStem.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-12-11 22:26:55 +01:00
+ ChunkProgressListener worldloadlistener = this.progressListenerFactory.create(this.worldData.getGameRules().getInt(GameRules.RULE_SPAWN_CHUNK_RADIUS));
2023-09-21 18:40:00 +02:00
+
2024-12-11 22:26:55 +01:00
+ world = new ServerLevel(this, this.executor, worldSession, iworlddataserver, worldKey, worlddimension, worldloadlistener, flag, j, list, true, (RandomSequences) null, org.bukkit.World.Environment.getEnvironment(dimension), gen, biomeProvider);
+ DimensionDataStorage worldpersistentdata = world.getDataStorage();
2021-11-21 23:00:00 +01:00
+ this.readScoreboard(worldpersistentdata);
2014-11-25 22:32:16 +01:00
+ this.server.scoreboardManager = new org.bukkit.craftbukkit.scoreboard.CraftScoreboardManager(this, world.getScoreboard());
2024-12-11 22:26:55 +01:00
+ this.commandStorage = new CommandStorage(worldpersistentdata);
2018-08-26 04:00:00 +02:00
+ } else {
2024-12-11 22:26:55 +01:00
+ ChunkProgressListener worldloadlistener = this.progressListenerFactory.create(this.worldData.getGameRules().getInt(GameRules.RULE_SPAWN_CHUNK_RADIUS));
+ world = new ServerLevel(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());
2024-12-11 22:26:55 +01:00
+ this.initWorld(world, worlddata, this.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();
2024-12-11 22:26:55 +01:00
+ for (ServerLevel worldserver : this.getAllLevels()) {
2021-11-21 23:00:00 +01:00
+ 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);
2022-10-30 00:22:32 +02:00
+ if (io.papermc.paper.plugin.PluginInitializerManager.instance().pluginRemapper != null) io.papermc.paper.plugin.PluginInitializerManager.instance().pluginRemapper.pluginsEnabled(); // Paper - Remap plugins
2019-04-23 04:00:00 +02:00
+ 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
+
2024-12-11 22:26:55 +01:00
+ public void initWorld(ServerLevel worldserver, ServerLevelData iworlddataserver, WorldData saveData, WorldOptions worldoptions) {
2022-12-07 17:00:00 +01:00
+ 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 {
2016-03-02 06:09:29 +01:00
@@ -427,30 +695,8 @@
2017-01-26 22:50:51 +01:00
iworlddataserver.setInitialized(true);
2014-05-24 00:05:10 +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()) {
2024-12-11 22:26:55 +01:00
- Entry<ResourceKey<LevelStem>, LevelStem> entry = (Entry) iterator.next();
- ResourceKey<LevelStem> resourcekey = (ResourceKey) entry.getKey();
2019-04-23 04:00:00 +02:00
-
2024-12-11 22:26:55 +01:00
- if (resourcekey != LevelStem.OVERWORLD) {
- ResourceKey<Level> resourcekey1 = ResourceKey.create(Registries.DIMENSION, resourcekey.location());
- DerivedLevelData secondaryworlddata = new DerivedLevelData(this.worldData, iworlddataserver);
- ServerLevel worldserver1 = new ServerLevel(this, this.executor, this.storageSource, secondaryworlddata, resourcekey1, (LevelStem) entry.getValue(), worldGenerationProgressListener, flag, j, ImmutableList.of(), false, randomsequences);
2020-06-25 02:00:00 +02:00
-
2024-12-11 22:26:55 +01:00
- worldborder.addListener(new BorderChangeListener.DelegateBorderChangeListener(worldserver1.getWorldBorder()));
2021-06-11 07:00:00 +02:00
- this.levels.put(resourcekey1, worldserver1);
2019-04-23 04:00:00 +02:00
- }
2014-05-24 00:05:10 +02:00
- }
-
2022-01-31 22:13:13 +01:00
- worldborder.applySettings(iworlddataserver.getWorldBorder());
2016-03-29 02:55:47 +02:00
}
2019-04-23 04:00:00 +02:00
+ // CraftBukkit end
2018-08-26 04:00:00 +02:00
2024-12-11 22:26:55 +01:00
private static void setInitialSpawn(ServerLevel world, ServerLevelData worldProperties, boolean bonusChest, boolean debugWorld) {
if (debugWorld) {
2016-03-02 06:09:29 +01:00
@@ -458,6 +704,21 @@
2021-11-21 23:00:00 +01:00
} else {
2024-12-11 22:26:55 +01:00
ServerChunkCache chunkproviderserver = world.getChunkSource();
ChunkPos chunkcoordintpair = new ChunkPos(chunkproviderserver.randomState().sampler().findSpawnPosition());
2020-06-25 02:00:00 +02:00
+ // CraftBukkit start
2024-12-11 22:26:55 +01:00
+ if (world.generator != null) {
+ Random rand = new Random(world.getSeed());
+ org.bukkit.Location spawn = world.generator.getFixedSpawnLocation(world.getWorld(), rand);
2020-06-25 02:00:00 +02:00
+
+ if (spawn != null) {
2024-12-11 22:26:55 +01:00
+ if (spawn.getWorld() != world.getWorld()) {
+ throw new IllegalStateException("Cannot set spawn point for " + worldProperties.getLevelName() + " to be in another world (" + spawn.getWorld().getName() + ")");
2020-06-25 02:00:00 +02:00
+ } else {
2024-12-11 22:26:55 +01:00
+ worldProperties.setSpawn(new BlockPos(spawn.getBlockX(), spawn.getBlockY(), spawn.getBlockZ()), spawn.getYaw());
2020-06-25 02:00:00 +02:00
+ return;
+ }
+ }
+ }
+ // CraftBukkit end
2024-12-11 22:26:55 +01:00
int i = chunkproviderserver.getGenerator().getSpawnHeight(world);
2020-06-25 02:00:00 +02:00
2024-12-11 22:26:55 +01:00
if (i < world.getMinY()) {
2016-03-02 06:09:29 +01:00
@@ -516,31 +777,36 @@
2024-12-11 22:26:55 +01:00
iworlddataserver.setGameType(GameType.SPECTATOR);
2019-04-23 04:00:00 +02:00
}
2018-08-26 04:00:00 +02:00
2024-12-11 22:26:55 +01:00
- public void prepareLevels(ChunkProgressListener worldGenerationProgressListener) {
- ServerLevel worldserver = this.overworld();
2019-04-23 04:00:00 +02:00
+ // CraftBukkit start
2024-12-11 22:26:55 +01:00
+ public void prepareLevels(ChunkProgressListener worldloadlistener, ServerLevel worldserver) {
2021-11-21 23:00:00 +01:00
+ // 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());
2024-12-11 22:26:55 +01:00
BlockPos blockposition = worldserver.getSharedSpawnPos();
2019-04-25 07:33:13 +02:00
2024-12-11 22:26:55 +01:00
- worldGenerationProgressListener.updateSpawnPos(new ChunkPos(blockposition));
+ worldloadlistener.updateSpawnPos(new ChunkPos(blockposition));
ServerChunkCache chunkproviderserver = worldserver.getChunkSource();
this.nextTickTimeNanos = Util.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
2024-12-11 22:26:55 +01:00
int j = i > 0 ? Mth.square(ChunkProgressListener.calculateDiameter(i)) : 0;
2022-03-04 08:53:19 +01:00
2024-04-23 17:15:00 +02:00
while (chunkproviderserver.getTickingGenerated() < j) {
2024-12-11 22:26:55 +01:00
- this.nextTickTimeNanos = Util.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
2024-12-11 22:26:55 +01:00
- this.nextTickTimeNanos = Util.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()) {
2024-12-11 22:26:55 +01:00
- ServerLevel worldserver1 = (ServerLevel) iterator.next();
2019-04-23 04:00:00 +02:00
+ if (true) {
2024-12-11 22:26:55 +01:00
+ ServerLevel worldserver1 = worldserver;
2019-04-23 04:00:00 +02:00
+ // CraftBukkit end
2024-12-11 22:26:55 +01:00
ForcedChunksSavedData forcedchunk = (ForcedChunksSavedData) worldserver1.getDataStorage().get(ForcedChunksSavedData.factory(), "chunks");
2019-04-23 04:00:00 +02:00
if (forcedchunk != null) {
2016-03-02 06:09:29 +01:00
@@ -555,10 +821,17 @@
2019-04-25 07:33:13 +02:00
}
}
2024-12-11 22:26:55 +01:00
- this.nextTickTimeNanos = Util.getNanos() + MinecraftServer.PREPARE_LEVELS_DEFAULT_DELAY_NANOS;
2021-11-21 23:00:00 +01:00
- this.waitUntilNextTick();
2024-12-11 22:26:55 +01:00
- worldGenerationProgressListener.stop();
- this.updateMobSpawningFlags();
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
2024-12-11 22:26:55 +01:00
+ worldloadlistener.stop();
2019-04-25 07:33:13 +02:00
+ // CraftBukkit start
2021-11-21 23:00:00 +01:00
+ // this.updateMobSpawningFlags();
2024-10-22 17:15:00 +02:00
+ worldserver.setSpawnSettings(this.isSpawningMonsters());
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
}
2024-12-11 22:26:55 +01:00
public GameType getDefaultGameType() {
2016-03-02 06:09:29 +01:00
@@ -588,12 +861,16 @@
2024-12-11 22:26:55 +01:00
worldserver.save((ProgressListener) null, flush, worldserver.noSave && !force);
2019-06-25 13:02:13 +02:00
}
2019-04-28 03:13:44 +02:00
2024-12-11 22:26:55 +01:00
- ServerLevel worldserver1 = this.overworld();
- ServerLevelData iworlddataserver = this.worldData.overworldData();
2019-06-25 13:02:13 +02:00
+ // CraftBukkit start - moved to WorldServer.save
+ /*
2024-12-11 22:26:55 +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
2024-12-11 22:26:55 +01:00
if (flush) {
2021-11-21 23:00:00 +01:00
Iterator iterator1 = this.getAllLevels().iterator();
2019-04-28 03:13:44 +02:00
2016-03-02 06:09:29 +01:00
@@ -628,18 +905,41 @@
2021-11-21 23:00:00 +01:00
this.stopServer();
2014-08-05 18:20:19 +02:00
}
2013-12-13 01:58:58 +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() {
2024-12-11 22:26:55 +01:00
+ synchronized (this.stopLock) {
+ return this.hasStopped;
2019-04-23 04:00:00 +02:00
+ }
2014-08-05 18:20:19 +02:00
+ }
2015-02-07 11:39:00 +01:00
+ // CraftBukkit end
2013-12-13 01:58:58 +01:00
+
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
2024-12-11 22:26:55 +01:00
+ synchronized(this.stopLock) {
+ if (this.hasStopped) return;
+ this.hasStopped = true;
2015-02-07 11:39:00 +01:00
+ }
+ // 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
2022-10-30 00:22:32 +02:00
+ if (io.papermc.paper.plugin.PluginInitializerManager.instance().pluginRemapper != null) io.papermc.paper.plugin.PluginInitializerManager.instance().pluginRemapper.shutdown(); // Paper - Plugin remapping
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");
2016-03-02 06:09:29 +01:00
@@ -693,6 +993,15 @@
2014-05-24 00:05:10 +02:00
} catch (IOException ioexception1) {
MinecraftServer.LOGGER.error("Failed to unlock level {}", this.storageSource.getLevelId(), ioexception1);
}
+ // Spigot start
2016-03-29 02:55:47 +02:00
+ io.papermc.paper.util.MCUtil.ASYNC_EXECUTOR.shutdown(); // Paper
+ try { io.papermc.paper.util.MCUtil.ASYNC_EXECUTOR.awaitTermination(30, java.util.concurrent.TimeUnit.SECONDS); // Paper
+ } catch (java.lang.InterruptedException ignored) {} // Paper
2014-05-24 00:05:10 +02:00
+ if (org.spigotmc.SpigotConfig.saveUserCacheOnStopOnly) {
+ MinecraftServer.LOGGER.info("Saving usercache.json");
+ this.getProfileCache().save();
+ }
+ // Spigot end
}
2016-03-02 06:09:29 +01:00
@@ -715,10 +1024,68 @@
this.serverThread.join();
} catch (InterruptedException interruptedexception) {
MinecraftServer.LOGGER.error("Error while shutting down", interruptedexception);
+ }
+ }
+
+ }
+
2017-01-26 22:50:51 +01:00
+ // Spigot Start
+ private static double calcTps(double avg, double exp, double tps)
+ {
+ return ( avg * exp ) + ( tps * ( 1 - exp ) );
2022-10-30 00:22:32 +02:00
+ }
+
2016-03-02 06:09:29 +01:00
+ // Paper start - Further improve server tick loop
+ private static final long SEC_IN_NANO = 1000000000;
+ private static final long MAX_CATCHUP_BUFFER = TICK_TIME * TPS * 60L;
+ private long lastTick = 0;
+ private long catchupTime = 0;
+ public final RollingAverage tps1 = new RollingAverage(60);
+ public final RollingAverage tps5 = new RollingAverage(60 * 5);
+ public final RollingAverage tps15 = new RollingAverage(60 * 15);
+
+ public static class RollingAverage {
+ private final int size;
+ private long time;
+ private java.math.BigDecimal total;
+ private int index = 0;
+ private final java.math.BigDecimal[] samples;
+ private final long[] times;
+
+ RollingAverage(int size) {
+ this.size = size;
+ this.time = size * SEC_IN_NANO;
+ this.total = dec(TPS).multiply(dec(SEC_IN_NANO)).multiply(dec(size));
+ this.samples = new java.math.BigDecimal[size];
+ this.times = new long[size];
+ for (int i = 0; i < size; i++) {
+ this.samples[i] = dec(TPS);
+ this.times[i] = SEC_IN_NANO;
+ }
+ }
+
+ private static java.math.BigDecimal dec(long t) {
+ return new java.math.BigDecimal(t);
+ }
+ public void add(java.math.BigDecimal x, long t) {
+ time -= times[index];
+ total = total.subtract(samples[index].multiply(dec(times[index])));
+ samples[index] = x;
+ times[index] = t;
+ time += t;
+ total = total.add(x.multiply(dec(t)));
+ if (++index == size) {
+ index = 0;
}
}
+ public double getAverage() {
+ return total.divide(dec(time), 30, java.math.RoundingMode.HALF_UP).doubleValue();
+ }
}
+ private static final java.math.BigDecimal TPS_BASE = new java.math.BigDecimal(1E9).multiply(new java.math.BigDecimal(SAMPLE_INTERVAL));
+ // Paper end
+ // Spigot End
2017-01-26 22:50:51 +01:00
protected void runServer() {
try {
2016-03-02 06:09:29 +01:00
@@ -727,9 +1094,15 @@
2023-03-14 17:30:00 +01:00
}
2024-12-11 22:26:55 +01:00
this.nextTickTimeNanos = Util.getNanos();
- this.statusIcon = (ServerStatus.Favicon) this.loadStatusIcon().orElse((Object) null);
+ this.statusIcon = (ServerStatus.Favicon) this.loadStatusIcon().orElse(null); // CraftBukkit - decompile error
2023-03-14 17:30:00 +01:00
this.status = this.buildServerStatus();
2017-01-26 22:50:51 +01:00
+ // Spigot start
+ Arrays.fill( this.recentTps, 20 );
2016-03-02 06:09:29 +01:00
+ // Paper start - further improve server tick loop
+ long tickSection = Util.getNanos();
+ long currentTime;
+ // Paper end - further improve server tick loop
2022-06-07 18:00:00 +02:00
while (this.running) {
2017-01-26 22:50:51 +01:00
long i;
2016-03-02 06:09:29 +01:00
@@ -744,12 +1117,31 @@
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;
2024-12-11 22:26:55 +01:00
+ if (this.server.getWarnOnOverload()) // CraftBukkit
MinecraftServer.LOGGER.warn("Can't keep up! Is the server overloaded? Running {}ms or {} ticks behind", j / TimeUtil.NANOSECONDS_PER_MILLISECOND, k);
2023-12-05 17:40:00 +01:00
this.nextTickTimeNanos += k * i;
this.lastOverloadWarningNanos = this.nextTickTimeNanos;
2017-01-26 22:50:51 +01:00
}
2021-01-29 17:54:03 +01:00
}
2017-01-26 22:50:51 +01:00
+ // Spigot start
2016-03-02 06:09:29 +01:00
+ // Paper start - further improve server tick loop
+ currentTime = Util.getNanos();
+ if (++MinecraftServer.currentTick % MinecraftServer.SAMPLE_INTERVAL == 0) {
+ final long diff = currentTime - tickSection;
+ final java.math.BigDecimal currentTps = TPS_BASE.divide(new java.math.BigDecimal(diff), 30, java.math.RoundingMode.HALF_UP);
+ tps1.add(currentTps, diff);
+ tps5.add(currentTps, diff);
+ tps15.add(currentTps, diff);
+ // Backwards compat with bad plugins
+ this.recentTps[0] = tps1.getAverage();
+ this.recentTps[1] = tps5.getAverage();
+ this.recentTps[2] = tps15.getAverage();
+ tickSection = currentTime;
2021-01-29 17:54:03 +01:00
+ }
2016-03-02 06:09:29 +01:00
+ // Paper end - further improve server tick loop
2017-01-26 22:50:51 +01:00
+ // Spigot end
2016-03-02 06:09:29 +01:00
+
2017-01-26 22:50:51 +01:00
boolean flag = i == 0L;
2016-03-02 06:09:29 +01:00
if (this.debugCommandProfilerDelayStart) {
@@ -757,6 +1149,8 @@
2024-12-11 22:26:55 +01:00
this.debugCommandProfiler = new MinecraftServer.TimeProfiler(Util.getNanos(), this.tickCount);
2022-06-07 18:00:00 +02:00
}
2016-03-02 06:09:29 +01:00
+ //MinecraftServer.currentTick = (int) (System.currentTimeMillis() / 50); // CraftBukkit // Paper - don't overwrite current tick time
+ lastTick = currentTime;
2023-12-05 17:40:00 +01:00
this.nextTickTimeNanos += i;
2024-10-22 17:15:00 +02:00
try {
2016-03-02 06:09:29 +01:00
@@ -830,6 +1224,13 @@
2022-06-07 18:00:00 +02:00
this.services.profileCache().clearExecutor();
2021-11-21 23:00:00 +01:00
}
2014-08-05 18:20:19 +02:00
+ org.spigotmc.WatchdogThread.doStop(); // Spigot
2014-11-25 22:32:16 +01:00
+ // CraftBukkit start - Restore terminal to original settings
+ try {
2017-06-09 19:03:43 +02:00
+ net.minecrell.terminalconsole.TerminalConsoleAppender.close(); // Paper - Use TerminalConsoleAppender
2014-11-25 22:32:16 +01:00
+ } catch (Exception ignored) {
+ }
+ // CraftBukkit end
2021-11-21 23:00:00 +01:00
this.onServerExit();
2014-11-25 22:32:16 +01:00
}
2016-03-02 06:09:29 +01:00
@@ -889,9 +1290,16 @@
2019-04-25 07:33:13 +02:00
}
2021-11-21 23:00:00 +01:00
private boolean haveTime() {
2024-12-11 22:26:55 +01:00
- return this.runningTask() || Util.getNanos() < (this.mayHaveDelayedTasks ? this.delayedTasksMaxNextTickTimeNanos : this.nextTickTimeNanos);
2019-04-25 07:33:13 +02:00
+ // CraftBukkit start
2024-12-11 22:26:55 +01:00
+ return this.forceTicks || this.runningTask() || Util.getNanos() < (this.mayHaveDelayedTasks ? this.delayedTasksMaxNextTickTimeNanos : this.nextTickTimeNanos);
}
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
2024-12-11 22:26:55 +01:00
+ }
+
2024-06-13 17:05:00 +02:00
public static boolean throwIfFatalException() {
2024-12-11 22:26:55 +01:00
RuntimeException runtimeexception = (RuntimeException) MinecraftServer.fatalException.get();
2016-03-02 06:09:29 +01:00
@@ -903,7 +1311,7 @@
2024-06-13 17:05:00 +02:00
}
2024-12-11 22:26:55 +01:00
public static void setFatalException(RuntimeException exception) {
- MinecraftServer.fatalException.compareAndSet((Object) null, exception);
+ MinecraftServer.fatalException.compareAndSet(null, exception); // CraftBukkit - decompile error
2024-06-13 17:05:00 +02:00
}
@Override
2016-03-02 06:09:29 +01:00
@@ -977,7 +1385,7 @@
2021-11-21 23:00:00 +01:00
}
}
2024-12-11 22:26:55 +01:00
- public void doRunTask(TickTask ticktask) {
2021-11-21 23:00:00 +01:00
+ public void doRunTask(TickTask ticktask) { // CraftBukkit - decompile error
2024-10-22 17:15:00 +02:00
Profiler.get().incrementCounter("runTask");
2021-11-21 23:00:00 +01:00
super.doRunTask(ticktask);
}
2016-03-02 06:09:29 +01:00
@@ -1025,6 +1433,7 @@
2014-08-05 18:20:19 +02:00
}
public void tickServer(BooleanSupplier shouldKeepTicking) {
+ org.spigotmc.WatchdogThread.tick(); // Spigot
long i = Util.getNanos();
int j = this.pauseWhileEmptySeconds() * 20;
2016-03-02 06:09:29 +01:00
@@ -1041,11 +1450,13 @@
2024-10-22 17:15:00 +02:00
this.autoSave();
}
+ this.server.getScheduler().mainThreadHeartbeat(); // CraftBukkit
this.tickConnection();
return;
}
2013-01-10 06:18:11 +01:00
}
+ SpigotTimings.serverTickTimer.startTiming(); // Spigot
++this.tickCount;
this.tickRateManager.tick();
this.tickChildren(shouldKeepTicking);
2016-03-02 06:09:29 +01:00
@@ -1055,7 +1466,7 @@
2014-11-25 22:32:16 +01:00
}
2023-12-05 17:40:00 +01:00
--this.ticksUntilAutosave;
- if (this.ticksUntilAutosave <= 0) {
2024-10-22 17:15:00 +02:00
+ if (this.autosavePeriod > 0 && this.ticksUntilAutosave <= 0) { // CraftBukkit
this.autoSave();
}
2016-03-02 06:09:29 +01:00
@@ -1071,10 +1482,13 @@
2013-01-10 06:18:11 +01:00
this.smoothedTickTimeMillis = this.smoothedTickTimeMillis * 0.8F + (float) k / (float) TimeUtil.NANOSECONDS_PER_MILLISECOND * 0.19999999F;
this.logTickMethodTime(i);
gameprofilerfiller.pop();
+ SpigotTimings.serverTickTimer.stopTiming(); // Spigot
+ org.spigotmc.CustomTimingsHandler.tick(); // Spigot
2024-10-22 17:15:00 +02:00
}
private void autoSave() {
- this.ticksUntilAutosave = this.computeNextAutosaveInterval();
+ this.ticksUntilAutosave = this.autosavePeriod; // CraftBukkit
2013-01-10 06:18:11 +01:00
+ SpigotTimings.worldSaveTimer.startTiming(); // Spigot
2024-10-22 17:15:00 +02:00
MinecraftServer.LOGGER.debug("Autosave started");
2024-12-11 22:26:55 +01:00
ProfilerFiller gameprofilerfiller = Profiler.get();
2024-10-22 17:15:00 +02:00
2016-03-02 06:09:29 +01:00
@@ -1082,6 +1496,7 @@
2013-01-10 06:18:11 +01:00
this.saveEverything(true, false, false);
gameprofilerfiller.pop();
MinecraftServer.LOGGER.debug("Autosave finished");
+ SpigotTimings.worldSaveTimer.stopTiming(); // Spigot
}
private void logTickMethodTime(long tickStartTime) {
2016-03-02 06:09:29 +01:00
@@ -1123,7 +1538,7 @@
2021-01-29 17:54:03 +01:00
private ServerStatus buildServerStatus() {
ServerStatus.Players serverping_serverpingplayersample = this.buildPlayerStatus();
- return new ServerStatus(Component.nullToEmpty(this.motd), Optional.of(serverping_serverpingplayersample), Optional.of(ServerStatus.Version.current()), Optional.ofNullable(this.statusIcon), this.enforceSecureProfile());
+ return new ServerStatus(io.papermc.paper.adventure.PaperAdventure.asVanilla(this.motd), Optional.of(serverping_serverpingplayersample), Optional.of(ServerStatus.Version.current()), Optional.ofNullable(this.statusIcon), this.enforceSecureProfile()); // Paper - Adventure
}
private ServerStatus.Players buildPlayerStatus() {
2016-03-02 06:09:29 +01:00
@@ -1154,11 +1569,35 @@
2023-09-21 18:40:00 +02:00
this.getPlayerList().getPlayers().forEach((entityplayer) -> {
entityplayer.connection.suspendFlushing();
});
2013-01-10 06:18:11 +01:00
+ SpigotTimings.schedulerTimer.startTiming(); // Spigot
2024-10-22 17:15:00 +02:00
+ this.server.getScheduler().mainThreadHeartbeat(); // CraftBukkit
2013-01-10 06:18:11 +01:00
+ SpigotTimings.schedulerTimer.stopTiming(); // Spigot
2021-01-29 17:54:03 +01:00
+ io.papermc.paper.adventure.providers.ClickCallbackProviderImpl.CALLBACK_MANAGER.handleQueue(this.tickCount); // Paper
2024-10-22 17:15:00 +02:00
gameprofilerfiller.push("commandFunctions");
2013-01-10 06:18:11 +01:00
+ SpigotTimings.commandFunctionsTimer.startTiming(); // Spigot
2021-11-21 23:00:00 +01:00
this.getFunctions().tick();
2013-01-10 06:18:11 +01:00
+ SpigotTimings.commandFunctionsTimer.stopTiming(); // Spigot
2024-10-22 17:15:00 +02:00
gameprofilerfiller.popPush("levels");
2021-11-21 23:00:00 +01:00
Iterator iterator = this.getAllLevels().iterator();
2014-05-24 00:05:10 +02:00
2014-11-25 22:32:16 +01:00
+ // CraftBukkit start
+ // Run tasks that are waiting on processing
2013-01-10 06:18:11 +01:00
+ SpigotTimings.processQueueTimer.startTiming(); // Spigot
2024-12-11 22:26:55 +01:00
+ while (!this.processQueue.isEmpty()) {
+ this.processQueue.remove().run();
2014-11-25 22:32:16 +01:00
+ }
2013-01-10 06:18:11 +01:00
+ SpigotTimings.processQueueTimer.stopTiming(); // Spigot
2014-05-24 00:05:10 +02:00
+
2013-01-10 06:18:11 +01:00
+ SpigotTimings.timeUpdateTimer.startTiming(); // Spigot
2014-11-25 22:32:16 +01:00
+ // 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) {
2024-12-11 22:26:55 +01:00
+ ServerPlayer entityplayer = (ServerPlayer) this.getPlayerList().players.get(i);
+ entityplayer.connection.send(new ClientboundSetTimePacket(entityplayer.level().getGameTime(), entityplayer.getPlayerTime(), entityplayer.serverLevel().getGameRules().getBoolean(GameRules.RULE_DAYLIGHT))); // Add support for per player time
2014-11-25 22:32:16 +01:00
+ }
+ }
2013-01-10 06:18:11 +01:00
+ SpigotTimings.timeUpdateTimer.stopTiming(); // Spigot
2014-11-25 22:32:16 +01:00
+
2019-06-21 12:00:00 +02:00
while (iterator.hasNext()) {
2024-12-11 22:26:55 +01:00
ServerLevel worldserver = (ServerLevel) iterator.next();
2019-06-21 12:00:00 +02:00
2016-03-02 06:09:29 +01:00
@@ -1167,16 +1606,20 @@
2024-04-23 17:15:00 +02:00
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) {
2024-10-22 17:15:00 +02:00
gameprofilerfiller.push("timeSync");
2023-03-14 17:30:00 +01:00
this.synchronizeTime(worldserver);
2024-10-22 17:15:00 +02:00
gameprofilerfiller.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
2024-10-22 17:15:00 +02:00
gameprofilerfiller.push("tick");
2014-11-25 22:32:16 +01:00
2013-01-10 06:18:11 +01:00
try {
+ worldserver.timings.doTick.startTiming(); // Spigot
worldserver.tick(shouldKeepTicking);
+ worldserver.timings.doTick.stopTiming(); // Spigot
} catch (Throwable throwable) {
CrashReport crashreport = CrashReport.forThrowable(throwable, "Exception ticking world");
2016-03-02 06:09:29 +01:00
@@ -1189,18 +1632,24 @@
2013-01-10 06:18:11 +01:00
}
gameprofilerfiller.popPush("connection");
+ SpigotTimings.connectionTimer.startTiming(); // Spigot
this.tickConnection();
+ SpigotTimings.connectionTimer.stopTiming(); // Spigot
gameprofilerfiller.popPush("players");
+ SpigotTimings.playerListTimer.startTiming(); // Spigot
this.playerList.tick();
+ SpigotTimings.playerListTimer.stopTiming(); // Spigot
if (SharedConstants.IS_RUNNING_IN_IDE && this.tickRateManager.runsNormally()) {
GameTestTicker.SINGLETON.tick();
}
gameprofilerfiller.popPush("server gui refresh");
+ SpigotTimings.tickablesTimer.startTiming(); // Spigot
for (int i = 0; i < this.tickables.size(); ++i) {
((Runnable) this.tickables.get(i)).run();
}
+ SpigotTimings.tickablesTimer.stopTiming(); // Spigot
gameprofilerfiller.popPush("send chunks");
iterator = this.playerList.getPlayers().iterator();
2016-03-02 06:09:29 +01:00
@@ -1267,6 +1716,22 @@
2024-12-11 22:26:55 +01:00
return (ServerLevel) this.levels.get(key);
2016-03-02 06:09:29 +01:00
}
2022-08-14 02:46:41 +02:00
+ // CraftBukkit start
2024-12-11 22:26:55 +01:00
+ public void addLevel(ServerLevel level) {
+ Map<ResourceKey<Level>, ServerLevel> oldLevels = this.levels;
+ Map<ResourceKey<Level>, ServerLevel> newLevels = Maps.newLinkedHashMap(oldLevels);
2022-08-14 02:46:41 +02:00
+ newLevels.put(level.dimension(), level);
+ this.levels = Collections.unmodifiableMap(newLevels);
+ }
+
2024-12-11 22:26:55 +01:00
+ public void removeLevel(ServerLevel level) {
+ Map<ResourceKey<Level>, ServerLevel> oldLevels = this.levels;
+ Map<ResourceKey<Level>, ServerLevel> newLevels = Maps.newLinkedHashMap(oldLevels);
2022-08-14 02:46:41 +02:00
+ newLevels.remove(level.dimension());
+ this.levels = Collections.unmodifiableMap(newLevels);
2016-03-02 06:09:29 +01:00
+ }
2022-08-14 02:46:41 +02:00
+ // CraftBukkit end
2016-03-02 06:09:29 +01:00
+
2024-12-11 22:26:55 +01:00
public Set<ResourceKey<Level>> levelKeys() {
2022-08-14 02:46:41 +02:00
return this.levels.keySet();
2016-03-02 06:09:29 +01:00
}
@@ -1296,7 +1761,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";
2014-04-11 12:16:34 +02:00
+ return "Spigot"; // Spigot - Spigot > // CraftBukkit - cb > vanilla!
2014-11-25 22:32:16 +01:00
}
2024-12-11 22:26:55 +01:00
public SystemReport fillSystemReport(SystemReport details) {
2016-03-02 06:09:29 +01:00
@@ -1347,7 +1812,7 @@
2017-06-09 19:03:43 +02:00
@Override
public void sendSystemMessage(Component message) {
- MinecraftServer.LOGGER.info(message.getString());
+ MinecraftServer.LOGGER.info(io.papermc.paper.adventure.PaperAdventure.ANSI_SERIALIZER.serialize(io.papermc.paper.adventure.PaperAdventure.asAdventure(message))); // Paper - Log message with colors
}
public KeyPair getKeyPair() {
2016-03-02 06:09:29 +01:00
@@ -1481,10 +1946,20 @@
2021-01-29 17:54:03 +01:00
@Override
public String getMotd() {
- return this.motd;
+ return net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().serialize(this.motd); // Paper - Adventure
}
public void setMotd(String motd) {
+ // Paper start - Adventure
+ this.motd = net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserializeOr(motd, net.kyori.adventure.text.Component.empty());
+ }
+
+ public net.kyori.adventure.text.Component motd() {
+ return this.motd;
+ }
+
+ public void motd(net.kyori.adventure.text.Component motd) {
+ // Paper end - Adventure
this.motd = motd;
}
2016-03-02 06:09:29 +01:00
@@ -1507,7 +1982,7 @@
2013-12-13 01:58:58 +01:00
}
public ServerConnectionListener getConnection() {
- return this.connection;
+ return this.connection == null ? this.connection = new ServerConnectionListener(this) : this.connection; // Spigot
}
public boolean isReady() {
2016-03-02 06:09:29 +01:00
@@ -1634,11 +2109,11 @@
2024-04-23 17:15:00 +02:00
2024-12-11 22:26:55 +01:00
public CompletableFuture<Void> reloadResources(Collection<String> dataPacks) {
2020-06-25 02:00:00 +02:00
CompletableFuture<Void> completablefuture = CompletableFuture.supplyAsync(() -> {
2024-12-11 22:26:55 +01:00
- Stream stream = dataPacks.stream();
+ Stream<String> stream = dataPacks.stream(); // CraftBukkit - decompile error
PackRepository resourcepackrepository = this.packRepository;
2020-06-25 02:00:00 +02:00
2021-06-11 07:00:00 +02:00
Objects.requireNonNull(this.packRepository);
2024-12-11 22:26:55 +01:00
- return (ImmutableList) stream.map(resourcepackrepository::getPack).filter(Objects::nonNull).map(Pack::open).collect(ImmutableList.toImmutableList());
2016-03-31 01:36:20 +02:00
+ return stream.<Pack>map(resourcepackrepository::getPack).filter(Objects::nonNull).map(Pack::open).collect(ImmutableList.toImmutableList()); // CraftBukkit - decompile error // Paper - decompile error // todo: is this needed anymore?
2020-06-25 02:00:00 +02:00
}, this).thenCompose((immutablelist) -> {
2024-12-11 22:26:55 +01:00
MultiPackResourceManager resourcemanager = new MultiPackResourceManager(PackType.SERVER_DATA, immutablelist);
List<Registry.PendingTags<?>> list = TagLoader.loadTagsForExistingRegistries(resourcemanager, this.registries.compositeAccess());
2016-03-02 06:09:29 +01:00
@@ -1654,6 +2129,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
2024-12-11 22:26:55 +01:00
this.packRepository.setSelected(dataPacks);
WorldDataConfiguration worlddataconfiguration = new WorldDataConfiguration(MinecraftServer.getSelectedPacks(this.packRepository, true), this.worldData.enabledFeatures());
2024-04-23 17:15:00 +02:00
2016-03-02 06:09:29 +01:00
@@ -1952,7 +2428,7 @@
2024-04-23 17:15:00 +02:00
final List<String> list = Lists.newArrayList();
final GameRules gamerules = this.getGameRules();
2024-12-11 22:26:55 +01:00
- gamerules.visitGameRuleTypes(new GameRules.GameRuleTypeVisitor(this) {
+ gamerules.visitGameRuleTypes(new GameRules.GameRuleTypeVisitor() { // CraftBukkit - decompile error
2024-04-23 17:15:00 +02:00
@Override
2024-12-11 22:26:55 +01:00
public <T extends GameRules.Value<T>> void visit(GameRules.Key<T> key, GameRules.Type<T> type) {
list.add(String.format(Locale.ROOT, "%s=%s\n", key.getId(), gamerules.getRule(key)));
2016-03-02 06:09:29 +01:00
@@ -2058,7 +2534,7 @@
2021-11-21 23:00:00 +01:00
try {
label51:
{
- ArrayList arraylist;
2024-12-11 22:26:55 +01:00
+ ArrayList<NativeModuleLister.NativeModuleInfo> arraylist; // CraftBukkit - decompile error
2021-11-21 23:00:00 +01:00
try {
arraylist = Lists.newArrayList(NativeModuleLister.listModules());
2016-03-02 06:09:29 +01:00
@@ -2105,8 +2581,24 @@
2014-05-24 00:05:10 +02:00
if (bufferedwriter != null) {
bufferedwriter.close();
}
+
+ }
2016-03-02 06:09:29 +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-03-02 06:09:29 +01:00
+ }
+
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;
2017-01-26 22:50:51 +01:00
+ }
2016-03-02 06:09:29 +01:00
2024-04-23 17:15:00 +02:00
+ @Deprecated
2024-12-11 22:26:55 +01:00
+ public static RegistryAccess getDefaultRegistryAccess() {
2024-04-23 17:15:00 +02:00
+ return CraftRegistry.getMinecraftRegistry();
2016-03-02 06:09:29 +01:00
}
2016-02-29 22:32:46 +01:00
+ // CraftBukkit end
2016-03-02 06:09:29 +01:00
2024-12-11 22:26:55 +01:00
private ProfilerFiller createProfiler() {
2021-06-11 07:00:00 +02:00
if (this.willStartRecordingMetrics) {
2016-03-02 06:09:29 +01:00
@@ -2225,18 +2717,24 @@
2021-01-29 17:54:03 +01:00
}
public void logChatMessage(Component message, ChatType.Bound params, @Nullable String prefix) {
- String s1 = params.decorate(message).getString();
+ // Paper start
+ net.kyori.adventure.text.Component s1 = io.papermc.paper.adventure.PaperAdventure.asAdventure(params.decorate(message));
if (prefix != null) {
- MinecraftServer.LOGGER.info("[{}] {}", prefix, s1);
+ MinecraftServer.COMPONENT_LOGGER.info("[{}] {}", prefix, s1);
} else {
- MinecraftServer.LOGGER.info("{}", s1);
+ MinecraftServer.COMPONENT_LOGGER.info("{}", s1);
+ // Paper end
}
2022-07-27 20:00:00 +02:00
}
2014-05-24 00:05:10 +02:00
2022-07-27 20:00:00 +02:00
+ public final java.util.concurrent.ExecutorService chatExecutor = java.util.concurrent.Executors.newCachedThreadPool(
2021-01-29 17:54:03 +01:00
+ new com.google.common.util.concurrent.ThreadFactoryBuilder().setDaemon(true).setNameFormat("Async Chat Thread - #%d").setUncaughtExceptionHandler(new net.minecraft.DefaultUncaughtExceptionHandlerWithName(net.minecraft.server.MinecraftServer.LOGGER)).build()); // Paper
2014-05-24 00:05:10 +02:00
+
2021-01-29 17:54:03 +01:00
+ public final ChatDecorator improvedChatDecorator = new io.papermc.paper.adventure.ImprovedChatDecorator(this); // Paper - adventure
2022-07-27 20:00:00 +02:00
public ChatDecorator getChatDecorator() {
2021-01-29 17:54:03 +01:00
- return ChatDecorator.PLAIN;
+ return this.improvedChatDecorator; // Paper - support async chat decoration events
2014-05-24 00:05:10 +02:00
}
2021-01-29 17:54:03 +01:00
public boolean logIPs() {