From 869ead63bc577314bc5a8bb116231a8672b1c84a Mon Sep 17 00:00:00 2001 From: wizjany Date: Sat, 24 Jan 2015 17:02:55 -0500 Subject: [PATCH] Fix armor stands to behave more like item frames. Placing and modifying them respects permissions, and they are no longer blocked by mob-spawning deny. --- .../bukkit/listener/EventAbstractionListener.java | 7 +++++++ .../bukkit/listener/WorldGuardEntityListener.java | 6 ++++++ .../java/com/sk89q/worldguard/bukkit/util/Entities.java | 7 ++++++- .../java/com/sk89q/worldguard/bukkit/util/Materials.java | 3 +++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java b/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java index 46e06c2f..eb086ae8 100644 --- a/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java +++ b/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java @@ -833,6 +833,13 @@ private static void handleBlockRightClick(T even Events.fireToCancel(event, new SpawnEntityEvent(event, cause, placed.getLocation().add(0.5, 0, 0.5), EntityType.BOAT)); } + // Handle created armor stands + try { // backwards compat for 1.7 + if (item != null && item.getType() == Material.ARMOR_STAND) { + Events.fireToCancel(event, new SpawnEntityEvent(event, cause, placed.getLocation().add(0.5, 0, 0.5), EntityType.ARMOR_STAND)); + } + } catch (Exception ignored) {} + // Handle created spawn eggs if (item != null && item.getType() == Material.MONSTER_EGG) { MaterialData data = item.getData(); diff --git a/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardEntityListener.java b/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardEntityListener.java index 17b24402..e17cc0bf 100644 --- a/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardEntityListener.java +++ b/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardEntityListener.java @@ -22,6 +22,7 @@ import com.sk89q.worldedit.blocks.BlockID; import com.sk89q.worldguard.LocalPlayer; import com.sk89q.worldguard.bukkit.*; +import com.sk89q.worldguard.bukkit.util.Entities; import com.sk89q.worldguard.protection.ApplicableRegionSet; import com.sk89q.worldguard.protection.flags.DefaultFlag; import com.sk89q.worldguard.protection.managers.RegionManager; @@ -552,6 +553,11 @@ public void onCreatureSpawn(CreatureSpawnEvent event) { return; } + // armor stands are living entities, but we check them as blocks/non-living entities, so ignore them here + if (Entities.isConsideredBuildingIfUsed(event.getEntity())) { + return; + } + if (wcfg.allowTamedSpawns && event.getEntity() instanceof Tameable // nullsafe check && ((Tameable) event.getEntity()).isTamed()) { diff --git a/src/main/java/com/sk89q/worldguard/bukkit/util/Entities.java b/src/main/java/com/sk89q/worldguard/bukkit/util/Entities.java index fcf0a7b5..47abdd09 100644 --- a/src/main/java/com/sk89q/worldguard/bukkit/util/Entities.java +++ b/src/main/java/com/sk89q/worldguard/bukkit/util/Entities.java @@ -19,6 +19,7 @@ package com.sk89q.worldguard.bukkit.util; +import com.sk89q.worldguard.util.Enums; import org.bukkit.entity.*; import org.bukkit.entity.minecart.ExplosiveMinecart; import org.bukkit.projectiles.ProjectileSource; @@ -163,6 +164,9 @@ public static boolean isNonPlayerCreature(Entity entity) { return entity instanceof LivingEntity && !(entity instanceof Player); } + private static final org.bukkit.entity.EntityType armorStandType = + Enums.findByValue(org.bukkit.entity.EntityType.class, "ARMOR_STAND"); + /** * Test whether using the given entity should be considered "building" * rather than merely using an entity. @@ -171,7 +175,8 @@ public static boolean isNonPlayerCreature(Entity entity) { * @return true if considered building */ public static boolean isConsideredBuildingIfUsed(Entity entity) { - return entity instanceof Hanging; + return entity instanceof Hanging + || entity.getType() == armorStandType; } } diff --git a/src/main/java/com/sk89q/worldguard/bukkit/util/Materials.java b/src/main/java/com/sk89q/worldguard/bukkit/util/Materials.java index 5482946f..8a4896c9 100644 --- a/src/main/java/com/sk89q/worldguard/bukkit/util/Materials.java +++ b/src/main/java/com/sk89q/worldguard/bukkit/util/Materials.java @@ -66,6 +66,9 @@ public final class Materials { ENTITY_ITEMS.put(EntityType.MINECART_HOPPER, Material.HOPPER_MINECART); ENTITY_ITEMS.put(EntityType.SPLASH_POTION, Material.POTION); ENTITY_ITEMS.put(EntityType.EGG, Material.EGG); + try { + ENTITY_ITEMS.put(EntityType.ARMOR_STAND, Material.ARMOR_STAND); + } catch (Exception ignored) {} MATERIAL_FLAGS.put(Material.AIR, 0); MATERIAL_FLAGS.put(Material.STONE, 0);