From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Aikar 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 index 72dd2986c366a7840116b2426c4e2e6b807d0cfa..77f6b636c8e9935e51d54a47c0ac7a171aab2e60 100644 --- a/src/main/java/net/minecraft/server/MinecraftServer.java +++ b/src/main/java/net/minecraft/server/MinecraftServer.java @@ -828,7 +828,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop { return Component.translatable("commands.difficulty.success", difficulty.getDisplayName()); }, true); diff --git a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java index 684e9e9d78f0d410176fa8b9c9d0fbfda6a156dc..6c009f7443eabce73ace587a9fc686c320f707a7 100644 --- a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java +++ b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java @@ -325,7 +325,7 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface @Override public void forceDifficulty() { - this.setDifficulty(this.getProperties().difficulty, true); + // this.setDifficulty(this.getProperties().difficulty, true); // Paper - per level difficulty; Don't overwrite level.dat's difficulty, keep current } @Override diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java index b48a663d73ded1633f85819b3c754cf6b60064e3..65b3a2c9acd0d2f1b990d9059ed319bc50d899b9 100644 --- a/src/main/java/net/minecraft/server/level/ServerPlayer.java +++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java @@ -1209,7 +1209,7 @@ public class ServerPlayer extends Player { this.isChangingDimension = true; // CraftBukkit - Set teleport invulnerability only if player changing worlds this.connection.send(new ClientboundRespawnPacket(this.createCommonSpawnInfo(worldserver), (byte) 3)); - this.connection.send(new ClientboundChangeDifficultyPacket(this.level().getDifficulty(), this.level().getLevelData().isDifficultyLocked())); + this.connection.send(new ClientboundChangeDifficultyPacket(worldserver.getDifficulty(), this.level().getLevelData().isDifficultyLocked())); // Paper - per level difficulty PlayerList playerlist = this.server.getPlayerList(); playerlist.sendPlayerPermissionLevel(this); diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java index 1f8818dd98b8d9b5eb278b5a0f3ea36971c641fa..c8a56234a4f2e0c045e7ba6cec9eb8127f03255f 100644 --- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java +++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java @@ -3176,7 +3176,7 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl public void handleChangeDifficulty(ServerboundChangeDifficultyPacket packet) { PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel()); if (this.player.hasPermissions(2) || this.isSingleplayerOwner()) { - this.server.setDifficulty(packet.getDifficulty(), false); + // this.server.setDifficulty(packet.getDifficulty(), false); // Paper - per level difficulty; don't allow clients to change this } } diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java index c2cafdacde4edef8674b96fd8614a47b6af4b64b..71da3ebf372b63119fadbe2412aa02dce61086b4 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java @@ -955,8 +955,8 @@ public final class CraftServer implements Server { org.spigotmc.SpigotConfig.init((File) this.console.options.valueOf("spigot-settings")); // Spigot this.console.paperConfigurations.reloadConfigs(this.console); 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)) for (SpawnCategory spawnCategory : SpawnCategory.values()) { if (CraftSpawnCategory.isValidForLimits(spawnCategory)) { diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java index 729c3c273e2393674f30af1cfb0ab0dcf0fb3e20..c74d14e6a78b103fe2bffa8d69b5e7e20215781c 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java @@ -1158,7 +1158,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 - per level difficulty; don't skip other difficulty-changing logic } @Override