Co-authored-by: Bjarne Koll <git@lynxplay.dev>
Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com>
Co-authored-by: Lulu13022002 <41980282+Lulu13022002@users.noreply.github.com>
Co-authored-by: MiniDigger | Martin <admin@minidigger.dev>
Co-authored-by: Nassim Jahnke <nassim@njahnke.dev>
Co-authored-by: Noah van der Aa <ndvdaa@gmail.com>
Co-authored-by: Owen1212055 <23108066+Owen1212055@users.noreply.github.com>
Co-authored-by: Shane Freeder <theboyetronic@gmail.com>
Co-authored-by: Spottedleaf <Spottedleaf@users.noreply.github.com>
Co-authored-by: Tamion <70228790+notTamion@users.noreply.github.com>
Co-authored-by: Warrior <50800980+Warriorrrr@users.noreply.github.com>
This commit is contained in:
Nassim Jahnke
2025-04-12 17:26:44 +02:00
parent 0767902699
commit f00727c57e
2092 changed files with 50551 additions and 48729 deletions

View File

@@ -1,6 +1,6 @@
--- a/net/minecraft/server/MinecraftServer.java
+++ b/net/minecraft/server/MinecraftServer.java
@@ -174,11 +_,13 @@
@@ -173,11 +_,13 @@
import org.slf4j.Logger;
public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTask> implements ServerInfo, ChunkIOErrorReporter, CommandSource {
@@ -15,7 +15,7 @@
private static final int OVERLOADED_TICKS_THRESHOLD = 20;
private static final long OVERLOADED_WARNING_INTERVAL_NANOS = 10L * TimeUtil.NANOSECONDS_PER_SECOND;
private static final int OVERLOADED_TICKS_WARNING_INTERVAL = 100;
@@ -218,6 +_,7 @@
@@ -217,6 +_,7 @@
private Map<ResourceKey<Level>, ServerLevel> levels = Maps.newLinkedHashMap();
private PlayerList playerList;
private volatile boolean running = true;
@@ -23,7 +23,7 @@
private boolean stopped;
private int tickCount;
private int ticksUntilAutosave = 6000;
@@ -226,11 +_,15 @@
@@ -225,11 +_,15 @@
private boolean preventProxyConnections;
private boolean pvp;
private boolean allowFlight;
@@ -41,7 +41,7 @@
@Nullable
private KeyPair keyPair;
@Nullable
@@ -271,10 +_,37 @@
@@ -270,10 +_,37 @@
private final SuppressedExceptionCollector suppressedExceptions = new SuppressedExceptionCollector();
private final DiscontinuousFrame tickFrame;
@@ -80,7 +80,7 @@
if (Runtime.getRuntime().availableProcessors() > 4) {
thread.setPriority(8);
}
@@ -286,6 +_,10 @@
@@ -285,6 +_,10 @@
}
public MinecraftServer(
@@ -91,7 +91,7 @@
Thread serverThread,
LevelStorageSource.LevelStorageAccess storageSource,
PackRepository packRepository,
@@ -296,9 +_,10 @@
@@ -295,9 +_,10 @@
ChunkProgressListenerFactory progressListenerFactory
) {
super("Server");
@@ -103,7 +103,7 @@
throw new IllegalStateException("Missing Overworld dimension data");
} else {
this.proxy = proxy;
@@ -309,7 +_,7 @@
@@ -308,7 +_,7 @@
services.profileCache().setExecutor(this);
}
@@ -112,7 +112,7 @@
this.tickRateManager = new ServerTickRateManager(this);
this.progressListenerFactory = progressListenerFactory;
this.storageSource = storageSource;
@@ -328,6 +_,38 @@
@@ -327,6 +_,38 @@
this.fuelValues = FuelValues.vanillaBurnTimes(this.registries.compositeAccess(), this.worldData.enabledFeatures());
this.tickFrame = TracyClient.createDiscontinuousFrame("Server Tick");
}
@@ -151,7 +151,7 @@
}
private void readScoreboard(DimensionDataStorage dataStorage) {
@@ -336,18 +_,13 @@
@@ -335,18 +_,13 @@
protected abstract boolean initServer() throws IOException;
@@ -172,7 +172,7 @@
if (profiledDuration != null) {
profiledDuration.finish(true);
}
@@ -364,25 +_,265 @@
@@ -363,25 +_,265 @@
protected void forceDifficulty() {
}
@@ -349,7 +349,7 @@
+
+ primaryLevelData.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 (this.options.has("forceUpgrade")) {
+ net.minecraft.server.Main.forceUpgrade(levelStorageAccess, net.minecraft.util.datafix.DataFixers.getDataFixer(), this.options.has("eraseCache"), () -> true, registryAccess, this.options.has("recreateRegionFiles"));
+ net.minecraft.server.Main.forceUpgrade(levelStorageAccess, primaryLevelData, net.minecraft.util.datafix.DataFixers.getDataFixer(), this.options.has("eraseCache"), () -> true, registryAccess, this.options.has("recreateRegionFiles"));
+ }
+
+ // Now modelled off the createLevels method
@@ -457,7 +457,7 @@
if (!serverLevelData.isInitialized()) {
try {
setInitialSpawn(serverLevel, serverLevelData, worldOptions.generateBonusChest(), isDebugWorld);
@@ -403,47 +_,30 @@
@@ -402,47 +_,30 @@
serverLevelData.setInitialized(true);
}
@@ -522,7 +522,7 @@
int spawnHeight = chunkSource.getGenerator().getSpawnHeight(level);
if (spawnHeight < level.getMinY()) {
BlockPos worldPosition = chunkPos.getWorldPosition();
@@ -495,26 +_,31 @@
@@ -494,36 +_,48 @@
serverLevelData.setGameType(GameType.SPECTATOR);
}
@@ -557,12 +557,11 @@
- for (ServerLevel serverLevel1 : this.levels.values()) {
+ if (true) {
+ ServerLevel serverLevel1 = serverLevel;
+ final ServerLevel serverLevel1 = serverLevel;
+ // CraftBukkit end
ForcedChunksSavedData forcedChunksSavedData = serverLevel1.getDataStorage().get(ForcedChunksSavedData.factory(), "chunks");
if (forcedChunksSavedData != null) {
LongIterator longIterator = forcedChunksSavedData.getChunks().iterator();
@@ -527,10 +_,17 @@
TicketStorage ticketStorage = serverLevel1.getDataStorage().get(TicketStorage.TYPE);
if (ticketStorage != null) {
ticketStorage.activateAllDeactivatedTickets();
}
}
@@ -583,11 +582,11 @@
}
public GameType getDefaultGameType() {
@@ -559,11 +_,14 @@
@@ -552,11 +_,14 @@
flag = true;
}
+ /* // CraftBukkit start - moved to WorldServer.save
+ /* // CraftBukkit start - moved to ServerLevel#save
ServerLevel serverLevel1 = this.overworld();
ServerLevelData serverLevelData = this.worldData.overworldData();
serverLevelData.setWorldBorder(serverLevel1.getWorldBorder().createSettings());
@@ -598,7 +597,7 @@
if (flush) {
for (ServerLevel serverLevel2 : this.getAllLevels()) {
LOGGER.info("ThreadedAnvilChunkStorage ({}): All chunks are saved", serverLevel2.getChunkSource().chunkMap.getStorageName());
@@ -593,18 +_,48 @@
@@ -586,18 +_,48 @@
this.stopServer();
}
@@ -648,7 +647,7 @@
}
LOGGER.info("Saving worlds");
@@ -646,6 +_,25 @@
@@ -639,6 +_,25 @@
} catch (IOException var4) {
LOGGER.error("Failed to unlock level {}", this.storageSource.getLevelId(), var4);
}
@@ -674,7 +673,7 @@
}
public String getLocalIp() {
@@ -661,6 +_,14 @@
@@ -654,6 +_,14 @@
}
public void halt(boolean waitForServer) {
@@ -689,7 +688,7 @@
this.running = false;
if (waitForServer) {
try {
@@ -671,6 +_,57 @@
@@ -664,6 +_,57 @@
}
}
@@ -747,7 +746,7 @@
protected void runServer() {
try {
if (!this.initServer()) {
@@ -681,6 +_,35 @@
@@ -674,6 +_,35 @@
this.statusIcon = this.loadStatusIcon().orElse(null);
this.status = this.buildServerStatus();
@@ -783,7 +782,7 @@
while (this.running) {
long l;
if (!this.isPaused() && this.tickRateManager.isSprinting() && this.tickRateManager.checkShouldSprintThisTick()) {
@@ -693,11 +_,30 @@
@@ -686,11 +_,30 @@
if (l1 > OVERLOADED_THRESHOLD_NANOS + 20L * l
&& this.nextTickTimeNanos - this.lastOverloadWarningNanos >= OVERLOADED_WARNING_INTERVAL_NANOS + 100L * l) {
long l2 = l1 / l;
@@ -814,7 +813,7 @@
boolean flag = l == 0L;
if (this.debugCommandProfilerDelayStart) {
@@ -705,6 +_,8 @@
@@ -698,6 +_,8 @@
this.debugCommandProfiler = new MinecraftServer.TimeProfiler(Util.getNanos(), this.tickCount);
}
@@ -823,7 +822,7 @@
this.nextTickTimeNanos += l;
try (Profiler.Scope scope = Profiler.use(this.createProfiler())) {
@@ -755,7 +_,7 @@
@@ -748,7 +_,7 @@
this.services.profileCache().clearExecutor();
}
@@ -832,7 +831,7 @@
}
}
}
@@ -807,7 +_,14 @@
@@ -800,7 +_,14 @@
}
private boolean haveTime() {
@@ -848,7 +847,7 @@
}
public static boolean throwIfFatalException() {
@@ -852,6 +_,12 @@
@@ -845,6 +_,12 @@
@Override
public TickTask wrapRunnable(Runnable runnable) {
@@ -861,7 +860,7 @@
return new TickTask(this.tickCount, runnable);
}
@@ -871,15 +_,16 @@
@@ -864,15 +_,16 @@
if (super.pollTask()) {
return true;
} else {
@@ -880,7 +879,7 @@
}
}
@@ -927,26 +_,44 @@
@@ -920,26 +_,44 @@
}
public void tickServer(BooleanSupplier hasTimeLeft) {
@@ -926,7 +925,7 @@
this.tickCount++;
this.tickRateManager.tick();
this.tickChildren(hasTimeLeft);
@@ -956,11 +_,19 @@
@@ -949,11 +_,19 @@
}
this.ticksUntilAutosave--;
@@ -947,7 +946,7 @@
profilerFiller.push("tallying");
long l = Util.getNanos() - nanos;
int i1 = this.tickCount % 100;
@@ -968,12 +_,17 @@
@@ -961,12 +_,17 @@
this.aggregatedTickTimesNanos += l;
this.tickTimesNanos[i1] = l;
this.smoothedTickTimeMillis = this.smoothedTickTimeMillis * 0.8F + (float)l / (float)TimeUtil.NANOSECONDS_PER_MILLISECOND * 0.19999999F;
@@ -966,7 +965,7 @@
LOGGER.debug("Autosave started");
ProfilerFiller profilerFiller = Profiler.get();
profilerFiller.push("save");
@@ -1015,7 +_,7 @@
@@ -1008,7 +_,7 @@
private ServerStatus buildServerStatus() {
ServerStatus.Players players = this.buildPlayerStatus();
return new ServerStatus(
@@ -975,7 +974,7 @@
Optional.of(players),
Optional.of(ServerStatus.Version.current()),
Optional.ofNullable(this.statusIcon),
@@ -1029,7 +_,7 @@
@@ -1022,7 +_,7 @@
if (this.hidesOnlinePlayers()) {
return new ServerStatus.Players(maxPlayers, players.size(), List.of());
} else {
@@ -984,7 +983,7 @@
ObjectArrayList<GameProfile> list = new ObjectArrayList<>(min);
int randomInt = Mth.nextInt(this.random, 0, players.size() - min);
@@ -1046,17 +_,66 @@
@@ -1039,17 +_,66 @@
protected void tickChildren(BooleanSupplier hasTimeLeft) {
ProfilerFiller profilerFiller = Profiler.get();
this.getPlayerList().getPlayers().forEach(serverPlayer1 -> serverPlayer1.connection.suspendFlushing());
@@ -1051,7 +1050,7 @@
profilerFiller.push("tick");
@@ -1070,7 +_,9 @@
@@ -1063,7 +_,9 @@
profilerFiller.pop();
profilerFiller.pop();
@@ -1061,7 +1060,7 @@
profilerFiller.popPush("connection");
this.tickConnection();
@@ -1148,6 +_,22 @@
@@ -1141,6 +_,22 @@
return this.levels.get(dimension);
}
@@ -1084,7 +1083,7 @@
public Set<ResourceKey<Level>> levelKeys() {
return this.levels.keySet();
}
@@ -1177,7 +_,7 @@
@@ -1170,7 +_,7 @@
@DontObfuscate
public String getServerModName() {
@@ -1093,7 +1092,7 @@
}
public SystemReport fillSystemReport(SystemReport systemReport) {
@@ -1212,7 +_,7 @@
@@ -1205,7 +_,7 @@
@Override
public void sendSystemMessage(Component component) {
@@ -1102,7 +1101,7 @@
}
public KeyPair getKeyPair() {
@@ -1250,11 +_,14 @@
@@ -1243,11 +_,14 @@
}
}
@@ -1112,9 +1111,9 @@
- this.updateMobSpawningFlags();
- this.getPlayerList().getPlayers().forEach(this::sendDifficultyUpdate);
+ // Paper start - per level difficulty
+ public void setDifficulty(ServerLevel level, Difficulty difficulty, boolean forceUpdate) {
+ net.minecraft.world.level.storage.PrimaryLevelData worldData = (net.minecraft.world.level.storage.PrimaryLevelData) level.serverLevelData;
+ if (forceUpdate || !worldData.isDifficultyLocked()) {
+ public void setDifficulty(ServerLevel level, Difficulty difficulty, boolean forced) {
+ net.minecraft.world.level.storage.PrimaryLevelData worldData = level.serverLevelData;
+ if (forced || !worldData.isDifficultyLocked()) {
+ worldData.setDifficulty(worldData.isHardcore() ? Difficulty.HARD : difficulty);
+ level.setSpawnSettings(worldData.getDifficulty() != Difficulty.PEACEFUL && ((net.minecraft.server.dedicated.DedicatedServer) this).settings.getProperties().spawnMonsters);
+ // this.getPlayerList().getPlayers().forEach(this::sendDifficultyUpdate);
@@ -1122,7 +1121,7 @@
}
}
@@ -1264,7 +_,7 @@
@@ -1257,7 +_,7 @@
private void updateMobSpawningFlags() {
for (ServerLevel serverLevel : this.getAllLevels()) {
@@ -1131,7 +1130,7 @@
}
}
@@ -1340,10 +_,20 @@
@@ -1333,10 +_,20 @@
@Override
public String getMotd() {
@@ -1153,7 +1152,7 @@
this.motd = motd;
}
@@ -1366,7 +_,7 @@
@@ -1359,7 +_,7 @@
}
public ServerConnectionListener getConnection() {
@@ -1162,7 +1161,7 @@
}
public boolean isReady() {
@@ -1452,7 +_,7 @@
@@ -1445,7 +_,7 @@
@Override
public void executeIfPossible(Runnable task) {
if (this.isStopped()) {
@@ -1171,7 +1170,7 @@
} else {
super.executeIfPossible(task);
}
@@ -1491,7 +_,13 @@
@@ -1484,7 +_,14 @@
return this.functionManager;
}
@@ -1180,12 +1179,13 @@
public CompletableFuture<Void> reloadResources(Collection<String> selectedIds) {
+ return this.reloadResources(selectedIds, io.papermc.paper.event.server.ServerResourcesReloadedEvent.Cause.PLUGIN);
+ }
+
+ public CompletableFuture<Void> reloadResources(Collection<String> selectedIds, io.papermc.paper.event.server.ServerResourcesReloadedEvent.Cause cause) {
+ // Paper end - Add ServerResourcesReloadedEvent
CompletableFuture<Void> completableFuture = CompletableFuture.<ImmutableList>supplyAsync(
() -> selectedIds.stream().map(this.packRepository::getPack).filter(Objects::nonNull).map(Pack::open).collect(ImmutableList.toImmutableList()),
this
@@ -1499,7 +_,7 @@
@@ -1492,7 +_,7 @@
.thenCompose(
list -> {
CloseableResourceManager closeableResourceManager = new MultiPackResourceManager(PackType.SERVER_DATA, list);
@@ -1194,7 +1194,7 @@
return ReloadableServerResources.loadResources(
closeableResourceManager,
this.registries,
@@ -1520,20 +_,39 @@
@@ -1513,20 +_,39 @@
)
.thenAcceptAsync(
reloadableResources -> {
@@ -1236,7 +1236,7 @@
},
this
);
@@ -1550,7 +_,7 @@
@@ -1543,7 +_,7 @@
DataPackConfig dataPackConfig = initialDataConfig.dataPacks();
FeatureFlagSet featureFlagSet = initMode ? FeatureFlagSet.of() : initialDataConfig.enabledFeatures();
FeatureFlagSet featureFlagSet1 = initMode ? FeatureFlags.REGISTRY.allFlags() : initialDataConfig.enabledFeatures();
@@ -1245,7 +1245,7 @@
if (safeMode) {
return configureRepositoryWithSelection(packRepository, List.of("vanilla"), featureFlagSet, false);
} else {
@@ -1605,7 +_,7 @@
@@ -1598,7 +_,7 @@
private static WorldDataConfiguration configureRepositoryWithSelection(
PackRepository packRepository, Collection<String> selectedPacks, FeatureFlagSet enabledFeatures, boolean safeMode
) {
@@ -1254,7 +1254,7 @@
enableForcedFeaturePacks(packRepository, enabledFeatures);
DataPackConfig selectedPacks1 = getSelectedPacks(packRepository, safeMode);
FeatureFlagSet featureFlagSet = packRepository.getRequestedFeatureFlags().join(enabledFeatures);
@@ -1637,7 +_,7 @@
@@ -1630,7 +_,7 @@
}
}
@@ -1263,7 +1263,7 @@
}
}
@@ -1651,11 +_,12 @@
@@ -1644,11 +_,12 @@
public void kickUnlistedPlayers(CommandSourceStack commandSource) {
if (this.isEnforceWhitelist()) {
PlayerList playerList = commandSource.getServer().getPlayerList();
@@ -1278,7 +1278,7 @@
}
}
}
@@ -1859,6 +_,22 @@
@@ -1852,6 +_,17 @@
}
}
@@ -1289,19 +1289,14 @@
+ }
+
+ public static MinecraftServer getServer() {
+ return SERVER; // Paper
+ }
+
+ @Deprecated
+ public static RegistryAccess getDefaultRegistryAccess() {
+ return org.bukkit.craftbukkit.CraftRegistry.getMinecraftRegistry();
+ return SERVER;
+ }
+ // CraftBukkit end
+
private ProfilerFiller createProfiler() {
if (this.willStartRecordingMetrics) {
this.metricsRecorder = ActiveMetricsRecorder.createStarted(
@@ -1980,16 +_,22 @@
@@ -1973,16 +_,22 @@
}
public void logChatMessage(Component content, ChatType.Bound boundChatType, @Nullable String header) {
@@ -1328,7 +1323,7 @@
}
public boolean logIPs() {
@@ -2122,4 +_,53 @@
@@ -2115,4 +_,53 @@
};
}
}