From 2121cbd8dd3f07fbeb5985d119df01fa893c58d7 Mon Sep 17 00:00:00 2001 From: Blanclour Date: Sat, 5 Nov 2016 09:42:16 -0500 Subject: [PATCH] Fix Lingering Potion PvP Bug --- src/com/massivecraft/factions/Factions.java | 2 + .../factions/integration/V19/EngineV19.java | 69 +++++++++++++++++++ .../integration/V19/IntegrationV19.java | 31 +++++++++ 3 files changed, 102 insertions(+) create mode 100644 src/com/massivecraft/factions/integration/V19/EngineV19.java create mode 100644 src/com/massivecraft/factions/integration/V19/IntegrationV19.java diff --git a/src/com/massivecraft/factions/Factions.java b/src/com/massivecraft/factions/Factions.java index b650de9b..8664a91d 100644 --- a/src/com/massivecraft/factions/Factions.java +++ b/src/com/massivecraft/factions/Factions.java @@ -35,6 +35,7 @@ import com.massivecraft.factions.entity.MFlagColl; import com.massivecraft.factions.entity.MPermColl; import com.massivecraft.factions.entity.MPlayerColl; import com.massivecraft.factions.entity.MConfColl; +import com.massivecraft.factions.integration.V19.IntegrationV19; import com.massivecraft.factions.integration.herochat.IntegrationHerochat; import com.massivecraft.factions.integration.lwc.IntegrationLwc; import com.massivecraft.factions.integration.spigot.IntegrationSpigot; @@ -159,6 +160,7 @@ public class Factions extends MassivePlugin IntegrationHerochat.class, IntegrationLwc.class, IntegrationWorldGuard.class, + IntegrationV19.class, // Spigot IntegrationSpigot.class, diff --git a/src/com/massivecraft/factions/integration/V19/EngineV19.java b/src/com/massivecraft/factions/integration/V19/EngineV19.java new file mode 100644 index 00000000..4f1e24f1 --- /dev/null +++ b/src/com/massivecraft/factions/integration/V19/EngineV19.java @@ -0,0 +1,69 @@ +package com.massivecraft.factions.integration.V19; + +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.entity.Entity; +import org.bukkit.entity.LivingEntity; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.entity.AreaEffectCloudApplyEvent; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.projectiles.ProjectileSource; + +import com.massivecraft.factions.Factions; +import com.massivecraft.factions.engine.EngineCombat; +import com.massivecraft.massivecore.Engine; +import com.massivecraft.massivecore.MassivePlugin; +import com.massivecraft.massivecore.util.MUtil; + +public class EngineV19 extends Engine +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static EngineV19 i = new EngineV19 (); + public static EngineV19 get() { return i; } + + @Override + public MassivePlugin getActivePlugin() + { + return Factions.get(); + } + + // -------------------------------------------- // + // LISTENER + // -------------------------------------------- // + + @SuppressWarnings("deprecation") + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void canCombatDamageHappen(AreaEffectCloudApplyEvent event) + { + // If a harmful potion effect cloud is present ... + if ( ! MUtil.isHarmfulPotion(event.getEntity().getBasePotionData().getType().getEffectType())) return; + + ProjectileSource projectileSource = event.getEntity().getSource(); + if ( ! (projectileSource instanceof Entity)) return; + + Entity thrower = (Entity)projectileSource; + + // ... create a dummy list to avoid ConcurrentModificationException ... + List affectedList = new ArrayList(); + + // ... then scan through affected entities to make sure they're all valid targets ... + for (LivingEntity affectedEntity : event.getAffectedEntities()) + { + EntityDamageByEntityEvent sub = new EntityDamageByEntityEvent(thrower, affectedEntity, EntityDamageEvent.DamageCause.CUSTOM, 0D); + // Notification disabled due to the iterating nature of effect clouds. + if (EngineCombat.get().canCombatDamageHappen(sub, false)) continue; + + affectedList.add(affectedEntity); + } + + // finally, remove valid targets from the affected list. (Unlike splash potions, area effect cloud's affected entities list is mutable.) + event.getAffectedEntities().removeAll(affectedList); + } + +} diff --git a/src/com/massivecraft/factions/integration/V19/IntegrationV19.java b/src/com/massivecraft/factions/integration/V19/IntegrationV19.java new file mode 100644 index 00000000..c7c398e6 --- /dev/null +++ b/src/com/massivecraft/factions/integration/V19/IntegrationV19.java @@ -0,0 +1,31 @@ +package com.massivecraft.factions.integration.V19; + +import com.massivecraft.massivecore.Engine; +import com.massivecraft.massivecore.Integration; + +public class IntegrationV19 extends Integration +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static IntegrationV19 i = new IntegrationV19(); + public static IntegrationV19 get() { return i; } + private IntegrationV19() + { + this.setClassNames( + "org.bukkit.event.entity.AreaEffectCloudApplyEvent" + ); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public Engine getEngine() + { + return EngineV19.get(); + } + +}