Search in sources :

Example 11 with IndirectEntityDamageSource

use of org.spongepowered.api.event.cause.entity.damage.source.IndirectEntityDamageSource in project Skree by Skelril.

the class DefensiveClusterListener method getSource.

public Optional<Living> getSource(Cause cause) {
    Optional<EntityDamageSource> optEntityDamageSource = cause.first(EntityDamageSource.class);
    if (!optEntityDamageSource.isPresent()) {
        return Optional.empty();
    }
    EntityDamageSource damageSource = optEntityDamageSource.get();
    Entity source;
    if (damageSource instanceof IndirectEntityDamageSource) {
        source = ((IndirectEntityDamageSource) damageSource).getIndirectSource();
    } else {
        source = damageSource.getSource();
    }
    if (!(source instanceof Living)) {
        return Optional.empty();
    }
    return Optional.of((Living) source);
}
Also used : Entity(org.spongepowered.api.entity.Entity) Living(org.spongepowered.api.entity.living.Living) IndirectEntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.IndirectEntityDamageSource) EntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.EntityDamageSource) IndirectEntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.IndirectEntityDamageSource)

Aggregations

IndirectEntityDamageSource (org.spongepowered.api.event.cause.entity.damage.source.IndirectEntityDamageSource)11 Entity (org.spongepowered.api.entity.Entity)9 Player (org.spongepowered.api.entity.living.player.Player)7 EntityDamageSource (org.spongepowered.api.event.cause.entity.damage.source.EntityDamageSource)7 Living (org.spongepowered.api.entity.living.Living)6 DamageSource (org.spongepowered.api.event.cause.entity.damage.source.DamageSource)5 Instruction (com.skelril.openboss.Instruction)4 DamageEntityEvent (org.spongepowered.api.event.entity.DamageEntityEvent)4 ItemStack (org.spongepowered.api.item.inventory.ItemStack)4 World (org.spongepowered.api.world.World)3 Vector3d (com.flowpowered.math.vector.Vector3d)2 PlayerCombatParser (com.skelril.nitro.combat.PlayerCombatParser)2 ItemDropper (com.skelril.nitro.item.ItemDropper)2 ItemStackFactory.newItemStack (com.skelril.nitro.item.ItemStackFactory.newItemStack)2 Skeleton (org.spongepowered.api.entity.living.monster.Skeleton)2 DropTable (com.skelril.nitro.droptable.DropTable)1 MasterDropTable (com.skelril.nitro.droptable.MasterDropTable)1 WildernessBossDetail (com.skelril.skree.content.world.wilderness.WildernessBossDetail)1 WanderingBoss (com.skelril.skree.content.world.wilderness.wanderer.WanderingBoss)1 ZoneBossDetail (com.skelril.skree.content.zone.ZoneBossDetail)1