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.
This commit is contained in:
FlorianMichael
2025-06-26 18:35:40 +02:00
committed by GitHub
parent 6c6ea1c1b4
commit 84ec090df1
2 changed files with 16 additions and 1 deletions

View File

@ -1298,6 +1298,17 @@ public class PlayerEventListener implements Listener {
//Allow all players to eat while also allowing the block place event to be fired //Allow all players to eat while also allowing the block place event to be fired
return; 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) { if (type == Material.ARMOR_STAND) {
location = BukkitUtil.adapt(block.getRelative(event.getBlockFace()).getLocation()); location = BukkitUtil.adapt(block.getRelative(event.getBlockFace()).getLocation());
eventType = PlayerBlockEventType.PLACE_MISC; eventType = PlayerBlockEventType.PLACE_MISC;

View File

@ -354,13 +354,17 @@ public class BukkitEntityUtil {
} }
public static boolean checkEntity(Entity entity, Plot plot) { 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() if (plot == null || !plot.hasOwner() || plot.getFlags().isEmpty() && plot.getArea()
.getFlagContainer().getFlagMap().isEmpty()) { .getFlagContainer().getFlagMap().isEmpty()) {
return false; return false;
} }
final com.sk89q.worldedit.world.entity.EntityType entityType = final com.sk89q.worldedit.world.entity.EntityType entityType =
BukkitAdapter.adapt(entity.getType()); BukkitAdapter.adapt(type);
if (EntityCategories.PLAYER.contains(entityType)) { if (EntityCategories.PLAYER.contains(entityType)) {
return false; return false;