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