From 6068eb129f880447c0f6d240a70024fa2b219b26 Mon Sep 17 00:00:00 2001 From: Aikar Date: Sun, 14 Jan 2018 17:36:24 -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 --- ...1-PlayerNaturallySpawnCreaturesEvent.patch | 80 +++++++++++++++++++ ...3-PlayerNaturallySpawnCreaturesEvent.patch | 33 ++++++++ 2 files changed, 113 insertions(+) create mode 100644 Spigot-API-Patches/0081-PlayerNaturallySpawnCreaturesEvent.patch create mode 100644 Spigot-Server-Patches/0263-PlayerNaturallySpawnCreaturesEvent.patch diff --git a/Spigot-API-Patches/0081-PlayerNaturallySpawnCreaturesEvent.patch b/Spigot-API-Patches/0081-PlayerNaturallySpawnCreaturesEvent.patch new file mode 100644 index 0000000000..6eb58e7385 --- /dev/null +++ b/Spigot-API-Patches/0081-PlayerNaturallySpawnCreaturesEvent.patch @@ -0,0 +1,80 @@ +From 3fcb573b25e7ea1c5ded854f96b6b6b39114c8de Mon Sep 17 00:00:00 2001 +From: Aikar +Date: Sun, 14 Jan 2018 17:31:37 -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/com/destroystokyo/paper/event/entity/PlayerNaturallySpawnCreaturesEvent.java b/src/main/java/com/destroystokyo/paper/event/entity/PlayerNaturallySpawnCreaturesEvent.java +new file mode 100644 +index 00000000..7c6953a7 +--- /dev/null ++++ b/src/main/java/com/destroystokyo/paper/event/entity/PlayerNaturallySpawnCreaturesEvent.java +@@ -0,0 +1,61 @@ ++package com.destroystokyo.paper.event.entity; ++ ++import org.bukkit.entity.Player; ++import org.bukkit.event.Cancellable; ++import org.bukkit.event.Event; ++import org.bukkit.event.HandlerList; ++import org.bukkit.event.player.PlayerEvent; ++ ++/** ++ * Fired when the server is calculating what chunks to try to spawn monsters in every Monster Spawn Tick event ++ */ ++public class PlayerNaturallySpawnCreaturesEvent extends PlayerEvent implements Cancellable { ++ private byte radius; ++ ++ public PlayerNaturallySpawnCreaturesEvent(Player player, byte radius) { ++ super(player); ++ this.radius = radius; ++ } ++ ++ /** ++ * @return The radius of chunks around this player to be included in natural spawn selection ++ */ ++ public byte getSpawnRadius() { ++ return radius; ++ } ++ ++ /** ++ * @param radius The radius of chunks around this player to be included in natural spawn selection ++ */ ++ public void setSpawnRadius(byte radius) { ++ this.radius = radius; ++ } ++ ++ private static final HandlerList handlers = new HandlerList(); ++ ++ public HandlerList getHandlers() { ++ return handlers; ++ } ++ ++ public static HandlerList getHandlerList() { ++ return handlers; ++ } ++ ++ private boolean cancelled = false; ++ ++ /** ++ * @return If this players chunks will be excluded from natural spawns ++ */ ++ @Override ++ public boolean isCancelled() { ++ return cancelled; ++ } ++ ++ /** ++ * @param cancel true if you wish to cancel this event, and not include this players chunks for natural spawning ++ */ ++ @Override ++ public void setCancelled(boolean cancel) { ++ cancelled = cancel; ++ } ++} +-- +2.15.1 + diff --git a/Spigot-Server-Patches/0263-PlayerNaturallySpawnCreaturesEvent.patch b/Spigot-Server-Patches/0263-PlayerNaturallySpawnCreaturesEvent.patch new file mode 100644 index 0000000000..9acf52b3ff --- /dev/null +++ b/Spigot-Server-Patches/0263-PlayerNaturallySpawnCreaturesEvent.patch @@ -0,0 +1,33 @@ +From 178935c622db79435acdabb55ac60b361b26a5a7 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/SpawnerCreature.java b/src/main/java/net/minecraft/server/SpawnerCreature.java +index 1137dda86..e205f591c 100644 +--- a/src/main/java/net/minecraft/server/SpawnerCreature.java ++++ b/src/main/java/net/minecraft/server/SpawnerCreature.java +@@ -72,6 +72,15 @@ public final class SpawnerCreature { + byte b0 = worldserver.spigotConfig.mobSpawnRange; + b0 = ( b0 > worldserver.spigotConfig.viewDistance ) ? (byte) worldserver.spigotConfig.viewDistance : b0; + b0 = ( b0 > 8 ) ? 8 : b0; ++ // Paper start ++ com.destroystokyo.paper.event.entity.PlayerNaturallySpawnCreaturesEvent event; ++ event = new com.destroystokyo.paper.event.entity.PlayerNaturallySpawnCreaturesEvent( ++ (org.bukkit.entity.Player) entityhuman.getBukkitEntity(), b0); ++ if (!event.callEvent()) { ++ continue; ++ } ++ b0 = event.getSpawnRadius(); ++ // Paperr end + + for (int i1 = -b0; i1 <= b0; ++i1) { + for (k = -b0; k <= b0; ++k) { +-- +2.15.1 +