Permalink
Browse files

Add mobs.block-armor-stand-destroy config option.

Same as the -painting- and -item-frame- ones.
Fixes WORLDGUARD-3781.
  • Loading branch information...
wizjany committed Dec 23, 2016
1 parent 67ece5c commit c0f3171a33039588d24b1b4b8f04d4c50380c24d
@@ -118,6 +118,7 @@
public boolean blockOtherExplosions;
public boolean blockEntityPaintingDestroy;
public boolean blockEntityItemFrameDestroy;
+ public boolean blockEntityArmorStandDestroy;
public boolean blockPluginSpawning;
public boolean blockGroundSlimes;
public boolean blockZombieDoorDestruction;
@@ -182,8 +183,8 @@
public boolean disableObsidianGenerators;
public boolean strictEntitySpawn;
public TargetMatcherSet allowAllInteract;
- public TargetMatcherSet blockUseAtFeet;
+ public TargetMatcherSet blockUseAtFeet;
private Map<String, Integer> maxRegionCounts;
/* Configuration data end */
@@ -407,6 +408,7 @@ private void loadConfiguration() {
disableSnowmanTrails = getBoolean("mobs.disable-snowman-trails", false);
blockEntityPaintingDestroy = getBoolean("mobs.block-painting-destroy", false);
blockEntityItemFrameDestroy = getBoolean("mobs.block-item-frame-destroy", false);
+ blockEntityArmorStandDestroy = getBoolean("mobs.block-armor-stand-destroy", false);
blockPluginSpawning = getBoolean("mobs.block-plugin-spawning", true);
blockGroundSlimes = getBoolean("mobs.block-above-ground-slimes", false);
blockOtherExplosions = getBoolean("mobs.block-other-explosions", false);
@@ -160,17 +160,23 @@ private void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
Entity attacker = event.getDamager();
Entity defender = event.getEntity();
+ WorldConfiguration wcfg = plugin.getGlobalStateManager().get(defender.getWorld());
+
if (defender instanceof ItemFrame) {
if (checkItemFrameProtection(attacker, (ItemFrame) defender)) {
event.setCancelled(true);
return;
}
+ } else if (defender.getType() == Entities.armorStandType && Entities.isNonPlayerCreature(attacker)) {
+ if (wcfg.blockEntityArmorStandDestroy) {
+ event.setCancelled(true);
+ return;
+ }
}
- if (attacker.getType() == Entities.enderCrystalType) {
+ if (attacker != null && attacker.getType() == Entities.enderCrystalType) {
// this isn't handled elsewhere because ender crystal explosions don't carry a player cause
// in the same way that creepers or tnt can
- WorldConfiguration wcfg = plugin.getGlobalStateManager().get(defender.getWorld());
if (wcfg.useRegions && wcfg.explosionFlagCancellation) {
if (!plugin.getRegionContainer().createQuery().getApplicableRegions(defender.getLocation())
.testState(null, DefaultFlag.OTHER_EXPLOSION)) {
@@ -184,9 +190,6 @@ private void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
Player player = (Player) defender;
LocalPlayer localPlayer = plugin.wrapPlayer(player);
- ConfigurationManager cfg = plugin.getGlobalStateManager();
- WorldConfiguration wcfg = cfg.get(player.getWorld());
-
if (wcfg.disableLightningDamage && event.getCause() == DamageCause.LIGHTNING) {
event.setCancelled(true);
return;
@@ -222,7 +225,6 @@ private void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
}
if (wcfg.useRegions) {
- RegionManager mgr = plugin.getGlobalRegionManager().get(player.getWorld());
ApplicableRegionSet set = plugin.getRegionContainer().createQuery().getApplicableRegions(defender.getLocation());
if (!set.allows(DefaultFlag.MOB_DAMAGE, localPlayer) && !(attacker instanceof Tameable)) {
@@ -252,15 +254,15 @@ private void onEntityDamageByProjectile(EntityDamageByEntityEvent event) {
return;
}
+ ConfigurationManager cfg = plugin.getGlobalStateManager();
+ WorldConfiguration wcfg = cfg.get(defender.getWorld());
if (defender instanceof Player) {
Player player = (Player) defender;
LocalPlayer localPlayer = plugin.wrapPlayer(player);
- ConfigurationManager cfg = plugin.getGlobalStateManager();
- WorldConfiguration wcfg = cfg.get(player.getWorld());
// Check Mob
- if (attacker != null && !(attacker instanceof Player)) {
+ if (!(attacker instanceof Player)) {
if (wcfg.disableMobDamage) {
event.setCancelled(true);
return;
@@ -299,6 +301,10 @@ private void onEntityDamageByProjectile(EntityDamageByEntityEvent event) {
event.setCancelled(true);
return;
}
+ } else if (defender.getType() == Entities.armorStandType && Entities.isNonPlayerCreature(attacker)) {
+ if (wcfg.blockEntityArmorStandDestroy) {
+ event.setCancelled(true);
+ }
}
}
@@ -180,7 +180,7 @@ public static boolean isNonPlayerCreature(Entity entity) {
return entity instanceof LivingEntity && !(entity instanceof Player);
}
- private static final EntityType armorStandType =
+ public static final EntityType armorStandType =
Enums.findByValue(EntityType.class, "ARMOR_STAND");
public static final EntityType enderCrystalType =
Enums.findByValue(EntityType.class, "ENDER_CRYSTAL");

0 comments on commit c0f3171

Please sign in to comment.