Search in sources :

Example 6 with ThrownPotion

use of org.bukkit.entity.ThrownPotion in project EliteMobs by MagmaGuy.

the class EnderDragonPotionBombardment method taskBehavior.

@Override
public void taskBehavior(EliteEntity eliteEntity) {
    for (int i = 0; i < 5; i++) {
        ItemStack itemStack = new ItemStack(Material.SPLASH_POTION);
        PotionMeta potionMeta = (PotionMeta) itemStack.getItemMeta();
        if (ThreadLocalRandom.current().nextBoolean())
            potionMeta.addCustomEffect(new PotionEffect(PotionEffectType.HARM, 0, 1), true);
        else
            potionMeta.addCustomEffect(new PotionEffect(PotionEffectType.SLOW, 0, 1), true);
        itemStack.setItemMeta(potionMeta);
        ThrownPotion thrownPotion = (ThrownPotion) eliteEntity.getLivingEntity().getWorld().spawnEntity(eliteEntity.getLivingEntity().getLocation().clone().subtract(new Vector(ThreadLocalRandom.current().nextInt(-1, 1), 1, ThreadLocalRandom.current().nextInt(-1, 1))), EntityType.SPLASH_POTION);
        thrownPotion.setItem(itemStack);
        thrownPotion.setVelocity(new Vector(ThreadLocalRandom.current().nextDouble() - 0.5, 0, ThreadLocalRandom.current().nextDouble() - 0.5));
    }
}
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 7 with ThrownPotion

use of org.bukkit.entity.ThrownPotion in project Towny by ElgarL.

the class TownyEntityListener method onPotionSplashEvent.

/**
 * Prevent potion damage on players in non PVP areas
 *
 * @param event
 */
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onPotionSplashEvent(PotionSplashEvent event) {
    List<LivingEntity> affectedEntities = (List<LivingEntity>) event.getAffectedEntities();
    ThrownPotion potion = event.getPotion();
    Entity attacker;
    List<PotionEffect> effects = (List<PotionEffect>) potion.getEffects();
    boolean detrimental = false;
    /*
		 * List of potion effects blocked from PvP.
		 */
    List<String> prots = TownySettings.getPotionTypes();
    for (PotionEffect effect : effects) {
        if (prots.contains(effect.getType().getName())) {
            detrimental = true;
        }
    }
    Object source = potion.getShooter();
    if (!(source instanceof Entity)) {
        // TODO: prevent damage from dispensers
        return;
    } else {
        attacker = (Entity) source;
    }
    // Not Wartime
    if (!TownyUniverse.isWarTime())
        for (LivingEntity defender : affectedEntities) {
            /*
				 * Don't block potion use on ourselves
				 * yet allow the use of beneficial potions on all.
				 */
            if (attacker != defender)
                if (CombatUtil.preventDamageCall(plugin, attacker, defender) && detrimental) {
                    event.setIntensity(defender, -1.0);
                }
        }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) PotionEffect(org.bukkit.potion.PotionEffect) ThrownPotion(org.bukkit.entity.ThrownPotion) List(java.util.List) EventHandler(org.bukkit.event.EventHandler)

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