org.bukkit.entity.SmallFireball Java Examples

The following examples show how to use org.bukkit.entity.SmallFireball. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CraftLivingEntity.java    From Thermos with GNU General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public <T extends Projectile> T launchProjectile(Class<? extends T> projectile, Vector velocity) {
    net.minecraft.world.World world = ((CraftWorld) getWorld()).getHandle();
    net.minecraft.entity.Entity launch = null;

    if (Snowball.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.projectile.EntitySnowball(world, getHandle());
    } else if (Egg.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.projectile.EntityEgg(world, getHandle());
    } else if (EnderPearl.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.item.EntityEnderPearl(world, getHandle());
    } else if (Arrow.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.projectile.EntityArrow(world, getHandle(), 1);
    } else if (ThrownPotion.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.projectile.EntityPotion(world, getHandle(), CraftItemStack.asNMSCopy(new ItemStack(Material.POTION, 1)));
    } else if (ThrownExpBottle.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.item.EntityExpBottle(world, getHandle());
    } else if (Fish.class.isAssignableFrom(projectile) && getHandle() instanceof net.minecraft.entity.player.EntityPlayer) {
        launch = new net.minecraft.entity.projectile.EntityFishHook(world, (net.minecraft.entity.player.EntityPlayer) getHandle());
    } else if (Fireball.class.isAssignableFrom(projectile)) {
        Location location = getEyeLocation();
        Vector direction = location.getDirection().multiply(10);

        if (SmallFireball.class.isAssignableFrom(projectile)) {
            launch = new net.minecraft.entity.projectile.EntitySmallFireball(world, getHandle(), direction.getX(), direction.getY(), direction.getZ());
        } else if (WitherSkull.class.isAssignableFrom(projectile)) {
            launch = new net.minecraft.entity.projectile.EntityWitherSkull(world, getHandle(), direction.getX(), direction.getY(), direction.getZ());
        } else {
            launch = new net.minecraft.entity.projectile.EntityLargeFireball(world, getHandle(), direction.getX(), direction.getY(), direction.getZ());
        }

        ((net.minecraft.entity.projectile.EntityFireball) launch).projectileSource = this;
        launch.setLocationAndAngles(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
    }

    Validate.notNull(launch, "Projectile not supported");

    if (velocity != null) {
        ((T) launch.getBukkitEntity()).setVelocity(velocity);
    }

    world.spawnEntityInWorld(launch);
    return (T) launch.getBukkitEntity();
}
 
Example #2
Source File: NecromancersStaff.java    From ce with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public boolean effect(Event event, Player player) {
    PlayerInteractEvent e = (PlayerInteractEvent) event;
    ItemMeta im = e.getPlayer().getItemInHand().getItemMeta();
    List<String> lore = new ArrayList<String>();
    if (!im.hasLore()) {
        lore.add(spells.get(0));
        im.setLore(lore);
        e.getPlayer().getItemInHand().setItemMeta(im);
    }
    lore = im.getLore();
    int lastElement = lore.size() - 1;

    if (e.getAction().toString().startsWith("LEFT")) {

        int nextSpellIndex = spells.indexOf(lore.get(lastElement)) + 1;

        if (nextSpellIndex == 3)
            nextSpellIndex = 0;

        String nextSpell = spells.get(nextSpellIndex);

        lore.set(lastElement, nextSpell);
        im.setLore(lore);
        e.getPlayer().getItemInHand().setItemMeta(im);

        player.sendMessage(ChatColor.GRAY + "Changed Spell to " + nextSpell.split(": ")[1] + ChatColor.GRAY + ".");
        player.getWorld().playEffect(player.getLocation(), Effect.CLICK1, 10);
    } else if (e.getAction().toString().startsWith("RIGHT")) {

        int spell = -1;
        int cost = -1;
        int cooldown = -1;

        // Get all values
        if (lore.get(lastElement).equals(spells.get(0))) {
            spell = 0;
            cost = WitherCost;
            cooldown = WitherCooldown;
        } else if (lore.get(lastElement).equals(spells.get(1))) {
            spell = 1;
            cost = FireballCost;
            cooldown = FireballCooldown;
        } else if (lore.get(lastElement).equals(spells.get(2))) {
            spell = 2;
            cost = LightningCost;
            cooldown = LightningCooldown;
        }

        // Apply costs
        if (player.getInventory().contains(Fuel, cost) || player.getGameMode().equals(GameMode.CREATIVE)) {
            if (!player.getGameMode().equals(GameMode.CREATIVE)) {
                ItemStack mana = new ItemStack(Fuel, cost);
                player.getInventory().removeItem(mana);
                player.updateInventory();
            }

            Location l = player.getLocation();

            // Apply effect
            if (spell == 0) {
                if (Tools.checkWorldGuard(l, player, "PVP", true)) {
                    WitherSkull ws = player.launchProjectile(WitherSkull.class);
                    ws.setVelocity(l.getDirection().multiply(2));
                    if (!Main.createExplosions)
                        ws.setMetadata("ce.explosive", new FixedMetadataValue(getPlugin(), null));
                    EffectManager.playSound(l, "ENTITY_WITHER_IDLE", 0.5f, 10f);
                } else {
                    EffectManager.playSound(l, "ENTITY_CAT_HISS", 0.3f, 5f);
                }
            } else if (spell == 1) {
                player.launchProjectile(SmallFireball.class).setVelocity(l.getDirection().multiply(1.5));
                EffectManager.playSound(l, "ENTITY_BLAZE_HIT", 0.2f, 0f);
            } else if (spell == 2) {
                Location target = player.getTargetBlock((Set<Material>) null, 20).getLocation();
                player.getWorld().strikeLightning(target);
                if (Tools.checkWorldGuard(l, player, "TNT", true))
                    player.getWorld().createExplosion(target, 1);
                EffectManager.playSound(target, "ENTITY_ENDERDRAGON_GROWL", 0.5f, 2f);
            }

            // Generate the cooldown based on the cooldown value
            generateCooldown(player, cooldown);
        } else {
            player.sendMessage(ChatColor.RED + "You need " + cost + " " + Fuel.toString().toLowerCase().replace("_", " ") + " to cast this spell.");
        }

    }
    return false; // The Staff generates it's own cooldowns, so it always
                  // returns false
}
 
Example #3
Source File: Blaze.java    From ce with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void effect(Event e, ItemStack item, int level) {
    EntityShootBowEvent event = (EntityShootBowEvent) e;
    event.setCancelled(true);
    event.getEntity().launchProjectile(SmallFireball.class);
}