Mirror von
https://github.com/PaperMC/Paper.git
synchronisiert 2024-11-15 04:20:04 +01:00
132 Zeilen
9.3 KiB
Diff
132 Zeilen
9.3 KiB
Diff
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
|
|
index 9829f86520c4028a94f239fb4804fb0f2a2ac6fa..229f5c1d651d903e1c641e67661004a4ee010417 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<TickTa
|
|
if (worldserver.getWorld().getKeepSpawnInMemory()) worldloadlistener.stop(); // Paper - Configurable Keep Spawn Loaded range per world
|
|
// CraftBukkit start
|
|
// this.updateMobSpawningFlags();
|
|
- 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
|
|
@@ -1814,11 +1814,14 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
|
}
|
|
}
|
|
|
|
- public void setDifficulty(Difficulty difficulty, boolean forceUpdate) {
|
|
- if (forceUpdate || !this.worldData.isDifficultyLocked()) {
|
|
- this.worldData.setDifficulty(this.worldData.isHardcore() ? Difficulty.HARD : difficulty);
|
|
- this.updateMobSpawningFlags();
|
|
- this.getPlayerList().getPlayers().forEach(this::sendDifficultyUpdate);
|
|
+ // Paper start - 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);
|
|
+ // Paper end - per level difficulty
|
|
}
|
|
}
|
|
|
|
@@ -1832,7 +1835,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
|
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))
|
|
}
|
|
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/server/commands/DifficultyCommand.java b/src/main/java/net/minecraft/server/commands/DifficultyCommand.java
|
|
index 997a96a21440ae72696d68f8031ece4ba487d3ef..3d8584929cee000ae7df10c5bd94f35820e70294 100644
|
|
--- a/src/main/java/net/minecraft/server/commands/DifficultyCommand.java
|
|
+++ b/src/main/java/net/minecraft/server/commands/DifficultyCommand.java
|
|
@@ -49,7 +49,7 @@ public class DifficultyCommand {
|
|
if (worldServer.getDifficulty() == difficulty) { // CraftBukkit
|
|
throw DifficultyCommand.ERROR_ALREADY_DIFFICULT.create(difficulty.getKey());
|
|
} else {
|
|
- worldServer.serverLevelData.setDifficulty(difficulty); // CraftBukkit
|
|
+ minecraftserver.setDifficulty(worldServer, difficulty, true); // Paper - per level difficulty; don't skip other difficulty-changing logic (fix upstream's fix)
|
|
source.sendSuccess(() -> {
|
|
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 ab84c4b098184370c8b63cbae687116a7b077cf5..09956f69b63844d67aeab1339ae65910fc8eb8bf 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 c87e5dd12b5931f9d06bd70a3dd591882a5c1f17..241c16b8df5128f2c88ed2f9e9c51d7f7b8420b4 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 56a664d7810e4c4b0f85d714e2b89014bb460fac..75073ab08a90bd0ce8afc54634e7d61d50650742 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 9896ea05523f6fb75213c861c9cf3962976cce88..85bc6dbfe71d841b4ed1ed912d3fe19d994a17f0 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
|