Search in sources :

Example 31 with ProjectileSource

use of org.bukkit.projectiles.ProjectileSource in project Glowstone by GlowstoneMC.

the class GlowEnderPearl method collide.

/**
 * Process teleportation when collide with a block.
 *
 * @param block the block that the ender pearl collides with
 */
@Override
public void collide(Block block) {
    ProjectileSource source = getShooter();
    if (source instanceof Entity) {
        Location destination = getLocation();
        Entity entity = (Entity) source;
        Location entityLocation = entity.getLocation();
        // Add 0.3 to Y value. Otherwise the eneity will get stuck inside a block.
        destination.add(0, 0.3, 0);
        // Renew the pitch and yaw value right before teleportation.
        destination.setPitch(entityLocation.getPitch());
        destination.setYaw(entityLocation.getYaw());
        entity.teleport(destination, PlayerTeleportEvent.TeleportCause.ENDER_PEARL);
        // Give fall damage to the eneity that threw this ender pearl.
        if (source instanceof LivingEntity) {
            ((LivingEntity) entity).damage(ENDER_PEARL_DAMAGE, EntityDamageEvent.DamageCause.FALL);
        }
    }
    // Spawn endermite for 5% chance.
    ThreadLocalRandom random = ThreadLocalRandom.current();
    if (random.nextInt(100) < 5) {
        getWorld().spawn(location, GlowEndermite.class, CreatureSpawnEvent.SpawnReason.ENDER_PEARL);
    }
    remove();
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) ThreadLocalRandom(io.netty.util.internal.ThreadLocalRandom) ProjectileSource(org.bukkit.projectiles.ProjectileSource) Location(org.bukkit.Location)

Example 32 with ProjectileSource

use of org.bukkit.projectiles.ProjectileSource in project Glowstone by GlowstoneMC.

the class GlowEgg method randomHatchSpawning.

/**
 * Handle spawning entities when the egg breaks.
 *
 * @param location The location the egg breaks
 */
private void randomHatchSpawning(Location location) {
    ThreadLocalRandom random = ThreadLocalRandom.current();
    // There is a 1/8 chance for egg to hatch and spawn at least 1 entity
    boolean hatching = random.nextInt(8) == 0;
    // ...and if the egg is hatching, there is now
    // 1/32 chance to spawn 3 more entities.
    byte amount;
    if (hatching) {
        amount = (byte) ((random.nextInt(32) == 0) ? 4 : 1);
    } else {
        amount = 0;
    }
    EntityType hatchingType = EntityType.CHICKEN;
    final ProjectileSource shooter = getShooter();
    if (shooter instanceof GlowPlayer) {
        PlayerEggThrowEvent event = EventFactory.getInstance().callEvent(new PlayerEggThrowEvent((GlowPlayer) shooter, this, hatching, amount, hatchingType));
        amount = event.getNumHatches();
        hatching = event.isHatching();
        hatchingType = event.getHatchingType();
    }
    if (hatching) {
        for (int i = 0; i < amount; i++) {
            GlowEntity entity = (GlowEntity) location.getWorld().spawnEntity(location.clone().add(0, 0.3, 0), hatchingType);
            if (entity instanceof GlowAgeable) {
                ((GlowAgeable) entity).setBaby();
            }
        }
    }
}
Also used : EntityType(org.bukkit.entity.EntityType) GlowPlayer(net.glowstone.entity.GlowPlayer) PlayerEggThrowEvent(org.bukkit.event.player.PlayerEggThrowEvent) GlowEntity(net.glowstone.entity.GlowEntity) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) GlowAgeable(net.glowstone.entity.GlowAgeable) ProjectileSource(org.bukkit.projectiles.ProjectileSource)

Example 33 with ProjectileSource

use of org.bukkit.projectiles.ProjectileSource in project Glowstone by GlowstoneMC.

the class GlowFireball method explode.

private void explode() {
    ProjectileSource source = getShooter();
    world.createExplosion(source instanceof Entity ? (Entity) source : this, location.getX(), location.getY(), location.getZ(), yield, incendiary, true);
    remove();
}
Also used : Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) ProjectileSource(org.bukkit.projectiles.ProjectileSource)

Example 34 with ProjectileSource

use of org.bukkit.projectiles.ProjectileSource in project modules-extra by CubeEngine.

the class ListenerVehicle method onVehicleDestroy.

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onVehicleDestroy(final VehicleDestroyEvent event) {
    Entity causer;
    if (event.getAttacker() != null) {
        if (event.getAttacker() instanceof Player) {
            causer = event.getAttacker();
        } else if (event.getAttacker() instanceof Projectile) {
            ProjectileSource shooter = ((Projectile) event.getAttacker()).getShooter();
            if (shooter instanceof Player) {
                causer = (Player) shooter;
            } else if (shooter instanceof Entity) {
                causer = (Entity) shooter;
            } else {
                // TODO other ProjectileSources
                return;
            }
        } else {
            causer = event.getAttacker();
        }
    } else if (event.getVehicle().getPassenger() instanceof Player) {
        causer = event.getVehicle().getPassenger();
    } else {
        // TODO why?
        return;
    }
    if (causer instanceof Player) {
        VehicleBreak action = this.newAction(VehicleBreak.class, event.getVehicle().getWorld());
        if (action != null) {
            action.setLocation(event.getVehicle().getLocation());
            action.setVehicle(event.getVehicle());
            action.setPlayer((Player) causer);
            this.logAction(action);
        }
    } else {
    // TODO EntityVehicleBreak
    }
}
Also used : Entity(org.spongepowered.api.entity.Entity) Player(org.spongepowered.api.entity.player.Player) ProjectileSource(org.bukkit.projectiles.ProjectileSource) Projectile(org.bukkit.entity.Projectile) EventHandler(org.bukkit.event.EventHandler)

Example 35 with ProjectileSource

use of org.bukkit.projectiles.ProjectileSource in project modules-extra by CubeEngine.

the class ListenerBlockIgnite method onIgnite.

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onIgnite(BlockIgniteEvent event) {
    BlockState oldState = event.getBlock().getState();
    ActionBlock action;
    switch(event.getCause()) {
        case FIREBALL:
            action = this.newAction(IgniteFireball.class, oldState.getWorld());
            if (action != null) {
                ProjectileSource shooter = ((Fireball) event.getIgnitingEntity()).getShooter();
                if (shooter instanceof Entity) {
                    ((IgniteFireball) action).setShooter((Entity) shooter);
                    if (shooter instanceof Ghast) {
                        LivingEntity target = BukkitUtils.getTarget((Ghast) shooter);
                        if (target instanceof Player) {
                            ((IgniteFireball) action).setPlayer((Player) target);
                        }
                    } else if (shooter instanceof Player) {
                        ((IgniteFireball) action).setPlayer((Player) shooter);
                    }
                }
            }
            break;
        case LAVA:
            action = this.newAction(IgniteLava.class, oldState.getWorld());
            if (action != null) {
                ((IgniteLava) action).setSource(event.getIgnitingBlock().getLocation());
            }
            break;
        case LIGHTNING:
            action = this.newAction(IgniteLightning.class, oldState.getWorld());
            break;
        case FLINT_AND_STEEL:
            action = this.newAction(IgniteLighter.class, oldState.getWorld());
            if (action != null && event.getPlayer() != null) {
                ((IgniteLighter) action).setPlayer(event.getPlayer());
            }
            break;
        case ENDER_CRYSTAL:
        case EXPLOSION:
            action = this.newAction(IgniteOther.class, oldState.getWorld());
            break;
        case SPREAD:
            return;
        default:
            this.module.getLog().warn("Unknown IgniteCause! {}", event.getCause().name());
            return;
    }
    if (action != null) {
        action.setOldBlock(oldState);
        action.setNewBlock(FIRE);
        action.setLocation(oldState.getLocation());
        this.logAction(action);
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Entity(org.spongepowered.api.entity.Entity) Player(org.spongepowered.api.entity.player.Player) ActionBlock(org.cubeengine.module.log.action.block.ActionBlock) LivingEntity(org.bukkit.entity.LivingEntity) BlockState(org.bukkit.block.BlockState) Fireball(org.bukkit.entity.Fireball) Ghast(org.bukkit.entity.Ghast) ProjectileSource(org.bukkit.projectiles.ProjectileSource) EventHandler(org.bukkit.event.EventHandler)

Aggregations

ProjectileSource (org.bukkit.projectiles.ProjectileSource)44 EventHandler (org.bukkit.event.EventHandler)24 LivingEntity (org.bukkit.entity.LivingEntity)21 Projectile (org.bukkit.entity.Projectile)21 Entity (org.bukkit.entity.Entity)20 Player (org.bukkit.entity.Player)17 EntityDamageByEntityEvent (org.bukkit.event.entity.EntityDamageByEntityEvent)5 UUID (java.util.UUID)4 Entity (org.spongepowered.api.entity.Entity)4 Player (org.spongepowered.api.entity.player.Player)4 EntityDamageEvent (org.bukkit.event.entity.EntityDamageEvent)3 EntityTag (com.denizenscript.denizen.objects.EntityTag)2 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)2 Mage (com.elmakers.mine.bukkit.api.magic.Mage)2 EnumAbilities (com.jacob_vejvoda.infernal_mobs.ability.EnumAbilities)2 Mob (com.jacob_vejvoda.infernal_mobs.persist.Mob)2 List (java.util.List)2 Random (java.util.Random)2 GlowPlayer (net.glowstone.entity.GlowPlayer)2 Location (org.bukkit.Location)2