Skip to content

Commit 84ec090

Browse files
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.
1 parent 6c6ea1c commit 84ec090

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEventListener.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,6 +1298,17 @@ public void onInteract(PlayerInteractEvent event) {
12981298
//Allow all players to eat while also allowing the block place event to be fired
12991299
return;
13001300
}
1301+
// Process creature spawning of armor stands & end crystals here if spawned by the player in order to be able to
1302+
// reset the player's hand item if spawning needs to be cancelled.
1303+
if (type == Material.ARMOR_STAND || type == Material.END_CRYSTAL) {
1304+
Plot plot = location.getOwnedPlotAbs();
1305+
if (BukkitEntityUtil.checkEntity(type == Material.ARMOR_STAND ? EntityType.ARMOR_STAND : EntityType.ENDER_CRYSTAL,
1306+
plot)) {
1307+
event.setCancelled(true);
1308+
break;
1309+
}
1310+
}
1311+
// Continue with normal place event checks
13011312
if (type == Material.ARMOR_STAND) {
13021313
location = BukkitUtil.adapt(block.getRelative(event.getBlockFace()).getLocation());
13031314
eventType = PlayerBlockEventType.PLACE_MISC;

Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEntityUtil.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,13 +354,17 @@ public static boolean entityDamage(Entity damager, Entity victim, EntityDamageEv
354354
}
355355

356356
public static boolean checkEntity(Entity entity, Plot plot) {
357+
return checkEntity(entity.getType(), plot);
358+
}
359+
360+
public static boolean checkEntity(EntityType type, Plot plot) {
357361
if (plot == null || !plot.hasOwner() || plot.getFlags().isEmpty() && plot.getArea()
358362
.getFlagContainer().getFlagMap().isEmpty()) {
359363
return false;
360364
}
361365

362366
final com.sk89q.worldedit.world.entity.EntityType entityType =
363-
BukkitAdapter.adapt(entity.getType());
367+
BukkitAdapter.adapt(type);
364368

365369
if (EntityCategories.PLAYER.contains(entityType)) {
366370
return false;

0 commit comments

Comments
 (0)