From 0f924843b0328c72c721e3d1e40d43987f88fd72 Mon Sep 17 00:00:00 2001 From: TheComputerGeek2 Date: Sun, 16 Apr 2017 19:36:00 -0700 Subject: [PATCH] Get the shooter of AreaEffectClouds as liable damagers --- .../massivecraft/massivecore/MassiveCore.java | 2 ++ .../IntegrationLiabilityAreaEffectCloud.java | 33 +++++++++++++++++++ .../LiabilityCalculatorAreaEffectCloud.java | 24 ++++++++++++++ .../massivecraft/massivecore/util/MUtil.java | 12 ++++--- 4 files changed, 66 insertions(+), 5 deletions(-) create mode 100644 src/com/massivecraft/massivecore/integration/liability/IntegrationLiabilityAreaEffectCloud.java create mode 100644 src/com/massivecraft/massivecore/integration/liability/LiabilityCalculatorAreaEffectCloud.java diff --git a/src/com/massivecraft/massivecore/MassiveCore.java b/src/com/massivecraft/massivecore/MassiveCore.java index 5ee0cae5..ce7d432b 100644 --- a/src/com/massivecraft/massivecore/MassiveCore.java +++ b/src/com/massivecraft/massivecore/MassiveCore.java @@ -51,6 +51,7 @@ import com.massivecraft.massivecore.engine.EngineMassiveCoreSponsor; import com.massivecraft.massivecore.engine.EngineMassiveCoreTeleportMixinCause; import com.massivecraft.massivecore.engine.EngineMassiveCoreVariable; import com.massivecraft.massivecore.engine.EngineMassiveCoreWorldNameSet; +import com.massivecraft.massivecore.integration.liability.IntegrationLiabilityAreaEffectCloud; import com.massivecraft.massivecore.integration.vault.IntegrationVault; import com.massivecraft.massivecore.item.DataBannerPattern; import com.massivecraft.massivecore.item.WriterItemStack; @@ -321,6 +322,7 @@ public class MassiveCore extends MassivePlugin // Integration IntegrationVault.class, + IntegrationLiabilityAreaEffectCloud.class, // Command CmdMassiveCore.class, diff --git a/src/com/massivecraft/massivecore/integration/liability/IntegrationLiabilityAreaEffectCloud.java b/src/com/massivecraft/massivecore/integration/liability/IntegrationLiabilityAreaEffectCloud.java new file mode 100644 index 00000000..3e75d3e7 --- /dev/null +++ b/src/com/massivecraft/massivecore/integration/liability/IntegrationLiabilityAreaEffectCloud.java @@ -0,0 +1,33 @@ +package com.massivecraft.massivecore.integration.liability; + +import com.massivecraft.massivecore.Integration; +import org.bukkit.entity.Entity; +import org.bukkit.event.entity.EntityDamageByEntityEvent; + +public class IntegrationLiabilityAreaEffectCloud extends Integration +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static IntegrationLiabilityAreaEffectCloud i = new IntegrationLiabilityAreaEffectCloud(); + public static IntegrationLiabilityAreaEffectCloud get() { return i; } + + public IntegrationLiabilityAreaEffectCloud() + { + this.setClassName("org.bukkit.entity.AreaEffectCloud"); + } + + // Don't need to specify an engine here since the only methods we want to protect are static + + // -------------------------------------------- // + // LIABILITY CALCULATION + // -------------------------------------------- // + + public Entity getLiableDamager(EntityDamageByEntityEvent event) + { + if (!this.isIntegrationActive()) return null; + return LiabilityCalculatorAreaEffectCloud.liability(event); + } + +} diff --git a/src/com/massivecraft/massivecore/integration/liability/LiabilityCalculatorAreaEffectCloud.java b/src/com/massivecraft/massivecore/integration/liability/LiabilityCalculatorAreaEffectCloud.java new file mode 100644 index 00000000..e5d50165 --- /dev/null +++ b/src/com/massivecraft/massivecore/integration/liability/LiabilityCalculatorAreaEffectCloud.java @@ -0,0 +1,24 @@ +package com.massivecraft.massivecore.integration.liability; + +import org.bukkit.entity.AreaEffectCloud; +import org.bukkit.entity.Entity; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.projectiles.ProjectileSource; + +public class LiabilityCalculatorAreaEffectCloud +{ + // -------------------------------------------- // + // LIABILITY CALCULATION + // -------------------------------------------- // + + public static Entity liability(EntityDamageByEntityEvent event) + { + Entity liable = event.getDamager(); + if (!(liable instanceof AreaEffectCloud)) return null; + + AreaEffectCloud cloud = (AreaEffectCloud) liable; + ProjectileSource source = cloud.getSource(); + return source instanceof Entity ? (Entity) source : null; + } + +} diff --git a/src/com/massivecraft/massivecore/util/MUtil.java b/src/com/massivecraft/massivecore/util/MUtil.java index 1effe032..1d49489e 100644 --- a/src/com/massivecraft/massivecore/util/MUtil.java +++ b/src/com/massivecraft/massivecore/util/MUtil.java @@ -9,6 +9,7 @@ import com.massivecraft.massivecore.comparator.ComparatorCaseInsensitive; import com.massivecraft.massivecore.engine.EngineMassiveCoreDatabase; import com.massivecraft.massivecore.engine.EngineMassiveCoreMain; import com.massivecraft.massivecore.engine.EngineMassiveCoreWorldNameSet; +import com.massivecraft.massivecore.integration.liability.IntegrationLiabilityAreaEffectCloud; import com.massivecraft.massivecore.mixin.MixinMessage; import com.massivecraft.massivecore.nms.NmsEntityGet; import com.massivecraft.massivecore.predicate.Predicate; @@ -1353,18 +1354,19 @@ public class MUtil public static Entity getLiableDamager(EntityDamageEvent event) { - if ( ! (event instanceof EntityDamageByEntityEvent)) return null; + if (!(event instanceof EntityDamageByEntityEvent)) return null; EntityDamageByEntityEvent edbeEvent = (EntityDamageByEntityEvent)event; Entity ret = edbeEvent.getDamager(); if (ret instanceof Projectile) { Projectile projectile = (Projectile)ret; ProjectileSource projectileSource = projectile.getShooter(); - if (projectileSource instanceof Entity) - { - ret = (Entity)projectileSource; - } + if (projectileSource instanceof Entity) ret = (Entity)projectileSource; } + + Entity cloudBasedDamager = IntegrationLiabilityAreaEffectCloud.get().getLiableDamager(edbeEvent); + if (cloudBasedDamager != null) ret = cloudBasedDamager; + return ret; }