Add WorldDifficultyChangeEvent (#12471)

This commit is contained in:
David
2025-07-26 23:38:16 +02:00
committed by GitHub
parent 57c13137e4
commit a57636189a
6 changed files with 96 additions and 9 deletions

View File

@@ -1112,7 +1112,7 @@
}
public KeyPair getKeyPair() {
@@ -1244,11 +_,14 @@
@@ -1244,11 +_,17 @@
}
}
@@ -1121,10 +1121,13 @@
- 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 forced) {
+ // Paper start - per level difficulty, WorldDifficultyChangeEvent
+ public void setDifficulty(ServerLevel level, Difficulty difficulty, @Nullable CommandSourceStack source, boolean forced) {
+ net.minecraft.world.level.storage.PrimaryLevelData worldData = level.serverLevelData;
+ if (forced || !worldData.isDifficultyLocked()) {
+ new io.papermc.paper.event.world.WorldDifficultyChangeEvent(
+ level.getWorld(), source, org.bukkit.craftbukkit.util.CraftDifficulty.toBukkit(difficulty)
+ ).callEvent();
+ worldData.setDifficulty(worldData.isHardcore() ? Difficulty.HARD : difficulty);
+ level.setSpawnSettings(worldData.getDifficulty() != Difficulty.PEACEFUL && ((net.minecraft.server.dedicated.DedicatedServer) this).settings.getProperties().spawnMonsters);
+ // this.getPlayerList().getPlayers().forEach(this::sendDifficultyUpdate);