Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
wizjany committed Jan 24, 2015
1 parent 6a6de78 commit 869ead6
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
Expand Up @@ -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();
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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()) {
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/com/sk89q/worldguard/bukkit/util/Entities.java
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand All @@ -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;
}

}
3 changes: 3 additions & 0 deletions src/main/java/com/sk89q/worldguard/bukkit/util/Materials.java
Expand Up @@ -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);
Expand Down

0 comments on commit 869ead6

Please sign in to comment.