diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java index 1a0c95d9d..6f27e1b10 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java @@ -779,8 +779,11 @@ 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)) { + if (PaperLib.isPaper() && "CUSTOM".equals(entity.getEntitySpawnReason().name())) { + continue; + } + // Fallback for Spigot not having Entity#getEntitySpawnReason + if (entity.getMetadata("ps_custom_spawned").stream().anyMatch(MetadataValue::asBoolean)) { continue; } switch (entity.getType().toString()) { diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/EntityEventListener.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/EntityEventListener.java index 6a147185f..92ecc7fec 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/EntityEventListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/EntityEventListener.java @@ -19,6 +19,7 @@ package com.plotsquared.bukkit.listener; import com.google.inject.Inject; +import com.plotsquared.bukkit.BukkitPlatform; import com.plotsquared.bukkit.player.BukkitPlayer; import com.plotsquared.bukkit.util.BukkitEntityUtil; import com.plotsquared.bukkit.util.BukkitUtil; @@ -41,6 +42,7 @@ import com.plotsquared.core.util.EventDispatcher; import com.plotsquared.core.util.PlotFlagUtil; import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.world.block.BlockType; +import io.papermc.lib.PaperLib; import org.bukkit.Material; import org.bukkit.Particle; import org.bukkit.World; @@ -78,15 +80,18 @@ import java.util.List; @SuppressWarnings("unused") public class EntityEventListener implements Listener { + private final BukkitPlatform platform; private final PlotAreaManager plotAreaManager; private final EventDispatcher eventDispatcher; private float lastRadius; @Inject public EntityEventListener( + final @NonNull BukkitPlatform platform, final @NonNull PlotAreaManager plotAreaManager, final @NonNull EventDispatcher eventDispatcher ) { + this.platform = platform; this.plotAreaManager = plotAreaManager; this.eventDispatcher = eventDispatcher; } @@ -170,7 +175,18 @@ public class EntityEventListener implements Listener { return; } } - case "BUILD_IRONGOLEM", "BUILD_SNOWMAN", "BUILD_WITHER", "CUSTOM" -> { + case "CUSTOM" -> { + if (!area.isSpawnCustom()) { + event.setCancelled(true); + return; + } + // No need to clutter metadata if running paper + if (!PaperLib.isPaper()) { + entity.setMetadata("ps_custom_spawned", new FixedMetadataValue(this.platform, true)); + } + return; // Don't cancel if mob spawning is disabled + } + case "BUILD_IRONGOLEM", "BUILD_SNOWMAN", "BUILD_WITHER" -> { if (!area.isSpawnCustom()) { event.setCancelled(true); return; 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 de0b6ec37..fc2f3a275 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/EntitySpawnListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/EntitySpawnListener.java @@ -123,8 +123,10 @@ public class EntitySpawnListener implements Listener { if (!location.isPlotArea() || area == null) { return; } - if (area.isSpawnCustom() && "CUSTOM".equals(entity.getEntitySpawnReason().name())) { - return; + if (PaperLib.isPaper()) { + if (area.isSpawnCustom() && "CUSTOM".equals(entity.getEntitySpawnReason().name())) { + return; + } } Plot plot = location.getOwnedPlotAbs(); EntityType type = entity.getType();