From 20180a0a3e12ef3b149a633e6d0018f83f0002bb Mon Sep 17 00:00:00 2001 From: Aikar 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 fba9f4b8a1..6c0a1eb413 100644 --- a/src/main/java/net/minecraft/server/PlayerChunkMap.java +++ b/src/main/java/net/minecraft/server/PlayerChunkMap.java @@ -764,11 +764,23 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d { 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; + final int finalChunkRange = chunkRange; // Paper for lambda below + //double blockRange = (reducedRange) ? Math.pow(chunkRange << 4, 2) : 16384.0D; // Paper - use from event // Spigot end return this.playerMap.a(chunkcoordintpair.pair()).noneMatch((entityplayer) -> { - return !entityplayer.isSpectator() && a(chunkcoordintpair, (Entity) entityplayer) < blockRange; // Spigot + // Paper start - + 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(); + blockRange = (double) ((event.getSpawnRadius() << 4) * (event.getSpawnRadius() << 4)); + if (event.isCancelled()) return true; + } + + return (!entityplayer.isSpectator() && a(chunkcoordintpair, (Entity) entityplayer) < blockRange); // Spigot + // Paper end }); } -- 2.21.0