Get the shooter of AreaEffectClouds as liable damagers

This commit is contained in:
TheComputerGeek2 2017-04-16 19:36:00 -07:00 committed by Olof Larsson
parent ed93c837bb
commit 0f924843b0
4 changed files with 66 additions and 5 deletions

View File

@ -51,6 +51,7 @@ import com.massivecraft.massivecore.engine.EngineMassiveCoreSponsor;
import com.massivecraft.massivecore.engine.EngineMassiveCoreTeleportMixinCause; import com.massivecraft.massivecore.engine.EngineMassiveCoreTeleportMixinCause;
import com.massivecraft.massivecore.engine.EngineMassiveCoreVariable; import com.massivecraft.massivecore.engine.EngineMassiveCoreVariable;
import com.massivecraft.massivecore.engine.EngineMassiveCoreWorldNameSet; import com.massivecraft.massivecore.engine.EngineMassiveCoreWorldNameSet;
import com.massivecraft.massivecore.integration.liability.IntegrationLiabilityAreaEffectCloud;
import com.massivecraft.massivecore.integration.vault.IntegrationVault; import com.massivecraft.massivecore.integration.vault.IntegrationVault;
import com.massivecraft.massivecore.item.DataBannerPattern; import com.massivecraft.massivecore.item.DataBannerPattern;
import com.massivecraft.massivecore.item.WriterItemStack; import com.massivecraft.massivecore.item.WriterItemStack;
@ -321,6 +322,7 @@ public class MassiveCore extends MassivePlugin
// Integration // Integration
IntegrationVault.class, IntegrationVault.class,
IntegrationLiabilityAreaEffectCloud.class,
// Command // Command
CmdMassiveCore.class, CmdMassiveCore.class,

View File

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

View File

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

View File

@ -9,6 +9,7 @@ import com.massivecraft.massivecore.comparator.ComparatorCaseInsensitive;
import com.massivecraft.massivecore.engine.EngineMassiveCoreDatabase; import com.massivecraft.massivecore.engine.EngineMassiveCoreDatabase;
import com.massivecraft.massivecore.engine.EngineMassiveCoreMain; import com.massivecraft.massivecore.engine.EngineMassiveCoreMain;
import com.massivecraft.massivecore.engine.EngineMassiveCoreWorldNameSet; import com.massivecraft.massivecore.engine.EngineMassiveCoreWorldNameSet;
import com.massivecraft.massivecore.integration.liability.IntegrationLiabilityAreaEffectCloud;
import com.massivecraft.massivecore.mixin.MixinMessage; import com.massivecraft.massivecore.mixin.MixinMessage;
import com.massivecraft.massivecore.nms.NmsEntityGet; import com.massivecraft.massivecore.nms.NmsEntityGet;
import com.massivecraft.massivecore.predicate.Predicate; import com.massivecraft.massivecore.predicate.Predicate;
@ -1353,18 +1354,19 @@ public class MUtil
public static Entity getLiableDamager(EntityDamageEvent event) public static Entity getLiableDamager(EntityDamageEvent event)
{ {
if ( ! (event instanceof EntityDamageByEntityEvent)) return null; if (!(event instanceof EntityDamageByEntityEvent)) return null;
EntityDamageByEntityEvent edbeEvent = (EntityDamageByEntityEvent)event; EntityDamageByEntityEvent edbeEvent = (EntityDamageByEntityEvent)event;
Entity ret = edbeEvent.getDamager(); Entity ret = edbeEvent.getDamager();
if (ret instanceof Projectile) if (ret instanceof Projectile)
{ {
Projectile projectile = (Projectile)ret; Projectile projectile = (Projectile)ret;
ProjectileSource projectileSource = projectile.getShooter(); ProjectileSource projectileSource = projectile.getShooter();
if (projectileSource instanceof Entity) if (projectileSource instanceof Entity) ret = (Entity)projectileSource;
{
ret = (Entity)projectileSource;
}
} }
Entity cloudBasedDamager = IntegrationLiabilityAreaEffectCloud.get().getLiableDamager(edbeEvent);
if (cloudBasedDamager != null) ret = cloudBasedDamager;
return ret; return ret;
} }