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));
}
}
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);
}
}
}
Aggregations