2021-06-11 14:02:28 +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/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
|
2021-11-09 08:59:15 +01:00
|
|
|
index 4f630156a597f2b8ebe16856d0db2c1723e958cd..335d42592d99d91ae1d99fe1b99122a3bac97a49 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
|
2021-11-09 08:59:15 +01:00
|
|
|
@@ -857,7 +857,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
2021-10-01 02:46:37 +02:00
|
|
|
chunkproviderserver.getLightEngine().setTaskPerBatch(worldserver.paperConfig.lightQueueSize); // Paper - increase light queue size
|
|
|
|
// CraftBukkit start
|
|
|
|
// this.updateSpawnFlags();
|
|
|
|
- worldserver.setSpawnSettings(this.isSpawningMonsters(), this.isSpawningAnimals());
|
|
|
|
+ worldserver.setSpawnSettings(worldserver.serverLevelData.getDifficulty() != Difficulty.PEACEFUL && ((DedicatedServer) this).settings.getProperties().spawnMonsters, this.isSpawningAnimals()); // Paper - per level difficulty (from setDifficulty(ServerLevel, Difficulty, boolean))
|
|
|
|
|
|
|
|
this.forceTicks = false;
|
|
|
|
// CraftBukkit end
|
2021-11-09 08:59:15 +01:00
|
|
|
@@ -1727,11 +1727,14 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-14 10:37:14 +02:00
|
|
|
- public void setDifficulty(Difficulty difficulty, boolean forceUpdate) {
|
2021-06-11 14:02:28 +02:00
|
|
|
- if (forceUpdate || !this.worldData.isDifficultyLocked()) {
|
2021-06-14 10:37:14 +02:00
|
|
|
- this.worldData.setDifficulty(this.worldData.isHardcore() ? Difficulty.HARD : difficulty);
|
2021-06-11 14:02:28 +02:00
|
|
|
- this.updateMobSpawningFlags();
|
|
|
|
- this.getPlayerList().getPlayers().forEach(this::sendDifficultyUpdate);
|
2021-06-14 10:37:14 +02:00
|
|
|
+ // 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);
|
2021-06-11 14:02:28 +02:00
|
|
|
+ // Paper end
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-09 08:59:15 +01:00
|
|
|
@@ -1745,7 +1748,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
2021-10-01 02:46:37 +02:00
|
|
|
while (iterator.hasNext()) {
|
|
|
|
ServerLevel worldserver = (ServerLevel) iterator.next();
|
|
|
|
|
|
|
|
- worldserver.setSpawnSettings(this.isSpawningMonsters(), this.isSpawningAnimals());
|
|
|
|
+ worldserver.setSpawnSettings(worldserver.serverLevelData.getDifficulty() != Difficulty.PEACEFUL && ((DedicatedServer) this).settings.getProperties().spawnMonsters, this.isSpawningAnimals()); // Paper - per level difficulty (from setDifficulty(ServerLevel, Difficulty, boolean))
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2021-06-11 14:02:28 +02:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/commands/DifficultyCommand.java b/src/main/java/net/minecraft/server/commands/DifficultyCommand.java
|
2021-06-14 10:37:14 +02:00
|
|
|
index 33c859df0b669d0c3e97ccba29f17c1ba2166a27..9f03b738aea623fe409ca176397f48be055466da 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/commands/DifficultyCommand.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/commands/DifficultyCommand.java
|
2021-06-14 10:37:14 +02:00
|
|
|
@@ -35,10 +35,11 @@ public class DifficultyCommand {
|
2021-06-11 14:02:28 +02:00
|
|
|
|
|
|
|
public static int setDifficulty(CommandSourceStack source, Difficulty difficulty) throws CommandSyntaxException {
|
2021-06-14 10:37:14 +02:00
|
|
|
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());
|
2021-06-11 14:02:28 +02:00
|
|
|
} else {
|
2021-06-14 10:37:14 +02:00
|
|
|
- minecraftServer.setDifficulty(difficulty, true);
|
|
|
|
+ minecraftServer.setDifficulty(level, difficulty, true); // Paper - use world
|
|
|
|
source.sendSuccess(new TranslatableComponent("commands.difficulty.success", difficulty.getDisplayName()), true);
|
2021-06-11 14:02:28 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
|
2021-09-09 18:57:16 +02:00
|
|
|
index 8098875a5c4146dec81f5daed0e34ddfe17a26c6..286863b7eb9ee0389154304e61942dd68f978ff1 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
|
2021-09-09 18:57:16 +02:00
|
|
|
@@ -370,7 +370,7 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
|
2021-06-11 14:02:28 +02:00
|
|
|
|
|
|
|
@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
|
2021-09-11 19:27:48 +02:00
|
|
|
index 7bd2a88de8eaf9d72d9424a39d5df2600bed7e58..c0ae236619bbdf9293fbf1c4a1764a785d16a67b 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
2021-09-11 19:27:48 +02:00
|
|
|
@@ -3022,7 +3022,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
|
2021-06-11 14:02:28 +02:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-01 02:46:37 +02:00
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
2021-10-05 05:14:11 +02:00
|
|
|
index cb08173bdfe52c8a0d5de70f0421cabaa476647a..da9fc8a99576f13a52ab4830cb09b69b1e406fae 100644
|
2021-10-01 02:46:37 +02:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
2021-10-05 05:14:11 +02:00
|
|
|
@@ -880,8 +880,8 @@ public final class CraftServer implements Server {
|
2021-10-01 02:46:37 +02:00
|
|
|
org.spigotmc.SpigotConfig.init((File) console.options.valueOf("spigot-settings")); // Spigot
|
|
|
|
com.destroystokyo.paper.PaperConfig.init((File) console.options.valueOf("paper-settings")); // Paper
|
|
|
|
for (ServerLevel world : this.console.getAllLevels()) {
|
|
|
|
- world.serverLevelData.setDifficulty(config.difficulty);
|
|
|
|
- world.setSpawnSettings(config.spawnMonsters, config.spawnAnimals);
|
|
|
|
+ // world.serverLevelData.setDifficulty(config.difficulty); // Paper - per level difficulty
|
|
|
|
+ world.setSpawnSettings(world.serverLevelData.getDifficulty() != Difficulty.PEACEFUL && config.spawnMonsters, config.spawnAnimals); // Paper - per level difficulty (from MinecraftServer#setDifficulty(ServerLevel, Difficulty, boolean))
|
|
|
|
if (this.getTicksPerAnimalSpawns() < 0) {
|
|
|
|
world.ticksPerAnimalSpawns = 400;
|
|
|
|
} else {
|