2020-06-28 10:01:01 +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/CommandDifficulty.java b/src/main/java/net/minecraft/server/CommandDifficulty.java
|
|
|
|
index bc71070c670d1a64c60b9f19711a5e8a50ace56e..9efc743e028650ccc9cda5a2c9deb1836253b91d 100644
|
|
|
|
--- a/src/main/java/net/minecraft/server/CommandDifficulty.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/CommandDifficulty.java
|
|
|
|
@@ -36,10 +36,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/DedicatedServer.java b/src/main/java/net/minecraft/server/DedicatedServer.java
|
2020-11-03 03:22:15 +01:00
|
|
|
index f5792b999ce42acb13ae9a62ceb2ddec39abe209..5504facd2e453238caa71d98743be5416d4dd4fe 100644
|
2020-06-28 10:01:01 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/DedicatedServer.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/DedicatedServer.java
|
2020-11-03 03:22:15 +01:00
|
|
|
@@ -323,7 +323,7 @@ public class DedicatedServer extends MinecraftServer implements IMinecraftServer
|
2020-06-28 10:01:01 +02:00
|
|
|
|
|
|
|
@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/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
|
2021-03-09 00:12:31 +01:00
|
|
|
index 89de6c1a2463b2ea3aefb31c22e277fe707555a3..cfe770b7b77bb08407b164b932b898dfbe869b28 100644
|
2020-06-28 10:01:01 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
|
2021-03-09 00:12:31 +01:00
|
|
|
@@ -1526,11 +1526,15 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
|
2020-11-03 03:22:15 +01:00
|
|
|
}
|
2020-06-28 10:01:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- public void a(EnumDifficulty enumdifficulty, boolean flag) {
|
2021-03-07 09:37:05 +01: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 10:01:01 +02:00
|
|
|
+ // Paper start - fix per world difficulty
|
2021-03-07 09:37:05 +01:00
|
|
|
+ public void setWorldDifficulty(WorldServer world, EnumDifficulty enumdifficulty, boolean forcefullySet) { this.a(world, enumdifficulty, forcefullySet); }
|
2020-06-28 10:01:01 +02:00
|
|
|
+ public void a(WorldServer world, EnumDifficulty enumdifficulty, boolean flag) {
|
|
|
|
+ WorldDataServer worldData = world.worldDataServer;
|
2021-03-07 09:37:05 +01: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 10:01:01 +02:00
|
|
|
+ // Paper end
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/PlayerConnection.java b/src/main/java/net/minecraft/server/PlayerConnection.java
|
2021-03-07 09:37:05 +01:00
|
|
|
index 439b460216c90ff4e269240217d94e52d73d5132..61e6fc80fba8dbd0216ddcc25a5f287f7fad068d 100644
|
2020-06-28 10:01:01 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/PlayerConnection.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/PlayerConnection.java
|
2021-03-02 04:07:12 +01:00
|
|
|
@@ -2883,7 +2883,7 @@ public class PlayerConnection implements PacketListenerPlayIn {
|
2020-06-28 10:01:01 +02: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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|