Paper/patches/server/0469-Fix-Per-World-Difficulty-Remembering-Difficulty.patch
2021-06-17 01:37:27 -07:00

78 Zeilen
4.8 KiB
Diff

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
index 04531db7c26b9defe76d2584d960132ad79dc0fa..ccca42f9a1cd72e7f4fe21bd626b61f06c51e2e7 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -1721,11 +1721,14 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
}
}
- public void setDifficulty(Difficulty difficulty, boolean forceUpdate) {
- if (forceUpdate || !this.worldData.isDifficultyLocked()) {
- this.worldData.setDifficulty(this.worldData.isHardcore() ? Difficulty.HARD : difficulty);
- this.updateMobSpawningFlags();
- this.getPlayerList().getPlayers().forEach(this::sendDifficultyUpdate);
+ // 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);
+ // Paper end
}
}
diff --git a/src/main/java/net/minecraft/server/commands/DifficultyCommand.java b/src/main/java/net/minecraft/server/commands/DifficultyCommand.java
index 33c859df0b669d0c3e97ccba29f17c1ba2166a27..9f03b738aea623fe409ca176397f48be055466da 100644
--- a/src/main/java/net/minecraft/server/commands/DifficultyCommand.java
+++ b/src/main/java/net/minecraft/server/commands/DifficultyCommand.java
@@ -35,10 +35,11 @@ public class DifficultyCommand {
public static int setDifficulty(CommandSourceStack source, Difficulty difficulty) throws CommandSyntaxException {
MinecraftServer minecraftServer = source.getServer();
- if (minecraftServer.getWorldData().getDifficulty() == difficulty) {
+ net.minecraft.server.level.ServerLevel level = source.getLevel(); // Paper
+ if (level.serverLevelData.getDifficulty() == difficulty) { // Paper
throw ERROR_ALREADY_DIFFICULT.create(difficulty.getKey());
} else {
- minecraftServer.setDifficulty(difficulty, true);
+ minecraftServer.setDifficulty(level, difficulty, true); // Paper - use world
source.sendSuccess(new TranslatableComponent("commands.difficulty.success", difficulty.getDisplayName()), true);
return 0;
}
diff --git a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
index e5f7f043cbdb28d85b8aa0eea7cbaeb584e5fb85..a5c1114f9b323e8a49c84d0e68461e473bbcd690 100644
--- a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
+++ b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
@@ -367,7 +367,7 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
@Override
public void forceDifficulty() {
- this.setDifficulty(this.getProperties().difficulty, true);
+ //this.a(this.getDedicatedServerProperties().difficulty, true); // Paper - Don't overwrite level.dat's difficulty, keep current
}
@Override
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
index 56e93709ce955a7c65dc2b058b5b8b8a646d1775..fecb2a6b8674ca110d6af539396873e9dcdc0edb 100644
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -3041,7 +3041,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
public void handleChangeDifficulty(ServerboundChangeDifficultyPacket packet) {
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.getLevel());
if (this.player.hasPermissions(2) || this.isSingleplayerOwner()) {
- this.server.setDifficulty(packet.getDifficulty(), false);
+ //this.minecraftServer.a(packetplayindifficultychange.b(), false); // Paper - don't allow clients to change this
}
}