Paper/Spigot-Server-Patches/0510-Fix-Per-World-Difficulty-Remembering-Difficulty.patch
Aikar a08be1ec7c
[Auto] Updated Upstream (CraftBukkit)
Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing

CraftBukkit Changes:
9294ebbf0 SPIGOT-5877: Add support for Vanilla custom dimensions
2021-04-15 20:47:34 -04:00

87 Zeilen
5.3 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 7ee8074a356df5db227bca78a545d14c5e8794e8..2c66ea1bda456da10d70ed180547bf73b7942f8b 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -1645,11 +1645,15 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
}
}
- public void a(EnumDifficulty enumdifficulty, boolean flag) {
- if (flag || !this.saveData.isDifficultyLocked()) {
- this.saveData.setDifficulty(this.saveData.isHardcore() ? EnumDifficulty.HARD : enumdifficulty);
- this.updateSpawnFlags();
- this.getPlayerList().getPlayers().forEach(this::b);
+ // Paper start - fix per world difficulty
+ public void setWorldDifficulty(WorldServer world, EnumDifficulty enumdifficulty, boolean forcefullySet) { this.a(world, enumdifficulty, forcefullySet); }
+ public void a(WorldServer world, EnumDifficulty enumdifficulty, boolean flag) {
+ WorldDataServer worldData = world.worldDataServer;
+ if (flag || !worldData.isDifficultyLocked()) {
+ worldData.setDifficulty(worldData.isHardcore() ? EnumDifficulty.HARD : enumdifficulty);
+ world.setSpawnFlags(worldData.getDifficulty() != EnumDifficulty.PEACEFUL && ((DedicatedServer) this).propertyManager.getProperties().spawnMonsters, this.getSpawnAnimals());
+ //this.getPlayerList().getPlayers().forEach(this::b); // Commented: WorldDataServer#setDifficulty handles updating players' difficulties
+ // Paper end
}
}
diff --git a/src/main/java/net/minecraft/server/commands/CommandDifficulty.java b/src/main/java/net/minecraft/server/commands/CommandDifficulty.java
index 1773fa44f55c6f6dcda0afceff4db39881861879..4a43b4632a5cb1e3b5659c9c6c44b42d33bbfcd4 100644
--- a/src/main/java/net/minecraft/server/commands/CommandDifficulty.java
+++ b/src/main/java/net/minecraft/server/commands/CommandDifficulty.java
@@ -7,6 +7,7 @@ import com.mojang.brigadier.exceptions.DynamicCommandExceptionType;
import net.minecraft.commands.CommandListenerWrapper;
import net.minecraft.network.chat.ChatMessage;
import net.minecraft.server.MinecraftServer;
+import net.minecraft.server.level.WorldServer;
import net.minecraft.world.EnumDifficulty;
public class CommandDifficulty {
@@ -41,10 +42,11 @@ public class CommandDifficulty {
public static int a(CommandListenerWrapper commandlistenerwrapper, EnumDifficulty enumdifficulty) throws CommandSyntaxException {
MinecraftServer minecraftserver = commandlistenerwrapper.getServer();
- if (minecraftserver.getSaveData().getDifficulty() == enumdifficulty) {
+ WorldServer world = commandlistenerwrapper.getWorld(); // Paper
+ if (world.worldDataServer.getDifficulty() == enumdifficulty) { // Paper
throw CommandDifficulty.a.create(enumdifficulty.c());
} else {
- minecraftserver.a(enumdifficulty, true);
+ minecraftserver.a(world, enumdifficulty, true); // Paper
commandlistenerwrapper.sendMessage(new ChatMessage("commands.difficulty.success", new Object[]{enumdifficulty.b()}), 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 ec1f36736d79d4054ad7ff4da4e3659f35c811d6..c4df472050622eb2469b2ddb4d2ed917994f6e95 100644
--- a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
+++ b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
@@ -362,7 +362,7 @@ public class DedicatedServer extends MinecraftServer implements IMinecraftServer
@Override
public void updateWorldSettings() {
- this.a(this.getDedicatedServerProperties().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/PlayerConnection.java b/src/main/java/net/minecraft/server/network/PlayerConnection.java
index 1b399bcd366f66d6b5e0d54e3a5e34f9e96f5a41..dc3f874b2a19d2d2c3890b7e1125cd1ec14cf673 100644
--- a/src/main/java/net/minecraft/server/network/PlayerConnection.java
+++ b/src/main/java/net/minecraft/server/network/PlayerConnection.java
@@ -3027,7 +3027,7 @@ public class PlayerConnection implements PacketListenerPlayIn {
public void a(PacketPlayInDifficultyChange packetplayindifficultychange) {
PlayerConnectionUtils.ensureMainThread(packetplayindifficultychange, this, this.player.getWorldServer());
if (this.player.k(2) || this.isExemptPlayer()) {
- this.minecraftServer.a(packetplayindifficultychange.b(), false);
+ //this.minecraftServer.a(packetplayindifficultychange.b(), false); // Paper - don't allow clients to change this
}
}