Search in sources :

Example 1 with ShulkerBullet

use of org.bukkit.entity.ShulkerBullet in project MagicPlugin by elBukkit.

the class ProjectileAction method start.

@Override
public SpellResult start(CastContext context) {
    MageController controller = context.getController();
    Mage mage = context.getMage();
    // Modify with wand power
    // Turned some of this off for now
    // int count = this.count * mage.getRadiusMultiplier();
    // int speed = this.speed * damageMultiplier;
    int size = (int) (mage.getRadiusMultiplier() * this.size);
    double damageMultiplier = mage.getDamageMultiplier("projectile");
    double damage = damageMultiplier * this.damage;
    float radiusMultiplier = mage.getRadiusMultiplier();
    float spread = this.spread;
    if (radiusMultiplier > 1) {
        spread = spread / radiusMultiplier;
    }
    Random random = context.getRandom();
    Class<?> projectileType = CompatibilityLib.getCompatibilityUtils().getProjectileClass(projectileTypeName);
    if (projectileType == null) {
        controller.getLogger().warning("Bad projectile class: " + projectileTypeName);
        return SpellResult.FAIL;
    }
    // Prepare parameters
    Location location = sourceLocation.getLocation(context);
    if (location == null) {
        return SpellResult.LOCATION_REQUIRED;
    }
    Vector direction = location.getDirection();
    if (startDistance > 0) {
        location = location.clone().add(direction.clone().multiply(startDistance));
    }
    // Spawn projectiles
    LivingEntity shootingEntity = context.getLivingEntity();
    ProjectileSource source = null;
    if (shootingEntity != null) {
        source = shootingEntity;
    }
    mage.setLaunchingProjectile(true);
    for (int i = 0; i < count; i++) {
        try {
            // Spawn a new projectile
            Projectile projectile = CompatibilityLib.getCompatibilityUtils().spawnProjectile(projectileType, location, direction, source, speed, spread, i > 0 ? spread : 0, random);
            if (projectile == null) {
                return SpellResult.FAIL;
            }
            if (shootingEntity != null) {
                projectile.setShooter(shootingEntity);
            }
            if (projectile instanceof ShulkerBullet) {
                ShulkerBullet bullet = (ShulkerBullet) projectile;
                bullet.setTarget(context.getTargetEntity());
            }
            if (projectile instanceof ThrownPotion && color != null && !color.isEmpty()) {
                ThrownPotion potion = (ThrownPotion) projectile;
                if (color.startsWith("#")) {
                    color = color.substring(1);
                }
                try {
                    Color potionColor = Color.fromRGB(Integer.parseInt(color, 16));
                    ItemStack itemStack = new ItemStack(Material.SPLASH_POTION);
                    ItemMeta meta = itemStack.getItemMeta();
                    if (meta != null && meta instanceof PotionMeta) {
                        CompatibilityLib.getCompatibilityUtils().setColor((PotionMeta) meta, potionColor);
                        itemStack.setItemMeta(meta);
                        potion.setItem(itemStack);
                    }
                } catch (Exception ex) {
                    context.getLogger().warning("Invalid potion color in Projectile action: " + color);
                }
            }
            if (projectile instanceof Fireball) {
                Fireball fireball = (Fireball) projectile;
                fireball.setIsIncendiary(useFire);
                fireball.setYield(size);
            }
            if (projectile instanceof Arrow) {
                Arrow arrow = (Arrow) projectile;
                if (useFire) {
                    arrow.setFireTicks(300);
                }
                if (damage > 0) {
                    CompatibilityLib.getCompatibilityUtils().setDamage(projectile, damage);
                }
                if (tickIncrease > 0) {
                    CompatibilityLib.getCompatibilityUtils().decreaseLifespan(projectile, tickIncrease);
                }
            }
            if (pickupStatus != null && !pickupStatus.isEmpty()) {
                CompatibilityLib.getCompatibilityUtils().setPickupStatus(projectile, pickupStatus);
            }
            if (!breakBlocks) {
                CompatibilityLib.getEntityMetadataUtils().setBoolean(projectile, MagicMetaKeys.CANCEL_EXPLOSION_BLOCKS, true);
            }
            track(context, projectile);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    mage.setLaunchingProjectile(false);
    return checkTracking(context);
}
Also used : Arrow(org.bukkit.entity.Arrow) Color(org.bukkit.Color) PotionMeta(org.bukkit.inventory.meta.PotionMeta) ShulkerBullet(org.bukkit.entity.ShulkerBullet) Projectile(org.bukkit.entity.Projectile) LivingEntity(org.bukkit.entity.LivingEntity) MageController(com.elmakers.mine.bukkit.api.magic.MageController) Fireball(org.bukkit.entity.Fireball) Random(java.util.Random) Mage(com.elmakers.mine.bukkit.api.magic.Mage) ThrownPotion(org.bukkit.entity.ThrownPotion) ProjectileSource(org.bukkit.projectiles.ProjectileSource) ItemStack(org.bukkit.inventory.ItemStack) Vector(org.bukkit.util.Vector) ItemMeta(org.bukkit.inventory.meta.ItemMeta) Location(org.bukkit.Location) SourceLocation(com.elmakers.mine.bukkit.magic.SourceLocation)

Example 2 with ShulkerBullet

use of org.bukkit.entity.ShulkerBullet in project Minigames by Derkades.

the class MeteorShower method spawnMeteor.

private void spawnMeteor() {
    MeteorBounds bounds = this.map.getMeteorBounds();
    float x = ThreadLocalRandom.current().nextFloat(bounds.minX(), bounds.maxX());
    float y = ThreadLocalRandom.current().nextFloat(bounds.y() - 10, bounds.y() + 10);
    float z = ThreadLocalRandom.current().nextFloat(bounds.minZ(), bounds.maxZ());
    Location bulletLoc = new Location(this.map.getWorld(), x, y, z);
    UUID uuid = this.map.getWorld().spawn(bulletLoc, ShulkerBullet.class).getUniqueId();
    meteorTasks.add(new BukkitRunnable() {

        Location loc = null;

        public void run() {
            Entity entity = map.getWorld().getEntity(uuid);
            if (entity == null) {
                if (loc != null) {
                    loc.getWorld().createExplosion(loc, 2.5f);
                    loc.getWorld().spawnParticle(Particle.LAVA, loc, 30, 1, 0, 1, 0);
                    if (ThreadLocalRandom.current().nextFloat() > 0.6) {
                        while (loc.getBlock().getType() == Material.AIR) {
                            loc.add(0, -1, 0);
                            if (y < 50) {
                                return;
                            }
                        }
                        createFire(loc);
                        loc.getBlock().setType(Material.LAVA);
                    }
                }
                this.cancel();
                return;
            }
            ShulkerBullet bullet = (ShulkerBullet) entity;
            loc = bullet.getLocation();
            loc.getWorld().spawnParticle(Particle.FLAME, loc, 5, 0, 0.5, 0, 0);
            loc.getWorld().spawnParticle(Particle.EXPLOSION_NORMAL, loc, 2, 0, .5, 0, 0);
        }
    }.runTaskTimer(Minigames.getInstance(), 1, 1));
    long delay = 15 - Math.max(this.getSecondsLeft() / 10, 10);
    this.meteorTasks.add(Scheduler.delay(delay, this::spawnMeteor));
}
Also used : Entity(org.bukkit.entity.Entity) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) UUID(java.util.UUID) ShulkerBullet(org.bukkit.entity.ShulkerBullet) Location(org.bukkit.Location)

Aggregations

Location (org.bukkit.Location)2 ShulkerBullet (org.bukkit.entity.ShulkerBullet)2 Mage (com.elmakers.mine.bukkit.api.magic.Mage)1 MageController (com.elmakers.mine.bukkit.api.magic.MageController)1 SourceLocation (com.elmakers.mine.bukkit.magic.SourceLocation)1 Random (java.util.Random)1 UUID (java.util.UUID)1 Color (org.bukkit.Color)1 Arrow (org.bukkit.entity.Arrow)1 Entity (org.bukkit.entity.Entity)1 Fireball (org.bukkit.entity.Fireball)1 LivingEntity (org.bukkit.entity.LivingEntity)1 Projectile (org.bukkit.entity.Projectile)1 ThrownPotion (org.bukkit.entity.ThrownPotion)1 ItemStack (org.bukkit.inventory.ItemStack)1 ItemMeta (org.bukkit.inventory.meta.ItemMeta)1 PotionMeta (org.bukkit.inventory.meta.PotionMeta)1 ProjectileSource (org.bukkit.projectiles.ProjectileSource)1 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)1 Vector (org.bukkit.util.Vector)1