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-09-12 21:57:21 +02:00
|
|
|
index 03b38e2c53376db25864a0c6f00f786c4dae215d..f55dc28f3e220966199ec718a437e50ef4b76027 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-09-12 21:57:21 +02:00
|
|
|
@@ -321,7 +321,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
|
2020-09-11 01:47:58 +02:00
|
|
|
index fa64622f78399b934b9246b03d747ad0997354a9..474b1a3d4e09489d18a9b2b07131af3d2599ab52 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
|
2020-08-25 04:22:08 +02:00
|
|
|
@@ -1518,11 +1518,14 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
|
2020-06-28 10:01:01 +02:00
|
|
|
this.H = keypair;
|
|
|
|
}
|
|
|
|
|
|
|
|
- public void a(EnumDifficulty enumdifficulty, boolean flag) {
|
|
|
|
- if (flag || !this.saveData.isDifficultyLocked()) {
|
|
|
|
- this.saveData.setDifficulty(this.saveData.isHardcore() ? EnumDifficulty.HARD : enumdifficulty);
|
2020-08-25 04:22:08 +02:00
|
|
|
- this.bb();
|
2020-06-28 10:01:01 +02:00
|
|
|
- this.getPlayerList().getPlayers().forEach(this::a);
|
|
|
|
+ // Paper start - fix per world difficulty
|
|
|
|
+ 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());
|
|
|
|
+ //world.players.forEach(this::a);
|
|
|
|
+ // Paper end
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/PlayerConnection.java b/src/main/java/net/minecraft/server/PlayerConnection.java
|
2020-09-12 21:57:21 +02:00
|
|
|
index 5b7f6f5504be294e4d5ff5a891644c8b45222ae2..c5f9d472d631e54c61e886e9b5915640ed4dcdba 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
|
2020-09-03 22:52:21 +02:00
|
|
|
@@ -2779,7 +2779,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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|