From 84ec090df1b19a67d10204736867954cf842f0bc Mon Sep 17 00:00:00 2001 From: FlorianMichael Date: Thu, 26 Jun 2025 18:35:40 +0200 Subject: [PATCH] fix: Add entity cap check of armor stands & end crystals into player interact listener (#4654) When cancelled in the creature spawn event and placed by a player, the player will lose the armor stand / end crystal item from their inventory. This PR aims to fix this by moving the verification whether the entity should be cancelled up to the spawn egg right click, this way the item is not touched. --- .../bukkit/listener/PlayerEventListener.java | 11 +++++++++++ .../com/plotsquared/bukkit/util/BukkitEntityUtil.java | 6 +++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEventListener.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEventListener.java index 161ff8a91..05e325450 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEventListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEventListener.java @@ -1298,6 +1298,17 @@ public class PlayerEventListener implements Listener { //Allow all players to eat while also allowing the block place event to be fired return; } + // Process creature spawning of armor stands & end crystals here if spawned by the player in order to be able to + // reset the player's hand item if spawning needs to be cancelled. + if (type == Material.ARMOR_STAND || type == Material.END_CRYSTAL) { + Plot plot = location.getOwnedPlotAbs(); + if (BukkitEntityUtil.checkEntity(type == Material.ARMOR_STAND ? EntityType.ARMOR_STAND : EntityType.ENDER_CRYSTAL, + plot)) { + event.setCancelled(true); + break; + } + } + // Continue with normal place event checks if (type == Material.ARMOR_STAND) { location = BukkitUtil.adapt(block.getRelative(event.getBlockFace()).getLocation()); eventType = PlayerBlockEventType.PLACE_MISC; diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEntityUtil.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEntityUtil.java index cb0272f2d..5bb8988fa 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEntityUtil.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEntityUtil.java @@ -354,13 +354,17 @@ public class BukkitEntityUtil { } public static boolean checkEntity(Entity entity, Plot plot) { + return checkEntity(entity.getType(), plot); + } + + public static boolean checkEntity(EntityType type, Plot plot) { if (plot == null || !plot.hasOwner() || plot.getFlags().isEmpty() && plot.getArea() .getFlagContainer().getFlagMap().isEmpty()) { return false; } final com.sk89q.worldedit.world.entity.EntityType entityType = - BukkitAdapter.adapt(entity.getType()); + BukkitAdapter.adapt(type); if (EntityCategories.PLAYER.contains(entityType)) { return false;