Search in sources :

Example 1 with ThrownPotion

use of org.bukkit.entity.ThrownPotion in project InfernalMobs by NyaaCat.

the class AbilityPotions method onPlayerAttack.

@Override
public void onPlayerAttack(LivingEntity mobEntity, Mob mob, Player attacker, boolean isDirectAttack, EntityDamageByEntityEvent ev) {
    if (Helper.possibility(0.3))
        return;
    Vector velocity = attacker.getEyeLocation().toVector().subtract(mobEntity.getEyeLocation().toVector());
    velocity.multiply(1D / 15D);
    velocity.add(new Vector(0, 0.2, 0));
    ThrownPotion t = mobEntity.launchProjectile(ThrownPotion.class, velocity);
    ItemStack item = new ItemStack(Material.SPLASH_POTION);
    PotionMeta pm = (PotionMeta) item.getItemMeta();
    PotionEffect effect = Helper.randomItem(POTION_EFFECTS);
    pm.addCustomEffect(effect, false);
    pm.setColor(effect.getColor());
    item.setItemMeta(pm);
    t.setItem(item);
}
Also used : PotionEffect(org.bukkit.potion.PotionEffect) ThrownPotion(org.bukkit.entity.ThrownPotion) PotionMeta(org.bukkit.inventory.meta.PotionMeta) ItemStack(org.bukkit.inventory.ItemStack) Vector(org.bukkit.util.Vector)

Example 2 with ThrownPotion

use of org.bukkit.entity.ThrownPotion in project Ublisk by Derkades.

the class PlayerInteract method spellTest.

@EventHandler(priority = EventPriority.MONITOR)
public void spellTest(PlayerInteractEvent event) {
    if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
        if (event.getPlayer().getInventory().getItemInMainHand().getType() == Material.BLAZE_ROD) {
            final Block block = event.getClickedBlock();
            if (block.getType() == Material.COBBLESTONE) {
                @SuppressWarnings("deprecation") FallingBlock fall = block.getWorld().spawnFallingBlock(block.getLocation(), block.getType(), block.getData());
                Vector velocity = fall.getVelocity();
                velocity.setY(velocity.getY() + 1.0);
                fall.setVelocity(velocity);
                block.setType(Material.AIR);
                Bukkit.getScheduler().scheduleSyncDelayedTask(Main.getInstance(), new Runnable() {

                    public void run() {
                        Location loc = block.getLocation();
                        loc.setY(loc.getY() + 1);
                        ThrownPotion potion = (ThrownPotion) Var.WORLD.spawnEntity(loc, EntityType.SPLASH_POTION);
                        PotionEffect effect = new PotionEffect(PotionEffectType.HARM, 1, 2);
                        potion.getEffects().add(effect);
                    }
                }, 2 * 20);
            }
        }
    }
}
Also used : FallingBlock(org.bukkit.entity.FallingBlock) PotionEffect(org.bukkit.potion.PotionEffect) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) URunnable(xyz.derkades.ublisk.utils.URunnable) Block(org.bukkit.block.Block) FallingBlock(org.bukkit.entity.FallingBlock) ThrownPotion(org.bukkit.entity.ThrownPotion) Vector(org.bukkit.util.Vector) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 3 with ThrownPotion

use of org.bukkit.entity.ThrownPotion in project Denizen-For-Bukkit by DenizenScript.

the class EntityPotion method getPotion.

public ItemStack getPotion() {
    if (entity.getBukkitEntity() instanceof ThrownPotion) {
        return ((ThrownPotion) entity.getBukkitEntity()).getItem();
    } else {
        // Tipped arrow
        ItemStack refItem = new ItemStack(Material.POTION);
        PotionMeta meta = (PotionMeta) refItem.getItemMeta();
        meta.setBasePotionData(((Arrow) entity.getBukkitEntity()).getBasePotionData());
        refItem.setItemMeta(meta);
        return refItem;
    }
}
Also used : ThrownPotion(org.bukkit.entity.ThrownPotion) PotionMeta(org.bukkit.inventory.meta.PotionMeta) ItemStack(org.bukkit.inventory.ItemStack)

Example 4 with ThrownPotion

use of org.bukkit.entity.ThrownPotion in project InfernalMobs by NyaaCat.

the class AbilityPotions method onPlayerAttack.

@Override
public void onPlayerAttack(LivingEntity mobEntity, Mob mob, Player attacker, boolean isDirectAttack, EntityDamageByEntityEvent ev) {
    if (Helper.possibility(0.3))
        return;
    Vector velocity = attacker.getEyeLocation().toVector().subtract(mobEntity.getEyeLocation().toVector());
    velocity.multiply(1D / 15D);
    velocity.add(new Vector(0, 0.2, 0));
    ThrownPotion t = mobEntity.launchProjectile(ThrownPotion.class, velocity);
    ItemStack item = new ItemStack(Material.SPLASH_POTION);
    PotionMeta pm = (PotionMeta) item.getItemMeta();
    PotionEffectWithColor effect = Helper.randomItem(POTION_EFFECTS);
    pm.addCustomEffect(effect.effect, false);
    pm.setColor(effect.color);
    item.setItemMeta(pm);
    t.setItem(item);
}
Also used : ThrownPotion(org.bukkit.entity.ThrownPotion) PotionMeta(org.bukkit.inventory.meta.PotionMeta) ItemStack(org.bukkit.inventory.ItemStack) Vector(org.bukkit.util.Vector)

Example 5 with ThrownPotion

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

the class CompatibilityUtils method magicDamage.

public static void magicDamage(Damageable target, double amount, Entity source) {
    try {
        if (target == null || target.isDead())
            return;
        if (class_EntityLiving_damageEntityMethod == null || object_magicSource == null || class_DamageSource_getMagicSourceMethod == null) {
            damage(target, amount, source);
            return;
        }
        // Might need to config-drive this, or just go back to defaulting to normal damage
        if (!USE_MAGIC_DAMAGE || target instanceof Witch || target instanceof Enderman || target instanceof ArmorStand || !(target instanceof LivingEntity)) {
            damage(target, amount, source);
            return;
        }
        Object targetHandle = getHandle(target);
        if (targetHandle == null)
            return;
        isDamaging = true;
        Object sourceHandle = getHandle(source);
        // Bukkit won't allow magic damage from anything but a potion..
        if (sourceHandle != null && source instanceof LivingEntity) {
            ThrownPotion potion = potionReference == null ? null : potionReference.get();
            Location location = target.getLocation();
            if (potion == null) {
                potion = (ThrownPotion) location.getWorld().spawnEntity(location, EntityType.SPLASH_POTION);
                potion.remove();
                potionReference = new WeakReference<>(potion);
            }
            potion.teleport(location);
            potion.setShooter((LivingEntity) source);
            Object potionHandle = getHandle(potion);
            Object damageSource = class_DamageSource_getMagicSourceMethod.invoke(null, potionHandle, sourceHandle);
            // of various non-living entity pieces.
            if (class_EntityDamageSource_setThornsMethod != null) {
                class_EntityDamageSource_setThornsMethod.invoke(damageSource);
            }
            class_EntityLiving_damageEntityMethod.invoke(targetHandle, damageSource, (float) amount);
        } else {
            class_EntityLiving_damageEntityMethod.invoke(targetHandle, object_magicSource, (float) amount);
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    isDamaging = false;
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) ComplexLivingEntity(org.bukkit.entity.ComplexLivingEntity) ArmorStand(org.bukkit.entity.ArmorStand) Enderman(org.bukkit.entity.Enderman) ThrownPotion(org.bukkit.entity.ThrownPotion) Witch(org.bukkit.entity.Witch) FileNotFoundException(java.io.FileNotFoundException) InvalidConfigurationException(org.bukkit.configuration.InvalidConfigurationException) IOException(java.io.IOException) Location(org.bukkit.Location)

Aggregations

ThrownPotion (org.bukkit.entity.ThrownPotion)7 ItemStack (org.bukkit.inventory.ItemStack)4 PotionMeta (org.bukkit.inventory.meta.PotionMeta)4 PotionEffect (org.bukkit.potion.PotionEffect)4 Vector (org.bukkit.util.Vector)4 Location (org.bukkit.Location)2 LivingEntity (org.bukkit.entity.LivingEntity)2 EventHandler (org.bukkit.event.EventHandler)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 List (java.util.List)1 Block (org.bukkit.block.Block)1 InvalidConfigurationException (org.bukkit.configuration.InvalidConfigurationException)1 ArmorStand (org.bukkit.entity.ArmorStand)1 ComplexLivingEntity (org.bukkit.entity.ComplexLivingEntity)1 Enderman (org.bukkit.entity.Enderman)1 Entity (org.bukkit.entity.Entity)1 FallingBlock (org.bukkit.entity.FallingBlock)1 Witch (org.bukkit.entity.Witch)1 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)1