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.
This commit is contained in:
wizjany 2015-01-24 17:02:55 -05:00
parent 6a6de7802b
commit 869ead63bc
4 changed files with 22 additions and 1 deletions

View File

@ -833,6 +833,13 @@ private static <T extends Event & Cancellable> 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();

View File

@ -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()) {

View File

@ -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;
}
}

View File

@ -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);