Search in sources :

Example 21 with Living

use of org.spongepowered.api.entity.living.Living 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();
    });
}
Also used : Entity(org.spongepowered.api.entity.Entity) WildernessBossDetail(com.skelril.skree.content.world.wilderness.WildernessBossDetail) DamageSource(org.spongepowered.api.event.cause.entity.damage.source.DamageSource) IndirectEntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.IndirectEntityDamageSource) Living(org.spongepowered.api.entity.living.Living) Instruction(com.skelril.openboss.Instruction) World(org.spongepowered.api.world.World) Skeleton(org.spongepowered.api.entity.living.monster.Skeleton) IndirectEntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.IndirectEntityDamageSource)

Example 22 with Living

use of org.spongepowered.api.entity.living.Living in project Skree by Skelril.

the class DeathMark method apply.

@Override
public Optional<Instruction<DamagedCondition, Boss<Zombie, CatacombsBossDetail>>> apply(DamagedCondition damagedCondition, Boss<Zombie, CatacombsBossDetail> zombieCatacombsBossDetailBoss) {
    new PlayerCombatParser() {

        @Override
        public void processPlayerAttack(Player attacker, Living defender) {
            CatacombsBossDetail detail = zombieCatacombsBossDetailBoss.getDetail();
            CatacombsInstance inst = detail.getZone();
            if (detail.isWarmingMark()) {
                return;
            }
            if (detail.getMarked().isPresent()) {
                if (attacker.equals(detail.getMarked().get())) {
                    inst.getPlayerMessageChannel(PlayerClassifier.SPECTATOR).send(Text.of(TextColors.YELLOW, attacker.getName() + " has been freed!"));
                } else {
                    detail.getMarked().get().offer(Keys.HEALTH, 0D);
                }
                detail.setMarked(null);
            } else if (activate(detail)) {
                detail.warmMark();
                inst.getPlayerMessageChannel(PlayerClassifier.SPECTATOR).send(Text.of(TextColors.DARK_RED, "The necromancer stares intently at " + attacker.getName() + "!"));
                Task.builder().execute(() -> {
                    if (!inst.contains(attacker)) {
                        detail.setMarked(null);
                        return;
                    }
                    detail.setMarked(attacker);
                    inst.getPlayerMessageChannel(PlayerClassifier.SPECTATOR).send(Text.of(TextColors.DARK_RED, attacker.getName() + " has been marked!"));
                }).delay(3, TimeUnit.SECONDS).submit(SkreePlugin.inst());
            }
        }
    }.parse(damagedCondition.getEvent());
    return Optional.empty();
}
Also used : CatacombsBossDetail(com.skelril.skree.content.zone.group.catacombs.CatacombsBossDetail) Player(org.spongepowered.api.entity.living.player.Player) CatacombsInstance(com.skelril.skree.content.zone.group.catacombs.CatacombsInstance) Living(org.spongepowered.api.entity.living.Living) PlayerCombatParser(com.skelril.nitro.combat.PlayerCombatParser)

Example 23 with Living

use of org.spongepowered.api.entity.living.Living in project SpongeForge by SpongePowered.

the class SpongeForgeEventFactory method createPlayerUseItemFinishEvent.

public static LivingEntityUseItemEvent.Finish createPlayerUseItemFinishEvent(Event event) {
    UseItemStackEvent.Finish spongeEvent = (UseItemStackEvent.Finish) event;
    Optional<Living> living = spongeEvent.getCause().first(Living.class);
    if (!living.isPresent()) {
        return null;
    }
    net.minecraft.item.ItemStack itemstack = (net.minecraft.item.ItemStack) (Object) spongeEvent.getItemStackInUse().createStack();
    LivingEntityUseItemEvent.Finish forgeEvent = // TODO Forge allows changing the itemstack mid tick...
    new LivingEntityUseItemEvent.Finish((EntityLivingBase) living.get(), itemstack, spongeEvent.getRemainingDuration(), itemstack);
    return forgeEvent;
}
Also used : ItemStack(net.minecraft.item.ItemStack) UseItemStackEvent(org.spongepowered.api.event.item.inventory.UseItemStackEvent) Living(org.spongepowered.api.entity.living.Living) ItemStack(net.minecraft.item.ItemStack) LivingEntityUseItemEvent(net.minecraftforge.event.entity.living.LivingEntityUseItemEvent)

Example 24 with Living

use of org.spongepowered.api.entity.living.Living in project SpongeForge by SpongePowered.

the class SpongeForgeEventFactory method createPlayerUseItemStopEvent.

public static LivingEntityUseItemEvent.Stop createPlayerUseItemStopEvent(Event event) {
    UseItemStackEvent.Stop spongeEvent = (UseItemStackEvent.Stop) event;
    Optional<Living> living = spongeEvent.getCause().first(Living.class);
    if (!living.isPresent()) {
        return null;
    }
    net.minecraft.item.ItemStack itemstack = (net.minecraft.item.ItemStack) (Object) spongeEvent.getItemStackInUse().createStack();
    LivingEntityUseItemEvent.Stop forgeEvent = new LivingEntityUseItemEvent.Stop((EntityLivingBase) living.get(), itemstack, spongeEvent.getRemainingDuration());
    return forgeEvent;
}
Also used : ItemStack(net.minecraft.item.ItemStack) UseItemStackEvent(org.spongepowered.api.event.item.inventory.UseItemStackEvent) Living(org.spongepowered.api.entity.living.Living) ItemStack(net.minecraft.item.ItemStack) LivingEntityUseItemEvent(net.minecraftforge.event.entity.living.LivingEntityUseItemEvent)

Example 25 with Living

use of org.spongepowered.api.entity.living.Living in project RedProtect by FabioZumbi12.

the class RPEntityListener method onEntityDamage.

@Listener(order = Order.FIRST, beforeModifications = true)
public void onEntityDamage(DamageEntityEvent e) {
    // victim
    Entity e1 = e.getTargetEntity();
    RedProtect.get().logger.debug("entity", "RPEntityListener - DamageEntityEvent entity target " + e1.getType().getName());
    Region r = RedProtect.get().rm.getTopRegion(e1.getLocation());
    if (e1 instanceof Living && !(e1 instanceof Monster)) {
        if (r != null && r.flagExists("invincible")) {
            if (r.getFlagBool("invincible")) {
                e.setCancelled(true);
            }
        }
    }
    if (e1 instanceof Animal || e1 instanceof Villager || e1 instanceof Golem || e1 instanceof Ambient) {
        if (r != null && r.flagExists("invincible")) {
            if (r.getFlagBool("invincible")) {
                if (e1 instanceof Animal) {
                    ((Animal) e1).setTarget(null);
                }
                e.setCancelled(true);
            }
        }
    }
    // damager
    if (!e.getCause().first(Living.class).isPresent()) {
        return;
    }
    Entity e2 = e.getCause().first(Living.class).get();
    RedProtect.get().logger.debug("entity", "RPEntityListener - DamageEntityEvent damager " + e2.getType().getName());
    if (e2 instanceof Projectile) {
        Projectile a = (Projectile) e2;
        if (a.getShooter() instanceof Entity) {
            e2 = (Entity) a.getShooter();
        }
    }
    Region r1 = RedProtect.get().rm.getTopRegion(e1.getLocation());
    Region r2 = RedProtect.get().rm.getTopRegion(e2.getLocation());
    if (e.getCause().containsType(Lightning.class) || e.getCause().containsType(Explosive.class) || e.getCause().containsType(Fireball.class) || e.getCause().containsType(Explosion.class)) {
        if (r1 != null && !r1.canFire() && !(e2 instanceof Player)) {
            e.setCancelled(true);
            return;
        }
    }
    if (e1 instanceof Player) {
        if (e2 instanceof Player) {
            Player p2 = (Player) e2;
            if (r1 != null) {
                ItemType itemInHand = ItemTypes.NONE;
                if (p2.getItemInHand(HandTypes.MAIN_HAND).isPresent()) {
                    itemInHand = p2.getItemInHand(HandTypes.MAIN_HAND).get().getItem();
                } else if (p2.getItemInHand(HandTypes.OFF_HAND).isPresent()) {
                    itemInHand = p2.getItemInHand(HandTypes.OFF_HAND).get().getItem();
                }
                if (itemInHand.getType().equals(ItemTypes.EGG) && !r1.canProtectiles(p2)) {
                    e.setCancelled(true);
                    RPLang.sendMessage(p2, "playerlistener.region.cantuse");
                    return;
                }
                if (r2 != null) {
                    if (itemInHand.getType().equals(ItemTypes.EGG) && !r2.canProtectiles(p2)) {
                        e.setCancelled(true);
                        RPLang.sendMessage(p2, "playerlistener.region.cantuse");
                        return;
                    }
                    if ((r1.flagExists("pvp") && !r1.canPVP(p2)) || (r1.flagExists("pvp") && !r2.canPVP(p2))) {
                        e.setCancelled(true);
                        RPLang.sendMessage(p2, "entitylistener.region.cantpvp");
                    }
                } else if (r1.flagExists("pvp") && !r1.canPVP(p2)) {
                    e.setCancelled(true);
                    RPLang.sendMessage(p2, "entitylistener.region.cantpvp");
                }
            } else if (r2 != null && r2.flagExists("pvp") && !r2.canPVP(p2)) {
                e.setCancelled(true);
                RPLang.sendMessage(p2, "entitylistener.region.cantpvp");
            }
        }
    } else if (e1 instanceof Animal || e1 instanceof Villager || e1 instanceof Golem || e instanceof Ambient) {
        if (r1 != null && e2 instanceof Player) {
            Player p2 = (Player) e2;
            if (!r1.canInteractPassives(p2)) {
                e.setCancelled(true);
                RPLang.sendMessage(p2, "entitylistener.region.cantpassive");
            }
        }
    } else if ((e1 instanceof Hanging) && e2 instanceof Player) {
        Player p2 = (Player) e2;
        if (r1 != null && !r1.canBuild(p2)) {
            e.setCancelled(true);
            RPLang.sendMessage(p2, "playerlistener.region.cantuse");
            return;
        }
        if (r2 != null && !r2.canBuild(p2)) {
            e.setCancelled(true);
            RPLang.sendMessage(p2, "playerlistener.region.cantuse");
        }
    } else if ((e1 instanceof Hanging) && e2 instanceof Monster) {
        if (r1 != null || r2 != null) {
            RedProtect.get().logger.debug("entity", "Cancelled ItemFrame drop Item");
            e.setCancelled(true);
        }
    } else if ((e1 instanceof Explosive)) {
        if ((r1 != null && !r1.canFire()) || (r2 != null && !r2.canFire())) {
            e.setCancelled(true);
        }
    }
}
Also used : Entity(org.spongepowered.api.entity.Entity) Player(org.spongepowered.api.entity.living.player.Player) Explosion(org.spongepowered.api.world.explosion.Explosion) Living(org.spongepowered.api.entity.living.Living) ItemType(org.spongepowered.api.item.ItemType) Projectile(org.spongepowered.api.entity.projectile.Projectile) Golem(org.spongepowered.api.entity.living.golem.Golem) Ambient(org.spongepowered.api.entity.living.Ambient) Explosive(org.spongepowered.api.entity.explosive.Explosive) Hanging(org.spongepowered.api.entity.hanging.Hanging) Animal(org.spongepowered.api.entity.living.animal.Animal) Lightning(org.spongepowered.api.entity.weather.Lightning) Monster(org.spongepowered.api.entity.living.monster.Monster) Villager(org.spongepowered.api.entity.living.Villager) Region(br.net.fabiozumbi12.RedProtect.Sponge.Region) Listener(org.spongepowered.api.event.Listener)

Aggregations

Living (org.spongepowered.api.entity.living.Living)63 Entity (org.spongepowered.api.entity.Entity)34 Player (org.spongepowered.api.entity.living.player.Player)16 Instruction (com.skelril.openboss.Instruction)15 ZoneBossDetail (com.skelril.skree.content.zone.ZoneBossDetail)13 Listener (org.spongepowered.api.event.Listener)13 World (org.spongepowered.api.world.World)12 NamedBindInstruction (com.skelril.skree.content.zone.group.catacombs.instruction.bossmove.NamedBindInstruction)10 HealthBindInstruction (com.skelril.skree.content.zone.group.freakyfour.boss.bossmove.HealthBindInstruction)10 DamageEntityEvent (org.spongepowered.api.event.entity.DamageEntityEvent)8 EntityDamageSource (org.spongepowered.api.event.cause.entity.damage.source.EntityDamageSource)7 Vector3d (com.flowpowered.math.vector.Vector3d)6 PlayerCombatParser (com.skelril.nitro.combat.PlayerCombatParser)6 CuboidContainmentPredicate (com.skelril.nitro.position.CuboidContainmentPredicate)6 BackTeleportInstruction (com.skelril.skree.content.zone.group.freakyfour.boss.bossmove.BackTeleportInstruction)6 HealableInstruction (com.skelril.skree.content.zone.group.freakyfour.boss.bossmove.HealableInstruction)6 IndirectEntityDamageSource (org.spongepowered.api.event.cause.entity.damage.source.IndirectEntityDamageSource)6 Vector3i (com.flowpowered.math.vector.Vector3i)5 IntegratedRunnable (com.skelril.nitro.time.IntegratedRunnable)5 TimedRunnable (com.skelril.nitro.time.TimedRunnable)5