use of org.bukkit.craftbukkit.v1_8_R2.entity.CraftEntity in project MagicPlugin by elBukkit.
the class CompatibilityUtils method damage.
@Override
public void damage(Damageable target, double amount, Entity source, String damageType) {
if (target == null || target.isDead())
return;
if (damageType.equalsIgnoreCase("direct")) {
double health = target.getHealth() - amount;
target.setHealth(Math.max(health, 0));
return;
}
if (damageType.equalsIgnoreCase("magic")) {
magicDamage(target, amount, source);
return;
}
DamageSource damageSource = getDamageSource(damageType);
if (damageSource == null) {
magicDamage(target, amount, source);
return;
}
net.minecraft.world.entity.Entity targetHandle = ((CraftEntity) target).getHandle();
if (targetHandle == null)
return;
try (EnteredStateTracker.Touchable damaging = isDamaging.enter()) {
damaging.touch();
targetHandle.hurt(damageSource, (float) amount);
} catch (Exception ex) {
ex.printStackTrace();
}
}
use of org.bukkit.craftbukkit.v1_8_R2.entity.CraftEntity in project MagicPlugin by elBukkit.
the class CompatibilityUtils method setEntityMotion.
@Override
public void setEntityMotion(Entity entity, Vector motion) {
net.minecraft.world.entity.Entity nms = ((CraftEntity) entity).getHandle();
nms.setDeltaMovement(new Vec3(motion.getX(), motion.getY(), motion.getZ()));
}
use of org.bukkit.craftbukkit.v1_8_R2.entity.CraftEntity in project MagicPlugin by elBukkit.
the class CompatibilityUtils method addToWorld.
@Override
public boolean addToWorld(World world, Entity entity, CreatureSpawnEvent.SpawnReason reason) {
ServerLevel level = ((CraftWorld) world).getHandle();
net.minecraft.world.entity.Entity entityHandle = ((CraftEntity) entity).getHandle();
level.addFreshEntity(entityHandle, reason);
return true;
}
use of org.bukkit.craftbukkit.v1_8_R2.entity.CraftEntity in project MagicPlugin by elBukkit.
the class CompatibilityUtils method magicDamage.
@Override
public void magicDamage(Damageable target, double amount, Entity source) {
try {
if (target == null || target.isDead())
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;
}
net.minecraft.world.entity.Entity targetHandle = ((CraftEntity) target).getHandle();
if (targetHandle == null)
return;
net.minecraft.world.entity.Entity sourceHandle = source == null ? null : ((CraftEntity) source).getHandle();
// Bukkit won't allow magic damage from anything but a potion..
if (sourceHandle != null && source instanceof LivingEntity) {
Location location = target.getLocation();
ThrownPotion potion = getOrCreatePotionEntity(location);
net.minecraft.world.entity.Entity potionHandle = ((CraftEntity) potion).getHandle();
potion.setShooter((LivingEntity) source);
DamageSource magicSource = DamageSource.indirectMagic(potionHandle, sourceHandle);
// This is a bit of hack that lets us damage the ender dragon, who is a weird and annoying collection
// of various non-living entity pieces.
((EntityDamageSource) magicSource).setThorns();
try (EnteredStateTracker.Touchable damaging = isDamaging.enter()) {
damaging.touch();
targetHandle.hurt(magicSource, (float) amount);
}
} else {
try (EnteredStateTracker.Touchable damaging = isDamaging.enter()) {
damaging.touch();
targetHandle.hurt(DamageSource.MAGIC, (float) amount);
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
use of org.bukkit.craftbukkit.v1_8_R2.entity.CraftEntity in project MagicPlugin by elBukkit.
the class CompatibilityUtils method setEntityMotion.
@Override
public void setEntityMotion(Entity entity, Vector motion) {
net.minecraft.world.entity.Entity nms = ((CraftEntity) entity).getHandle();
nms.setDeltaMovement(new Vec3(motion.getX(), motion.getY(), motion.getZ()));
}
Aggregations