2021-06-11 14:02:28 +02:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Aikar <aikar@aikar.co>
|
|
|
|
Date: Sun, 28 Jun 2020 03:59:10 -0400
|
|
|
|
Subject: [PATCH] Fix Per World Difficulty / Remembering Difficulty
|
|
|
|
|
|
|
|
Fixes per world difficulty with /difficulty command and also
|
|
|
|
makes it so that the server keeps the last difficulty used instead
|
|
|
|
of restoring the server.properties every single load.
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
|
2023-08-28 13:05:48 +02:00
|
|
|
index ccf238c12c416e2aa7ee83a14bbbb96f5b2f8b51..c09adcb869edf273c633ce996b048173ded89703 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
|
2023-08-28 13:05:48 +02:00
|
|
|
@@ -797,7 +797,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
2023-06-08 01:20:26 +02:00
|
|
|
if (worldserver.getWorld().getKeepSpawnInMemory()) worldloadlistener.stop(); // Paper
|
2021-10-01 02:46:37 +02:00
|
|
|
// CraftBukkit start
|
2021-11-24 13:30:55 +01:00
|
|
|
// this.updateMobSpawningFlags();
|
2021-10-01 02:46:37 +02:00
|
|
|
- worldserver.setSpawnSettings(this.isSpawningMonsters(), this.isSpawningAnimals());
|
|
|
|
+ worldserver.setSpawnSettings(worldserver.serverLevelData.getDifficulty() != Difficulty.PEACEFUL && ((DedicatedServer) this).settings.getProperties().spawnMonsters, this.isSpawningAnimals()); // Paper - per level difficulty (from setDifficulty(ServerLevel, Difficulty, boolean))
|
|
|
|
|
|
|
|
this.forceTicks = false;
|
|
|
|
// CraftBukkit end
|
2023-08-28 13:05:48 +02:00
|
|
|
@@ -1725,11 +1725,14 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-14 10:37:14 +02:00
|
|
|
- public void setDifficulty(Difficulty difficulty, boolean forceUpdate) {
|
2021-06-11 14:02:28 +02:00
|
|
|
- if (forceUpdate || !this.worldData.isDifficultyLocked()) {
|
2021-06-14 10:37:14 +02:00
|
|
|
- this.worldData.setDifficulty(this.worldData.isHardcore() ? Difficulty.HARD : difficulty);
|
2021-06-11 14:02:28 +02:00
|
|
|
- this.updateMobSpawningFlags();
|
|
|
|
- this.getPlayerList().getPlayers().forEach(this::sendDifficultyUpdate);
|
2021-06-14 10:37:14 +02:00
|
|
|
+ // Paper start - remember per level difficulty
|
|
|
|
+ public void setDifficulty(ServerLevel level, Difficulty difficulty, boolean forceUpdate) {
|
|
|
|
+ PrimaryLevelData worldData = level.serverLevelData;
|
|
|
|
+ if (forceUpdate || !worldData.isDifficultyLocked()) {
|
|
|
|
+ worldData.setDifficulty(worldData.isHardcore() ? Difficulty.HARD : difficulty);
|
|
|
|
+ level.setSpawnSettings(worldData.getDifficulty() != Difficulty.PEACEFUL && ((DedicatedServer) this).settings.getProperties().spawnMonsters, this.isSpawningAnimals());
|
|
|
|
+ // this.getPlayerList().getPlayers().forEach(this::sendDifficultyUpdate);
|
2021-06-11 14:02:28 +02:00
|
|
|
+ // Paper end
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-28 13:05:48 +02:00
|
|
|
@@ -1743,7 +1746,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
2021-10-01 02:46:37 +02:00
|
|
|
while (iterator.hasNext()) {
|
|
|
|
ServerLevel worldserver = (ServerLevel) iterator.next();
|
|
|
|
|
|
|
|
- worldserver.setSpawnSettings(this.isSpawningMonsters(), this.isSpawningAnimals());
|
|
|
|
+ worldserver.setSpawnSettings(worldserver.serverLevelData.getDifficulty() != Difficulty.PEACEFUL && ((DedicatedServer) this).settings.getProperties().spawnMonsters, this.isSpawningAnimals()); // Paper - per level difficulty (from setDifficulty(ServerLevel, Difficulty, boolean))
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2021-06-11 14:02:28 +02:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/commands/DifficultyCommand.java b/src/main/java/net/minecraft/server/commands/DifficultyCommand.java
|
2023-06-08 01:20:26 +02:00
|
|
|
index 89be3991ef4fb2deb7276c5409cb571a7fb1f821..9c272f7cf8cbd2bbe147e57f7fabe135b6ff5c0b 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/commands/DifficultyCommand.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/commands/DifficultyCommand.java
|
2023-06-08 01:20:26 +02:00
|
|
|
@@ -49,7 +49,7 @@ public class DifficultyCommand {
|
2022-03-01 06:43:03 +01:00
|
|
|
if (worldServer.getDifficulty() == difficulty) { // CraftBukkit
|
|
|
|
throw DifficultyCommand.ERROR_ALREADY_DIFFICULT.create(difficulty.getKey());
|
2021-06-11 14:02:28 +02:00
|
|
|
} else {
|
2022-03-01 06:43:03 +01:00
|
|
|
- worldServer.serverLevelData.setDifficulty(difficulty); // CraftBukkit
|
|
|
|
+ minecraftserver.setDifficulty(worldServer, difficulty, true); // Paper - don't skip other difficulty-changing logic (fix upstream's fix)
|
2023-06-08 01:20:26 +02:00
|
|
|
source.sendSuccess(() -> {
|
|
|
|
return Component.translatable("commands.difficulty.success", difficulty.getDisplayName());
|
|
|
|
}, true);
|
2021-06-11 14:02:28 +02:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
|
2023-08-28 13:05:48 +02:00
|
|
|
index fff1f35b783bea3c2ea43c5d403ff57d96c2bf86..8f7916aa522fa2a49197d59e63d6e5c3a2d4bf42 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
|
2023-08-28 13:05:48 +02:00
|
|
|
@@ -325,7 +325,7 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
|
2021-06-11 14:02:28 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void forceDifficulty() {
|
|
|
|
- this.setDifficulty(this.getProperties().difficulty, true);
|
2022-06-08 07:02:19 +02:00
|
|
|
+ // this.setDifficulty(this.getProperties().difficulty, true); // Paper - Don't overwrite level.dat's difficulty, keep current
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-12-05 20:44:17 +01:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
2023-08-06 02:21:59 +02:00
|
|
|
index 15a70bad66eb2508f58ff184061c2d19e45297e1..f80645fe0e1f9ad2a70ea33c5dc6a8c02ff262ec 100644
|
2021-12-05 20:44:17 +01:00
|
|
|
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
2023-06-08 07:21:04 +02:00
|
|
|
@@ -1203,7 +1203,7 @@ public class ServerPlayer extends Player {
|
2021-12-05 20:44:17 +01:00
|
|
|
this.isChangingDimension = true; // CraftBukkit - Set teleport invulnerability only if player changing worlds
|
|
|
|
|
2023-06-08 01:20:26 +02:00
|
|
|
this.connection.send(new ClientboundRespawnPacket(worldserver.dimensionTypeId(), worldserver.dimension(), BiomeManager.obfuscateSeed(worldserver.getSeed()), this.gameMode.getGameModeForPlayer(), this.gameMode.getPreviousGameModeForPlayer(), worldserver.isDebug(), worldserver.isFlat(), (byte) 3, this.getLastDeathLocation(), this.getPortalCooldown()));
|
|
|
|
- this.connection.send(new ClientboundChangeDifficultyPacket(this.level().getDifficulty(), this.level().getLevelData().isDifficultyLocked()));
|
|
|
|
+ this.connection.send(new ClientboundChangeDifficultyPacket(worldserver.getDifficulty(), this.level().getLevelData().isDifficultyLocked())); // Paper - fix difficulty sync issue
|
2021-12-05 20:44:17 +01:00
|
|
|
PlayerList playerlist = this.server.getPlayerList();
|
|
|
|
|
|
|
|
playerlist.sendPlayerPermissionLevel(this);
|
2021-06-11 14:02:28 +02:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
2023-08-28 13:05:48 +02:00
|
|
|
index 61053ccdcf5e588164f243faa9ef6beda5bf45fc..2f0fb75a35a1fa45614621da9e24cec6e842b693 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
2023-08-16 09:58:07 +02:00
|
|
|
@@ -3382,7 +3382,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
|
2021-06-11 14:02:28 +02:00
|
|
|
public void handleChangeDifficulty(ServerboundChangeDifficultyPacket packet) {
|
2023-06-08 01:20:26 +02:00
|
|
|
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
|
2021-06-11 14:02:28 +02:00
|
|
|
if (this.player.hasPermissions(2) || this.isSingleplayerOwner()) {
|
|
|
|
- this.server.setDifficulty(packet.getDifficulty(), false);
|
2022-06-08 07:02:19 +02:00
|
|
|
+ // this.server.setDifficulty(packet.getDifficulty(), false); // Paper - don't allow clients to change this
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-01 02:46:37 +02:00
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
2023-08-06 02:21:59 +02:00
|
|
|
index 6134dfb1b64c8ab88053f62aea5341ead2563db7..a910974f8e6f6f5a4cc63d8060a62ac21dfe0d01 100644
|
2021-10-01 02:46:37 +02:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
2023-08-06 02:21:59 +02:00
|
|
|
@@ -975,8 +975,8 @@ public final class CraftServer implements Server {
|
2021-10-01 02:46:37 +02:00
|
|
|
org.spigotmc.SpigotConfig.init((File) console.options.valueOf("spigot-settings")); // Spigot
|
2022-06-09 10:51:45 +02:00
|
|
|
this.console.paperConfigurations.reloadConfigs(this.console);
|
2021-10-01 02:46:37 +02:00
|
|
|
for (ServerLevel world : this.console.getAllLevels()) {
|
|
|
|
- world.serverLevelData.setDifficulty(config.difficulty);
|
|
|
|
- world.setSpawnSettings(config.spawnMonsters, config.spawnAnimals);
|
|
|
|
+ // world.serverLevelData.setDifficulty(config.difficulty); // Paper - per level difficulty
|
|
|
|
+ world.setSpawnSettings(world.serverLevelData.getDifficulty() != Difficulty.PEACEFUL && config.spawnMonsters, config.spawnAnimals); // Paper - per level difficulty (from MinecraftServer#setDifficulty(ServerLevel, Difficulty, boolean))
|
2022-02-12 14:20:33 +01:00
|
|
|
|
|
|
|
for (SpawnCategory spawnCategory : SpawnCategory.values()) {
|
|
|
|
if (CraftSpawnCategory.isValidForLimits(spawnCategory)) {
|
2022-11-01 19:29:52 +01:00
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
2023-07-04 10:22:56 +02:00
|
|
|
index b34067a6bc3bf61ca94929bb8e9677deef686077..eb7a3a89ad7174e57d8ce98a67725c0d329b5d88 100644
|
2022-11-01 19:29:52 +01:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
2023-06-13 01:51:45 +02:00
|
|
|
@@ -1150,7 +1150,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
2022-11-01 19:29:52 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setDifficulty(Difficulty difficulty) {
|
|
|
|
- this.getHandle().serverLevelData.setDifficulty(net.minecraft.world.Difficulty.byId(difficulty.getValue()));
|
|
|
|
+ this.getHandle().getServer().setDifficulty(this.getHandle(), net.minecraft.world.Difficulty.byId(difficulty.getValue()), true); // Paper - don't skip other difficulty-changing logic
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|