use of org.bukkit.entity.Witch 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;
}
use of org.bukkit.entity.Witch in project Glowstone by GlowstoneMC.
the class GlowVillager method damage.
@Override
public void damage(double amount, Entity source, @NotNull DamageCause cause) {
if (!DamageCause.LIGHTNING.equals(cause)) {
super.damage(amount, source, cause);
return;
}
Witch witch = world.spawn(this.location, Witch.class);
witch.damage(amount, source, cause);
witch.setFireTicks(this.getFireTicks());
remove();
}
Aggregations