From fccc146053812ebb1db2db142fe646882754e21d Mon Sep 17 00:00:00 2001 From: Nico Lube <32245510+nicolube@users.noreply.github.com> Date: Sun, 21 Jan 2024 12:33:53 +0100 Subject: [PATCH] Do not remove entitys with CUSTOM spawn-reason on CreatureSpawnEvent. (#4297) Do not remove entitys with CUSTOM spawn-reason. --- .../main/java/com/plotsquared/bukkit/BukkitPlatform.java | 7 +++++-- .../plotsquared/bukkit/listener/EntitySpawnListener.java | 5 ++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java index ad332176e..1a0c95d9d 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java @@ -779,6 +779,10 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl Iterator iterator = entities.iterator(); while (iterator.hasNext()) { Entity entity = iterator.next(); + final String spawnReason = entity.getEntitySpawnReason().name(); + if ("CUSTOM".equals(spawnReason)) { + continue; + } switch (entity.getType().toString()) { case "EGG": case "FISHING_HOOK": @@ -867,8 +871,7 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl if (livingEntity.isLeashed() && !Settings.Enabled_Components.KILL_OWNED_ROAD_MOBS) { continue; } - List keep = entity.getMetadata("keep"); - if (!keep.isEmpty()) { + if (entity.hasMetadata("keep")) { continue; } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/EntitySpawnListener.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/EntitySpawnListener.java index 841f52970..de0b6ec37 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/EntitySpawnListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/EntitySpawnListener.java @@ -120,7 +120,10 @@ public class EntitySpawnListener implements Listener { Entity entity = event.getEntity(); Location location = BukkitUtil.adapt(entity.getLocation()); PlotArea area = location.getPlotArea(); - if (!location.isPlotArea()) { + if (!location.isPlotArea() || area == null) { + return; + } + if (area.isSpawnCustom() && "CUSTOM".equals(entity.getEntitySpawnReason().name())) { return; } Plot plot = location.getOwnedPlotAbs();