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
|
2022-11-01 19:29:52 +01:00
|
|
|
index fb2d02ad6f6a4a1c69dde06e7e193aaef8655028..dda33bd52d9c527c37f67b829010c27dba4b667a 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
|
2022-07-27 22:46:05 +02:00
|
|
|
@@ -791,7 +791,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
2022-06-09 10:51:45 +02:00
|
|
|
chunkproviderserver.getLightEngine().setTaskPerBatch(worldserver.paperConfig().misc.lightQueueSize); // Paper - increase light queue size
|
2021-10-01 02:46:37 +02:00
|
|
|
// CraftBukkit start
|
2021-11-24 13:30:55 +01:00
|
|
|
// this.updateMobSpawningFlags();
|
2021-10-01 02:46:37 +02:00
|
|
|
- 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
|
2022-09-26 10:02:51 +02:00
|
|
|
@@ -1704,11 +1704,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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-26 10:02:51 +02:00
|
|
|
@@ -1722,7 +1725,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
|
2022-06-08 07:02:19 +02:00
|
|
|
index 4bb29f86538552bb62125cc61210fd77b1ec671d..817193ca5fc15134d2985187bc2226ccbb4f0108 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
|
2022-03-01 06:43:03 +01:00
|
|
|
@@ -47,7 +47,7 @@ public class DifficultyCommand {
|
|
|
|
if (worldServer.getDifficulty() == difficulty) { // CraftBukkit
|
|
|
|
throw DifficultyCommand.ERROR_ALREADY_DIFFICULT.create(difficulty.getKey());
|
2021-06-11 14:02:28 +02:00
|
|
|
} else {
|
2022-03-01 06:43:03 +01:00
|
|
|
- worldServer.serverLevelData.setDifficulty(difficulty); // CraftBukkit
|
|
|
|
+ minecraftserver.setDifficulty(worldServer, difficulty, true); // Paper - don't skip other difficulty-changing logic (fix upstream's fix)
|
2022-06-08 07:02:19 +02:00
|
|
|
source.sendSuccess(Component.translatable("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
|
2022-11-01 19:29:52 +01:00
|
|
|
index e3a62579067209c447f2fdcb76b2a11e489a376b..a8e18a168e8288ebea95bacd61a38039b3427d5e 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
|
2022-06-09 23:43:27 +02:00
|
|
|
@@ -332,7 +332,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);
|
2022-06-08 07:02:19 +02:00
|
|
|
+ // this.setDifficulty(this.getProperties().difficulty, true); // Paper - Don't overwrite level.dat's difficulty, keep current
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-12-05 20:44:17 +01:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
2022-11-01 19:29:52 +01:00
|
|
|
index 83d05b2546fe54485daede323a0f6343b62d278a..d8c77533a44e316693535ea66fe6ae7f4994de5f 100644
|
2021-12-05 20:44:17 +01:00
|
|
|
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
2022-09-26 10:02:51 +02:00
|
|
|
@@ -1129,7 +1129,7 @@ public class ServerPlayer extends Player {
|
2021-12-05 20:44:17 +01:00
|
|
|
this.isChangingDimension = true; // CraftBukkit - Set teleport invulnerability only if player changing worlds
|
|
|
|
|
2022-06-08 07:02:19 +02:00
|
|
|
this.connection.send(new ClientboundRespawnPacket(worldserver.dimensionTypeId(), worldserver.dimension(), BiomeManager.obfuscateSeed(worldserver.getSeed()), this.gameMode.getGameModeForPlayer(), this.gameMode.getPreviousGameModeForPlayer(), worldserver.isDebug(), worldserver.isFlat(), true, this.getLastDeathLocation()));
|
2021-12-05 20:44:17 +01:00
|
|
|
- this.connection.send(new ClientboundChangeDifficultyPacket(this.level.getDifficulty(), this.level.getLevelData().isDifficultyLocked()));
|
2022-03-01 06:43:03 +01:00
|
|
|
+ this.connection.send(new ClientboundChangeDifficultyPacket(worldserver.getDifficulty(), this.level.getLevelData().isDifficultyLocked())); // Paper - fix difficulty sync issue
|
2021-12-05 20:44:17 +01:00
|
|
|
PlayerList playerlist = this.server.getPlayerList();
|
|
|
|
|
|
|
|
playerlist.sendPlayerPermissionLevel(this);
|
2021-06-11 14:02:28 +02:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
2022-09-12 13:31:45 +02:00
|
|
|
index 02b6cf65f6abedfd4933e4e64d254f190e061301..c59e90ba0de83eeda3719b6303bee9796b4a1af0 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
|
2022-09-12 13:31:45 +02:00
|
|
|
@@ -3498,7 +3498,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
|
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);
|
2022-06-08 07:02:19 +02:00
|
|
|
+ // this.server.setDifficulty(packet.getDifficulty(), false); // Paper - don't allow clients to change this
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
2022-11-01 19:29:52 +01:00
|
|
|
index e8e31ddaa7fa87b9854961dd44abff9ddb6a6142..4c6c9aa8b3305f5ab4f7b8d356e860da169fb1db 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
|
2022-08-09 09:18:08 +02:00
|
|
|
@@ -951,8 +951,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
|
2022-06-09 10:51:45 +02:00
|
|
|
this.console.paperConfigurations.reloadConfigs(this.console);
|
2021-10-01 02:46:37 +02:00
|
|
|
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))
|
2022-02-12 14:20:33 +01:00
|
|
|
|
|
|
|
for (SpawnCategory spawnCategory : SpawnCategory.values()) {
|
|
|
|
if (CraftSpawnCategory.isValidForLimits(spawnCategory)) {
|
2022-11-01 19:29:52 +01:00
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
|
|
|
index c3703933598ee96d856a18dcc0932061959c9791..298012beaf6f587a05d230b7208325ea8c3ad811 100644
|
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
|
|
|
@@ -1147,7 +1147,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setDifficulty(Difficulty difficulty) {
|
|
|
|
- this.getHandle().serverLevelData.setDifficulty(net.minecraft.world.Difficulty.byId(difficulty.getValue()));
|
|
|
|
+ this.getHandle().getServer().setDifficulty(this.getHandle(), net.minecraft.world.Difficulty.byId(difficulty.getValue()), true); // Paper - don't skip other difficulty-changing logic
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|