From 12758b5a037448c892b24608db5bffd2d75cdcf1 Mon Sep 17 00:00:00 2001 From: RoboMWM Date: Thu, 17 Nov 2016 23:20:08 -0800 Subject: [PATCH] Close #25 - Witches can no longer apply potions to claimed animals (as if they were an untrusted player) - Protect claimed villagers as well - Don't cancel entire event when we're protecting a single animal. --- .../GriefPrevention/EntityEventHandler.java | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/me/ryanhamshire/GriefPrevention/EntityEventHandler.java b/src/me/ryanhamshire/GriefPrevention/EntityEventHandler.java index db6dd42..1870168 100644 --- a/src/me/ryanhamshire/GriefPrevention/EntityEventHandler.java +++ b/src/me/ryanhamshire/GriefPrevention/EntityEventHandler.java @@ -954,12 +954,14 @@ public class EntityEventHandler implements Listener PlayerData playerData = null; //if not a player or an explosive, allow + //RoboMWM: Or a lingering potion, or a witch if(attacker == null && damageSource != null && damageSource.getType() != EntityType.CREEPER && damageSource.getType() != EntityType.WITHER && damageSource.getType() != EntityType.ENDER_CRYSTAL && damageSource.getType() != EntityType.AREA_EFFECT_CLOUD + && damageSource.getType() != EntityType.WITCH && !(damageSource instanceof Projectile) && !(damageSource instanceof Explosive) && !(damageSource instanceof ExplosiveMinecart)) @@ -1187,37 +1189,42 @@ public class EntityEventHandler implements Listener //ignore potions not thrown by players ProjectileSource projectileSource = potion.getShooter(); - if(projectileSource == null || !(projectileSource instanceof Player)) return; - Player thrower = (Player)projectileSource; + if(projectileSource == null) return; + Player thrower = null; + if ((projectileSource instanceof Player)) + thrower = (Player)projectileSource; Collection effects = potion.getEffects(); for(PotionEffect effect : effects) { PotionEffectType effectType = effect.getType(); - //restrict some potions on claimed animals (griefers could use this to kill or steal animals over fences) + //restrict some potions on claimed animals (griefers could use this to kill or steal animals over fences) //RoboMWM: include villagers if(effectType.getName().equals("JUMP") || effectType.getName().equals("POISON")) { - for(LivingEntity effected : event.getAffectedEntities()) + Claim cachedClaim = null; + for(LivingEntity effected : event.getAffectedEntities()) { - Claim cachedClaim = null; - if(effected instanceof Animals) + if(effected.getType() == EntityType.VILLAGER || effected instanceof Animals) { Claim claim = this.dataStore.getClaimAt(effected.getLocation(), false, cachedClaim); if(claim != null) { cachedClaim = claim; - if(claim.allowContainers(thrower) != null) + if(thrower == null || claim.allowContainers(thrower) != null) { - event.setCancelled(true); - GriefPrevention.sendMessage(thrower, TextMode.Err, Messages.NoDamageClaimedEntity, claim.getOwnerName()); + event.setIntensity(effected, 0); + instance.sendMessage(thrower, TextMode.Err, Messages.NoDamageClaimedEntity, claim.getOwnerName()); return; } } } } } - + + //Otherwise, ignore potions not thrown by players + if (thrower == null) return; + //otherwise, no restrictions for positive effects if(positiveEffects.contains(effectType)) continue;