Skip to content

Commit

Permalink
Add mobs.block-armor-stand-destroy config option.
Browse files Browse the repository at this point in the history
Same as the -painting- and -item-frame- ones.
Fixes WORLDGUARD-3781.
  • Loading branch information
wizjany committed Dec 23, 2016
1 parent 67ece5c commit c0f3171
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
Expand Up @@ -118,6 +118,7 @@ public class WorldConfiguration {
public boolean blockOtherExplosions;
public boolean blockEntityPaintingDestroy;
public boolean blockEntityItemFrameDestroy;
public boolean blockEntityArmorStandDestroy;
public boolean blockPluginSpawning;
public boolean blockGroundSlimes;
public boolean blockZombieDoorDestruction;
Expand Down Expand Up @@ -182,8 +183,8 @@ public class WorldConfiguration {
public boolean disableObsidianGenerators;
public boolean strictEntitySpawn;
public TargetMatcherSet allowAllInteract;
public TargetMatcherSet blockUseAtFeet;

public TargetMatcherSet blockUseAtFeet;
private Map<String, Integer> maxRegionCounts;

/* Configuration data end */
Expand Down Expand Up @@ -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);
Expand Down
Expand Up @@ -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)) {
Expand All @@ -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;
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

}
Expand Down
Expand Up @@ -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");
Expand Down

0 comments on commit c0f3171

Please sign in to comment.