mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-07-01 05:04:43 +02:00
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:
@ -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;
|
||||
|
@ -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;
|
||||
|
Reference in New Issue
Block a user