Search in sources :

Example 11 with Projectile

use of org.spongepowered.api.entity.projectile.Projectile in project Skree by Skelril.

the class ProjectileWatcherServiceImpl method onProjectileLaunch.

@Listener
public void onProjectileLaunch(SpawnEntityEvent event) {
    for (Entity entity : event.getEntities()) {
        if (!(entity instanceof Projectile)) {
            continue;
        }
        ProjectileSource shooter = ((Projectile) entity).getShooter();
        if (shooter instanceof ArmorEquipable) {
            entity.offer(new ShootingItemData((((ArmorEquipable) shooter).getItemInHand(HandTypes.MAIN_HAND).map(ItemStack::createSnapshot).orElse(null))));
        }
        track((Projectile) entity, event.getCause());
    }
}
Also used : Entity(org.spongepowered.api.entity.Entity) ArmorEquipable(org.spongepowered.api.entity.ArmorEquipable) ProjectileSource(org.spongepowered.api.entity.projectile.source.ProjectileSource) ItemStack(org.spongepowered.api.item.inventory.ItemStack) ShootingItemData(com.skelril.skree.service.internal.projectilewatcher.shooter.ShootingItemData) Projectile(org.spongepowered.api.entity.projectile.Projectile) Listener(org.spongepowered.api.event.Listener)

Example 12 with Projectile

use of org.spongepowered.api.entity.projectile.Projectile in project Skree by Skelril.

the class ArrowFishingHandler method onProjectileTickEvent.

@Listener
public void onProjectileTickEvent(ProjectileTickEvent event) {
    Projectile projectile = event.getTargetEntity();
    if (!(projectile instanceof Arrow) || Probability.getChance(3)) {
        return;
    }
    Location<World> loc = projectile.getLocation();
    if (MultiTypeRegistry.isWater(loc.getBlockType()) && checkVelocity(projectile.getVelocity())) {
        ProjectileSource source = projectile.getShooter();
        double modifier = 1;
        if (source instanceof Living) {
            modifier = 50;
        }
        Optional<ModifierService> optService = Sponge.getServiceManager().provide(ModifierService.class);
        int rolls = 1;
        if (optService.isPresent() && optService.get().isActive(UBER_ARROW_FISHING)) {
            if (source instanceof Living) {
                rolls = 15;
            } else {
                rolls = 5;
            }
        }
        new ItemDropper(loc).dropStacks(dropTable.getDrops(rolls, modifier));
    }
}
Also used : Arrow(org.spongepowered.api.entity.projectile.arrow.Arrow) ItemDropper(com.skelril.nitro.item.ItemDropper) Living(org.spongepowered.api.entity.living.Living) ProjectileSource(org.spongepowered.api.entity.projectile.source.ProjectileSource) ModifierService(com.skelril.skree.service.ModifierService) World(org.spongepowered.api.world.World) Projectile(org.spongepowered.api.entity.projectile.Projectile) Listener(org.spongepowered.api.event.Listener)

Example 13 with Projectile

use of org.spongepowered.api.entity.projectile.Projectile in project RedProtect by FabioZumbi12.

the class EntityListener method onEntityDamage.

@Listener(order = Order.FIRST, beforeModifications = true)
public void onEntityDamage(DamageEntityEvent e) {
    // victim
    Entity e1 = e.getTargetEntity();
    RedProtect.get().logger.debug(LogLevel.ENTITY, "EntityListener - DamageEntityEvent entity target " + e1.getType().getName());
    Region r = RedProtect.get().getRegionManager().getTopRegion(e1.getLocation(), this.getClass().getName());
    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(LogLevel.ENTITY, "EntityListener - 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().getRegionManager().getTopRegion(e1.getLocation(), this.getClass().getName());
    Region r2 = RedProtect.get().getRegionManager().getTopRegion(e2.getLocation(), this.getClass().getName());
    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 = RedProtect.get().getVersionHelper().getItemInHand(p2);
                if (itemInHand.getType().equals(ItemTypes.EGG) && !r1.canProtectiles(p2)) {
                    e.setCancelled(true);
                    RedProtect.get().getLanguageManager().sendMessage(p2, "playerlistener.region.cantuse");
                    return;
                }
                if (r2 != null) {
                    if (itemInHand.getType().equals(ItemTypes.EGG) && !r2.canProtectiles(p2)) {
                        e.setCancelled(true);
                        RedProtect.get().getLanguageManager().sendMessage(p2, "playerlistener.region.cantuse");
                        return;
                    }
                    if ((r1.flagExists("pvp") && !r1.canPVP((Player) e1, p2)) || (r1.flagExists("pvp") && !r2.canPVP((Player) e1, p2))) {
                        e.setCancelled(true);
                        RedProtect.get().getLanguageManager().sendMessage(p2, "entitylistener.region.cantpvp");
                    }
                } else if (r1.flagExists("pvp") && !r1.canPVP((Player) e1, p2)) {
                    e.setCancelled(true);
                    RedProtect.get().getLanguageManager().sendMessage(p2, "entitylistener.region.cantpvp");
                }
            } else if (r2 != null && r2.flagExists("pvp") && !r2.canPVP((Player) e1, p2)) {
                e.setCancelled(true);
                RedProtect.get().getLanguageManager().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);
                RedProtect.get().getLanguageManager().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);
            RedProtect.get().getLanguageManager().sendMessage(p2, "playerlistener.region.cantuse");
            return;
        }
        if (r2 != null && !r2.canBuild(p2)) {
            e.setCancelled(true);
            RedProtect.get().getLanguageManager().sendMessage(p2, "playerlistener.region.cantuse");
        }
    } else if ((e1 instanceof Hanging) && e2 instanceof Monster) {
        if (r1 != null || r2 != null) {
            RedProtect.get().logger.debug(LogLevel.ENTITY, "Cancelled ItemFrame drop Item");
            e.setCancelled(true);
        }
    } else if (e1 instanceof Explosive && !(e1 instanceof Living)) {
        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) ItemType(org.spongepowered.api.item.ItemType) Projectile(org.spongepowered.api.entity.projectile.Projectile) Golem(org.spongepowered.api.entity.living.golem.Golem) 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) Region(br.net.fabiozumbi12.RedProtect.Sponge.Region) Listener(org.spongepowered.api.event.Listener)

Example 14 with Projectile

use of org.spongepowered.api.entity.projectile.Projectile in project RedProtect by FabioZumbi12.

the class PlayerListener method onEntityDamageEvent.

@Listener(order = Order.FIRST, beforeModifications = true)
public void onEntityDamageEvent(DamageEntityEvent e) {
    // victim
    Entity e1 = e.getTargetEntity();
    // damager
    Entity e2 = null;
    if (e.getCause().first(IndirectEntityDamageSource.class).isPresent()) {
        e2 = e.getCause().first(IndirectEntityDamageSource.class).get().getSource();
        RedProtect.get().logger.debug(LogLevel.PLAYER, "RPLayerListener: Is DamageEntityEvent event. Damager " + e2.getType().getName());
    }
    Player damager = null;
    if (e2 instanceof Projectile) {
        Projectile proj = (Projectile) e2;
        if (proj.getShooter() instanceof Player) {
            damager = (Player) proj.getShooter();
        }
    } else if (e2 instanceof Player) {
        damager = (Player) e2;
    }
    Location<World> l = e1.getLocation();
    Region r = RedProtect.get().getRegionManager().getTopRegion(l, this.getClass().getName());
    if (r == null) {
        return;
    }
    RedProtect.get().logger.debug(LogLevel.PLAYER, "RPLayerListener: Is DamageEntityEvent event. Victim " + e1.getType().getName());
    if (damager != null) {
        if (e1 instanceof Hanging && !r.canBuild(damager)) {
            RedProtect.get().getLanguageManager().sendMessage(damager, "entitylistener.region.cantinteract");
            e.setCancelled(true);
            return;
        }
        if ((e1 instanceof Boat || e1 instanceof Minecart) && !r.canMinecart(damager)) {
            RedProtect.get().getLanguageManager().sendMessage(damager, "entitylistener.region.cantbreak");
            e.setCancelled(true);
            return;
        }
        if (e1 instanceof Player && !e1.equals(damager) && r.flagExists("pvp") && !r.canPVP(damager, (Player) e1)) {
            RedProtect.get().getLanguageManager().sendMessage(damager, "entitylistener.region.cantpvp");
            e.setCancelled(true);
            return;
        }
    }
    // return if not player
    if (!(e1 instanceof Player)) {
        return;
    }
    Player play = (Player) e.getTargetEntity();
    if (RedProtect.get().tpWait.contains(play.getName())) {
        RedProtect.get().tpWait.remove(play.getName());
        RedProtect.get().getLanguageManager().sendMessage(play, RedProtect.get().getLanguageManager().get("cmdmanager.region.tpcancelled"));
    }
    if (!r.canPlayerDamage()) {
        e.setCancelled(true);
    }
    // execute on health
    if (r.cmdOnHealth(play)) {
        RedProtect.get().logger.debug(LogLevel.PLAYER, "Cmd on healt: true");
    }
    if (!r.canDeath() && play.get(Keys.HEALTH).get() <= 1) {
        e.setCancelled(true);
    }
    // deny damagecauses
    List<String> Causes = RedProtect.get().getConfigManager().globalFlagsRoot().worlds.get(play.getWorld().getName()).deny_death_by;
    if (Causes.size() > 0) {
        DamageType damagec = null;
        if (e.getCause().containsType(EntityDamageSource.class)) {
            damagec = e.getCause().first(EntityDamageSource.class).get().getType();
        }
        if (e.getCause().containsType(DamageSource.class)) {
            damagec = e.getCause().first(DamageSource.class).get().getType();
        }
        if (e.getCause().containsType(BlockDamageSource.class)) {
            damagec = e.getCause().first(BlockDamageSource.class).get().getType();
        }
        if (damagec != null && Causes.contains(damagec.getName())) {
            e.setCancelled(true);
        }
    }
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) DamageSource(org.spongepowered.api.event.cause.entity.damage.source.DamageSource) BlockDamageSource(org.spongepowered.api.event.cause.entity.damage.source.BlockDamageSource) EntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.EntityDamageSource) IndirectEntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.IndirectEntityDamageSource) Minecart(org.spongepowered.api.entity.vehicle.minecart.Minecart) World(org.spongepowered.api.world.World) DamageType(org.spongepowered.api.event.cause.entity.damage.DamageType) Projectile(org.spongepowered.api.entity.projectile.Projectile) EntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.EntityDamageSource) IndirectEntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.IndirectEntityDamageSource) Hanging(org.spongepowered.api.entity.hanging.Hanging) BlockDamageSource(org.spongepowered.api.event.cause.entity.damage.source.BlockDamageSource) Region(br.net.fabiozumbi12.RedProtect.Sponge.Region) PlayerRegion(br.net.fabiozumbi12.RedProtect.Core.region.PlayerRegion) IndirectEntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.IndirectEntityDamageSource) Boat(org.spongepowered.api.entity.vehicle.Boat) Listener(org.spongepowered.api.event.Listener)

Example 15 with Projectile

use of org.spongepowered.api.entity.projectile.Projectile in project RedProtect by FabioZumbi12.

the class GlobalListener method onEntityDamageEntity.

@Listener(order = Order.FIRST, beforeModifications = true)
public void onEntityDamageEntity(DamageEntityEvent e) {
    Entity e1 = e.getTargetEntity();
    Entity e2;
    RedProtect.get().logger.debug(LogLevel.ENTITY, "GlobalListener: DamageEntityEvent - e1: " + e1.getType().getName());
    if (e1 instanceof Living && !(e1 instanceof Monster)) {
        Region r = RedProtect.get().getRegionManager().getTopRegion(e1.getLocation(), this.getClass().getName());
        if (r == null && RedProtect.get().getConfigManager().globalFlagsRoot().worlds.get(e1.getWorld().getName()).invincible) {
            e.setCancelled(true);
        }
    }
    if (e.getCause().first(Living.class).isPresent()) {
        e2 = e.getCause().first(Living.class).get();
        RedProtect.get().logger.debug(LogLevel.ENTITY, "GlobalListener: DamageEntityEvent - Is DamageEntityEvent event. Damager " + e2.getType().getName());
    } else {
        return;
    }
    RedProtect.get().logger.debug(LogLevel.ENTITY, "GlobalListener: DamageEntityEvent - e1: " + e1.getType().getName() + " - e2: " + e2.getType().getName());
    Location<World> loc = e1.getLocation();
    if (e2 instanceof Projectile) {
        Region r1 = RedProtect.get().getRegionManager().getTopRegion(loc, this.getClass().getName());
        if (r1 != null) {
            return;
        }
        Projectile proj = (Projectile) e2;
        if (proj.getShooter() instanceof Entity) {
            e2 = (Entity) proj.getShooter();
        }
        if (!(e2 instanceof Player)) {
            if (e1 instanceof Hanging || e1 instanceof ArmorStand) {
                if (!RedProtect.get().getConfigManager().globalFlagsRoot().worlds.get(e1.getWorld().getName()).entity_block_damage) {
                    e.setCancelled(true);
                    return;
                }
            }
        }
    }
    if (e2 instanceof Creeper || e2 instanceof PrimedTNT || e2 instanceof TNTMinecart) {
        Region r1 = RedProtect.get().getRegionManager().getTopRegion(loc, this.getClass().getName());
        if (r1 != null) {
            return;
        }
        if (e1 instanceof Player) {
            if (!RedProtect.get().getConfigManager().globalFlagsRoot().worlds.get(e1.getWorld().getName()).explosion_entity_damage) {
                e.setCancelled(true);
                return;
            }
        }
        if (e1 instanceof Animal || e1 instanceof Villager || e1 instanceof Golem || e1 instanceof Ambient) {
            if (!RedProtect.get().getConfigManager().globalFlagsRoot().worlds.get(e1.getWorld().getName()).explosion_entity_damage) {
                e.setCancelled(true);
                return;
            }
        }
        if (e1 instanceof Monster) {
            if (!RedProtect.get().getConfigManager().globalFlagsRoot().worlds.get(e1.getWorld().getName()).explosion_entity_damage) {
                e.setCancelled(true);
                return;
            }
        }
        if (e1 instanceof Hanging || e1 instanceof ArmorStand) {
            if (!RedProtect.get().getConfigManager().globalFlagsRoot().worlds.get(e1.getWorld().getName()).explosion_entity_damage) {
                e.setCancelled(true);
                return;
            }
        }
    }
    if (e2 instanceof Player) {
        Region r1 = RedProtect.get().getRegionManager().getTopRegion(loc, this.getClass().getName());
        if (r1 != null) {
            return;
        }
        Player p = (Player) e2;
        if (e1 instanceof Player) {
            if (!e1.equals(e2) && !RedProtect.get().getConfigManager().globalFlagsRoot().worlds.get(e1.getWorld().getName()).pvp && !p.hasPermission("redprotect.world.bypass")) {
                e.setCancelled(true);
                return;
            }
        }
        if (e1 instanceof Animal || e1 instanceof Villager || e1 instanceof Golem || e1 instanceof Ambient) {
            if (!RedProtect.get().getConfigManager().globalFlagsRoot().worlds.get(e1.getWorld().getName()).player_hurt_passives && !p.hasPermission("redprotect.world.bypass")) {
                e.setCancelled(true);
                return;
            }
        }
        if (e1 instanceof Monster) {
            if (!RedProtect.get().getConfigManager().globalFlagsRoot().worlds.get(e1.getWorld().getName()).player_hurt_monsters && !p.hasPermission("redprotect.world.bypass")) {
                e.setCancelled(true);
                return;
            }
        }
        if (e1 instanceof Boat || e1 instanceof Minecart) {
            if (!RedProtect.get().getConfigManager().globalFlagsRoot().worlds.get(e1.getWorld().getName()).use_minecart && !p.hasPermission("redprotect.world.bypass")) {
                e.setCancelled(true);
                return;
            }
        }
        if (e1 instanceof Hanging || e1 instanceof ArmorStand) {
            if (!RedProtect.get().getConfigManager().globalFlagsRoot().worlds.get(e1.getWorld().getName()).entity_block_damage && !p.hasPermission("redprotect.world.bypass")) {
                e.setCancelled(true);
            }
        }
    }
}
Also used : PrimedTNT(org.spongepowered.api.entity.explosive.PrimedTNT) Entity(org.spongepowered.api.entity.Entity) Player(org.spongepowered.api.entity.living.player.Player) Creeper(org.spongepowered.api.entity.living.monster.Creeper) TNTMinecart(org.spongepowered.api.entity.vehicle.minecart.TNTMinecart) Minecart(org.spongepowered.api.entity.vehicle.minecart.Minecart) World(org.spongepowered.api.world.World) Projectile(org.spongepowered.api.entity.projectile.Projectile) Golem(org.spongepowered.api.entity.living.golem.Golem) Hanging(org.spongepowered.api.entity.hanging.Hanging) TNTMinecart(org.spongepowered.api.entity.vehicle.minecart.TNTMinecart) Animal(org.spongepowered.api.entity.living.animal.Animal) Monster(org.spongepowered.api.entity.living.monster.Monster) Region(br.net.fabiozumbi12.RedProtect.Sponge.Region) Boat(org.spongepowered.api.entity.vehicle.Boat) Listener(org.spongepowered.api.event.Listener)

Aggregations

Projectile (org.spongepowered.api.entity.projectile.Projectile)15 Entity (org.spongepowered.api.entity.Entity)13 Player (org.spongepowered.api.entity.living.player.Player)12 Listener (org.spongepowered.api.event.Listener)11 World (org.spongepowered.api.world.World)9 Region (br.net.fabiozumbi12.RedProtect.Sponge.Region)8 Hanging (org.spongepowered.api.entity.hanging.Hanging)6 Living (org.spongepowered.api.entity.living.Living)4 Animal (org.spongepowered.api.entity.living.animal.Animal)4 Golem (org.spongepowered.api.entity.living.golem.Golem)4 Monster (org.spongepowered.api.entity.living.monster.Monster)4 ArrayList (java.util.ArrayList)3 Collection (java.util.Collection)3 ProjectileSource (org.spongepowered.api.entity.projectile.source.ProjectileSource)3 Boat (org.spongepowered.api.entity.vehicle.Boat)3 Minecart (org.spongepowered.api.entity.vehicle.minecart.Minecart)3 Vector3d (com.flowpowered.math.vector.Vector3d)2 List (java.util.List)2 Optional (java.util.Optional)2 Nullable (javax.annotation.Nullable)2