diff --git a/src/main/java/net/tfminecraft/dowsing/objects/Node.java b/src/main/java/net/tfminecraft/dowsing/objects/Node.java index 04772b2..9da7d0a 100644 --- a/src/main/java/net/tfminecraft/dowsing/objects/Node.java +++ b/src/main/java/net/tfminecraft/dowsing/objects/Node.java @@ -13,7 +13,10 @@ import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Sound; +import org.bukkit.entity.ArmorStand; import org.bukkit.entity.Entity; +import org.bukkit.entity.ItemDisplay; +import org.bukkit.entity.ItemFrame; import org.bukkit.entity.Player; import dev.lone.itemsadder.api.CustomFurniture; @@ -639,14 +642,7 @@ public void breakNode() { if(type.equalsIgnoreCase("v")) { this.loc.getBlock().setType(Material.AIR); } else if(type.equalsIgnoreCase("ia")) { - Location center = this.loc.clone().add(0.5, 0.5, 0.5); - for(Entity a : this.loc.getWorld().getNearbyEntities(center, 1.5, 1.5, 1.5)) { - CustomFurniture f = CustomFurniture.byAlreadySpawned(a); - if(f != null) { - f.remove(false); - break; - } - } + removeNearbyFurniture(); if(this.loc.getBlock().getType() != Material.AIR) { this.loc.getBlock().setType(Material.AIR); } @@ -658,4 +654,29 @@ public void breakNode() { loc.getWorld().playSound(loc, Sound.ENTITY_GLOW_ITEM_FRAME_REMOVE_ITEM, 0.5f, 1f); NodeManager.requestNodeBenefitSync(); } + + private void removeNearbyFurniture() { + Location center = this.loc.clone().add(0.5, 0.5, 0.5); + for(Entity entity : this.loc.getWorld().getNearbyEntities(center, 1.5, 1.5, 1.5)) { + if(!isFurnitureCarrier(entity)) continue; + CustomFurniture furniture = lookupFurniture(entity); + if(furniture != null) { + furniture.remove(false); + break; + } + } + } + + private static CustomFurniture lookupFurniture(Entity entity) { + try { + return CustomFurniture.byAlreadySpawned(entity); + } catch (RuntimeException ex) { + // ItemsAdder throws for entities that are not furniture instead of returning null. + return null; + } + } + + private static boolean isFurnitureCarrier(Entity entity) { + return entity instanceof ArmorStand || entity instanceof ItemFrame || entity instanceof ItemDisplay; + } }