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

Same as the -painting- and -item-frame- ones.
Fixes WORLDGUARD-3781.
This commit is contained in:
wizjany 2016-12-22 23:38:28 -05:00
parent 67ece5c5d7
commit c0f3171a33
3 changed files with 19 additions and 11 deletions

View File

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

View File

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

View File

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