use of org.spongepowered.api.event.cause.entity.damage.source.IndirectEntityDamageSource in project Skree by Skelril.
the class GraveDigger method setupGraveDigger.
private void setupGraveDigger() {
Sponge.getEventManager().registerListeners(SkreePlugin.inst(), new BossListener<>(bossManager, Skeleton.class));
List<Instruction<BindCondition, Boss<Skeleton, WildernessBossDetail>>> bindProcessor = bossManager.getBindProcessor();
bindProcessor.add((condition, boss) -> {
Optional<Skeleton> optBossEnt = boss.getTargetEntity();
if (optBossEnt.isPresent()) {
Skeleton bossEnt = optBossEnt.get();
bossEnt.offer(Keys.DISPLAY_NAME, Text.of("Grave Digger"));
bossEnt.offer(Keys.CUSTOM_NAME_VISIBLE, true);
double bossHealth = 20 * 43 * boss.getDetail().getLevel();
setMaxHealth(bossEnt, bossHealth, true);
}
return Optional.empty();
});
List<Instruction<DamageCondition, Boss<Skeleton, WildernessBossDetail>>> damageProcessor = bossManager.getDamageProcessor();
damageProcessor.add((condition, boss) -> {
Entity eToHit = condition.getAttacked();
if (!(eToHit instanceof Living)) {
return Optional.empty();
}
Living toHit = (Living) eToHit;
Location<World> targetLocation = toHit.getLocation();
makeExplosiveTomb(targetLocation, boss);
return Optional.empty();
});
List<Instruction<DamagedCondition, Boss<Skeleton, WildernessBossDetail>>> damagedProcessor = bossManager.getDamagedProcessor();
damagedProcessor.add((condition, boss) -> {
Optional<DamageSource> optDamageSource = condition.getDamageSource();
if (optDamageSource.isPresent()) {
DamageSource damageSource = optDamageSource.get();
// Explosions are show up as custom instead of Explosion
if (damageSource.getType() == DamageTypes.CUSTOM) {
condition.getEvent().setCancelled(true);
}
if (!(damageSource instanceof IndirectEntityDamageSource)) {
return Optional.empty();
}
Entity source = ((IndirectEntityDamageSource) damageSource).getIndirectSource();
Location<World> targetLocation = source.getLocation();
makeExplosiveTomb(targetLocation, boss);
}
return Optional.empty();
});
}
use of org.spongepowered.api.event.cause.entity.damage.source.IndirectEntityDamageSource in project modules-extra by CubeEngine.
the class Observe method cause.
public static Map<String, Object> cause(Object cause, boolean doRecursion) {
if (cause instanceof EntityDamageSource) {
Entity source = ((EntityDamageSource) cause).getSource();
Map<String, Object> sourceCause = Observe.cause(source);
Map<String, Object> indirectCause = null;
if (cause instanceof IndirectEntityDamageSource) {
indirectCause = Observe.cause(((IndirectEntityDamageSource) cause).getIndirectSource());
if (sourceCause == null) {
return indirectCause;
}
}
// TODO indirectCause
return sourceCause;
} else if (cause instanceof BlockDamageSource) {
return Observe.cause(((BlockDamageSource) cause).getBlockSnapshot());
} else if (cause instanceof DamageSource) {
return Observe.damageCause(((DamageSource) cause));
}
if (cause instanceof Player) {
return playerCause(((Player) cause));
} else if (cause instanceof BlockSnapshot) {
return blockCause(((BlockSnapshot) cause));
} else if (cause instanceof PrimedTNT) {
return tntCause(((PrimedTNT) cause));
} else if (cause instanceof Entity) {
return entityCause(((Entity) cause), doRecursion);
}
// TODO other causes that interest us
return null;
}
use of org.spongepowered.api.event.cause.entity.damage.source.IndirectEntityDamageSource in project AtherysCore by Atherys-Horizons.
the class DamageConfig method getDamageType.
public AtherysDamageType getDamageType(EntityDamageSource originalSource) {
Entity source;
if (originalSource instanceof IndirectEntityDamageSource) {
source = ((IndirectEntityDamageSource) originalSource).getIndirectSource();
} else {
source = originalSource.getSource();
}
Optional<ItemStack> stack = InventoryUtils.getMainHand(source);
if (stack.isPresent()) {
return getItemDamageType(stack.get().getType());
} else {
return AtherysDamageTypes.UNARMED;
}
}
use of org.spongepowered.api.event.cause.entity.damage.source.IndirectEntityDamageSource in project Skree by Skelril.
the class BackTeleportInstruction method apply.
@Override
public Optional<Instruction<DamagedCondition, Boss<Living, ZoneBossDetail<FreakyFourInstance>>>> apply(DamagedCondition damagedCondition, Boss<Living, ZoneBossDetail<FreakyFourInstance>> livingZoneBossDetailBoss) {
DamageEntityEvent event = damagedCondition.getEvent();
new PlayerCombatParser() {
@Override
public void processPlayerAttack(Player attacker, Living defender) {
boolean backTeleport = Probability.getChance(config.backTeleport);
if (backTeleport || damagedCondition.getDamageSource().get() instanceof IndirectEntityDamageSource) {
double distSQ = 2;
double maxDist = 1;
if (defender instanceof Skeleton) {
distSQ = defender.getLocation().getPosition().distanceSquared(attacker.getLocation().getPosition());
maxDist = config.snipeeTeleportDist;
}
if (backTeleport || distSQ > Math.pow(maxDist, 2)) {
final Entity finalDamager = attacker;
Task.builder().execute(() -> {
defender.setLocation(finalDamager.getLocation());
throwBack(defender);
}).delayTicks(1).submit(SkreePlugin.inst());
}
}
}
}.parse(event);
return Optional.empty();
}
use of org.spongepowered.api.event.cause.entity.damage.source.IndirectEntityDamageSource in project Skree by Skelril.
the class RangedSpecialAttackClusterListener method getSource.
public Optional<Clause<Living, ItemStackSnapshot>> getSource(Cause cause) {
Optional<EntityDamageSource> optEntityDamageSource = cause.first(EntityDamageSource.class);
if (!optEntityDamageSource.isPresent()) {
return Optional.empty();
}
EntityDamageSource damageSource = optEntityDamageSource.get();
if (!(damageSource instanceof IndirectEntityDamageSource)) {
return Optional.empty();
}
Entity projectile = damageSource.getSource();
Entity source = ((IndirectEntityDamageSource) damageSource).getIndirectSource();
if (!(source instanceof Living)) {
return Optional.empty();
}
return Optional.of(new Clause<>((Living) source, projectile.get(SHOOTING_ITEM_DATA_KEY).map(Optional::get).orElse(null)));
}
Aggregations