3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-11-15 12:30:06 +01:00
Paper/Spigot-Server-Patches/0197-PlayerNaturallySpawnCreaturesEvent.patch

45 Zeilen
2.2 KiB
Diff

From a0a096827f8afc67e10dcbb7b0db1cf71c8b0590 Mon Sep 17 00:00:00 2001
2019-04-28 19:59:47 +02:00
From: Aikar <aikar@aikar.co>
Date: Sun, 14 Jan 2018 17:36:02 -0500
Subject: [PATCH] PlayerNaturallySpawnCreaturesEvent
This event can be used for when you want to exclude a certain player
from triggering monster spawns on a server.
Also a highly more effecient way to blanket block spawns in a world
diff --git a/src/main/java/net/minecraft/server/PlayerChunkMap.java b/src/main/java/net/minecraft/server/PlayerChunkMap.java
index 6960e46ec6..1212f3f67d 100644
2019-04-28 19:59:47 +02:00
--- a/src/main/java/net/minecraft/server/PlayerChunkMap.java
+++ b/src/main/java/net/minecraft/server/PlayerChunkMap.java
@@ -755,12 +755,24 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d {
2019-04-28 19:59:47 +02:00
chunkRange = (chunkRange > world.spigotConfig.viewDistance) ? (byte) world.spigotConfig.viewDistance : chunkRange;
chunkRange = (chunkRange > 8) ? 8 : chunkRange;
- double blockRange = (reducedRange) ? Math.pow(chunkRange << 4, 2) : 16384.0D;
2019-04-28 19:59:47 +02:00
+ final int finalChunkRange = chunkRange; // Paper for lambda below
+ //double blockRange = (reducedRange) ? Math.pow(chunkRange << 4, 2) : 16384.0D; // Paper - use from event
2019-04-28 19:59:47 +02:00
// Spigot end
long i = chunkcoordintpair.pair();
2019-04-28 19:59:47 +02:00
return !this.u.d(i) ? true : this.playerMap.a(i).noneMatch((entityplayer) -> {
- return !entityplayer.isSpectator() && a(chunkcoordintpair, (Entity) entityplayer) < blockRange; // Spigot
2019-04-28 19:59:47 +02:00
+ // Paper start -
2019-06-06 07:13:00 +02:00
+ com.destroystokyo.paper.event.entity.PlayerNaturallySpawnCreaturesEvent event;
+ double blockRange = 16384.0D;
+ if (reducedRange) {
+ event = new com.destroystokyo.paper.event.entity.PlayerNaturallySpawnCreaturesEvent(entityplayer.getBukkitEntity(), (byte) finalChunkRange);
+ event.callEvent();
2019-06-06 07:13:00 +02:00
+ blockRange = (double) ((event.getSpawnRadius() << 4) * (event.getSpawnRadius() << 4));
+ if (event.isCancelled()) return true;
+ }
+
+ return (!entityplayer.isSpectator() && a(chunkcoordintpair, (Entity) entityplayer) < blockRange); // Spigot
2019-04-28 19:59:47 +02:00
+ // Paper end
});
}
2019-04-28 19:59:47 +02:00
--
2.22.0
2019-04-28 19:59:47 +02:00