2020-06-28 08:01:01 +00: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
|
2021-03-16 07:19:45 +00:00
|
|
|
index b1a05896c50787657421e4cf721b9100bb38706d..31a083730536177c5ff5ae463ca0b9780968a5d8 100644
|
2020-06-28 08:01:01 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
|
2021-03-16 07:19:45 +00:00
|
|
|
@@ -1633,11 +1633,15 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
|
2020-11-03 02:22:15 +00:00
|
|
|
}
|
2020-06-28 08:01:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- public void a(EnumDifficulty enumdifficulty, boolean flag) {
|
2021-03-07 08:37:05 +00:00
|
|
|
- if (flag || !this.saveData.isDifficultyLocked()) {
|
|
|
|
- this.saveData.setDifficulty(this.saveData.isHardcore() ? EnumDifficulty.HARD : enumdifficulty);
|
|
|
|
- this.updateSpawnFlags();
|
|
|
|
- this.getPlayerList().getPlayers().forEach(this::b);
|
2020-06-28 08:01:01 +00:00
|
|
|
+ // Paper start - fix per world difficulty
|
2021-03-07 08:37:05 +00:00
|
|
|
+ public void setWorldDifficulty(WorldServer world, EnumDifficulty enumdifficulty, boolean forcefullySet) { this.a(world, enumdifficulty, forcefullySet); }
|
2020-06-28 08:01:01 +00:00
|
|
|
+ public void a(WorldServer world, EnumDifficulty enumdifficulty, boolean flag) {
|
|
|
|
+ WorldDataServer worldData = world.worldDataServer;
|
2021-03-07 08:37:05 +00:00
|
|
|
+ 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
|
2020-06-28 08:01:01 +00:00
|
|
|
+ // Paper end
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-16 07:19:45 +00:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/commands/CommandDifficulty.java b/src/main/java/net/minecraft/server/commands/CommandDifficulty.java
|
|
|
|
index 1773fa44f55c6f6dcda0afceff4db39881861879..21125087e9a81dee994cbec7ee7ad41447772a32 100644
|
|
|
|
--- a/src/main/java/net/minecraft/server/commands/CommandDifficulty.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/commands/CommandDifficulty.java
|
|
|
|
@@ -41,10 +41,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 a28441952e57e92a24a2933feb9188b13f15af2f..95f4d39f3c21933f440f8ee3e29fd8a533dfb4c1 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 {
|
2020-06-28 08:01:01 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|