use of org.bukkit.entity.LivingEntity in project MagicPlugin by elBukkit.
the class CureAction method perform.
@Override
public SpellResult perform(CastContext context) {
Entity entity = context.getTargetEntity();
if (entity == null || !(entity instanceof LivingEntity)) {
return SpellResult.NO_TARGET;
}
LivingEntity targetEntity = (LivingEntity) entity;
Collection<PotionEffect> currentEffects = targetEntity.getActivePotionEffects();
for (PotionEffect effect : currentEffects) {
if (negativeEffects.contains(effect.getType())) {
context.registerPotionEffects(targetEntity);
targetEntity.removePotionEffect(effect.getType());
}
}
return SpellResult.CAST;
}
use of org.bukkit.entity.LivingEntity in project MagicPlugin by elBukkit.
the class CaptureAction method perform.
@Override
public SpellResult perform(CastContext context) {
Entity targetEntity = context.getTargetEntity();
if (targetEntity instanceof Player) {
return SpellResult.NO_TARGET;
}
if (minHealth >= 0) {
if (!(targetEntity instanceof LivingEntity)) {
return SpellResult.NO_TARGET;
}
LivingEntity li = (LivingEntity) targetEntity;
if (li.getHealth() > minHealth) {
return SpellResult.NO_TARGET;
}
}
String entityTypeString = CompatibilityUtils.getEntityType(targetEntity);
if (entityTypeString == null) {
return SpellResult.FAIL;
}
Object savedEntity = CompatibilityUtils.getEntityData(targetEntity);
if (savedEntity == null) {
return SpellResult.FAIL;
}
if (targetEntity instanceof LivingEntity) {
LivingEntity li = (LivingEntity) targetEntity;
li.setHealth(li.getMaxHealth());
}
targetEntity.remove();
ItemStack spawnEgg = new ItemStack(Material.MONSTER_EGG);
String entityName = targetEntity.getCustomName();
if (entityName != null && !entityName.isEmpty()) {
ItemMeta meta = spawnEgg.getItemMeta();
meta.setDisplayName("Spawn " + entityName);
spawnEgg.setItemMeta(meta);
}
spawnEgg = InventoryUtils.makeReal(spawnEgg);
// Add entity type attribute
CompatibilityUtils.setMeta(savedEntity, "id", entityTypeString);
// Remove instance-specific attributes
CompatibilityUtils.removeMeta(savedEntity, "Pos");
CompatibilityUtils.removeMeta(savedEntity, "Motion");
CompatibilityUtils.removeMeta(savedEntity, "Rotation");
CompatibilityUtils.removeMeta(savedEntity, "FallDistance");
CompatibilityUtils.removeMeta(savedEntity, "Dimension");
CompatibilityUtils.removeMeta(savedEntity, "UUID");
CompatibilityUtils.removeMeta(savedEntity, "PortalCooldown");
if (!CompatibilityUtils.setMetaNode(spawnEgg, "EntityTag", savedEntity)) {
return SpellResult.FAIL;
}
targetEntity.getWorld().dropItemNaturally(targetEntity.getLocation(), spawnEgg);
return SpellResult.CAST;
}
use of org.bukkit.entity.LivingEntity in project Spirits by xNuminousx.
the class Infest method infestEntities.
public void infestEntities(Entity entity) {
if (new Random().nextInt(effectInt) == 0) {
if (entity instanceof Player) {
Player ePlayer = (Player) entity;
BendingPlayer bEntity = BendingPlayer.getBendingPlayer(ePlayer);
if (bEntity.hasElement(Element.getElement("DarkSpirit")) && healDarkSpirits) {
LivingEntity le = (LivingEntity) entity;
le.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 120, 1));
ParticleEffect.HEART.display(entity.getLocation().add(0, 2, 0), 0, 0, 0, 0, 1);
}
} else if (entity instanceof Monster) {
LivingEntity le = (LivingEntity) entity;
le.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 120, 1));
ParticleEffect.ANGRY_VILLAGER.display(entity.getLocation().add(0, 1, 0), 0, 0, 0, 0, 1);
} else if (entity instanceof LivingEntity && damageEntities) {
DamageHandler.damageEntity(entity, damage, this);
ParticleEffect.PORTAL.display(entity.getLocation().add(0, 1, 0), 0, 0, 0, 1.5F, 5);
}
}
}
use of org.bukkit.entity.LivingEntity in project Spirits by xNuminousx.
the class Shelter method shieldSelf.
public void shieldSelf() {
if (System.currentTimeMillis() > time + duration) {
bPlayer.addCooldown(this, selfCooldown);
remove();
return;
} else {
rotateShield(player.getLocation(), 96, selfShield);
for (Entity target : GeneralMethods.getEntitiesAroundPoint(player.getLocation(), selfShield)) {
if (target instanceof LivingEntity && !target.getUniqueId().equals(player.getUniqueId())) {
Vector vec = target.getLocation().getDirection().normalize().multiply(-selfKnockDis);
vec.setY(1);
target.setVelocity(vec);
}
}
}
}
use of org.bukkit.entity.LivingEntity in project Spirits by xNuminousx.
the class Shelter method shieldOther.
public void shieldOther() {
if (progress) {
location.add(direction.multiply(1));
progressBlast(location, 100, 0.04F);
}
for (Entity target : GeneralMethods.getEntitiesAroundPoint(location, 2)) {
if (target instanceof LivingEntity && !target.getUniqueId().equals(player.getUniqueId())) {
bPlayer.addCooldown(this, othersCooldown);
if (System.currentTimeMillis() > time + duration) {
remove();
return;
} else {
this.progress = false;
location = target.getLocation();
if (isDamaged) {
remove();
return;
}
for (Entity target2 : GeneralMethods.getEntitiesAroundPoint(location, shieldSize)) {
if (target2 instanceof LivingEntity && !target2.getUniqueId().equals(target.getUniqueId()) && !target2.getUniqueId().equals(player.getUniqueId())) {
Vector vec = target2.getLocation().getDirection().normalize().multiply(-knockDis);
vec.setY(1);
target2.setVelocity(vec);
}
}
rotateShield(location, 100, shieldSize);
}
}
}
}
Aggregations