use of org.bukkit.entity.LivingEntity in project MagicPlugin by elBukkit.
the class MageTrigger method execute.
public void execute(Mage mage, double damage) {
if (minDamage > 0 && damage < minDamage)
return;
if (maxDamage > 0 && damage > maxDamage)
return;
LivingEntity li = mage.getLivingEntity();
if (minHealth > 0 && (li == null || li.getHealth() < minHealth))
return;
if (maxHealth > 0 && (li == null || li.getHealth() > maxHealth))
return;
if (minHealthPercentage > 0 && (li == null || li.getHealth() * 100 / li.getMaxHealth() < minHealthPercentage))
return;
if (maxHealthPercentage > 0 && (li == null || li.getHealth() * 100 / li.getMaxHealth() > maxHealthPercentage))
return;
if (spells != null && !spells.isEmpty()) {
String deathSpell = RandomUtils.weightedRandom(spells);
cast(mage, deathSpell);
}
if (commands != null) {
Entity topDamager = mage.getTopDamager();
Entity killer = mage.getLastDamager();
Collection<Entity> damagers = mage.getDamagers();
Location location = mage.getLocation();
for (String command : commands) {
if (command.contains("@killer")) {
if (killer == null)
continue;
command = command.replace("@killer", killer.getName());
}
if (command.contains("@damager")) {
if (topDamager == null)
continue;
command = command.replace("@damager", topDamager.getName());
}
boolean allDamagers = command.contains("@damagers");
if (allDamagers && damagers == null) {
continue;
}
command = command.replace("@name", mage.getName()).replace("@world", location.getWorld().getName()).replace("@x", Double.toString(location.getX())).replace("@y", Double.toString(location.getY())).replace("@z", Double.toString(location.getZ()));
if (allDamagers) {
for (Entity damager : damagers) {
String damagerCommand = command.replace("@damagers", damager.getName());
mage.getController().getPlugin().getServer().dispatchCommand(Bukkit.getConsoleSender(), damagerCommand);
}
} else {
mage.getController().getPlugin().getServer().dispatchCommand(Bukkit.getConsoleSender(), command);
}
}
}
}
use of org.bukkit.entity.LivingEntity in project MagicPlugin by elBukkit.
the class Mage method setLocation.
@Override
public void setLocation(Location location) {
LivingEntity entity = getLivingEntity();
if (entity != null && location != null) {
entity.teleport(location);
return;
}
this.location = location;
}
use of org.bukkit.entity.LivingEntity in project MagicPlugin by elBukkit.
the class Mage method updatePassiveEffects.
protected void updatePassiveEffects() {
protection.clear();
strength.clear();
weakness.clear();
attributes.clear();
spMultiplier = 1;
cooldownReduction = 0;
costReduction = 0;
consumeReduction = 0;
List<PotionEffectType> currentEffects = new ArrayList<>(effectivePotionEffects.keySet());
LivingEntity entity = getLivingEntity();
effectivePotionEffects.clear();
addPassiveEffects(properties, true);
if (activeClass != null) {
addPassiveEffects(activeClass, true);
spMultiplier = (float) (spMultiplier * activeClass.getDouble("sp_multiplier", 1.0));
}
if (activeWand != null && !activeWand.isPassive()) {
addPassiveEffects(activeWand, false);
effectivePotionEffects.putAll(activeWand.getPotionEffects());
}
// Don't add these together so things stay balanced!
if (offhandWand != null && !offhandWand.isPassive()) {
addPassiveEffects(offhandWand, false);
effectivePotionEffects.putAll(offhandWand.getPotionEffects());
spMultiplier *= offhandWand.getSPMultiplier();
}
for (Wand armorWand : activeArmor.values()) {
if (armorWand != null) {
addPassiveEffects(armorWand, false);
effectivePotionEffects.putAll(armorWand.getPotionEffects());
}
}
if (entity != null) {
for (PotionEffectType effectType : currentEffects) {
if (!effectivePotionEffects.containsKey(effectType)) {
entity.removePotionEffect(effectType);
}
}
for (Map.Entry<PotionEffectType, Integer> effects : effectivePotionEffects.entrySet()) {
PotionEffect effect = new PotionEffect(effects.getKey(), Integer.MAX_VALUE, effects.getValue(), true, false);
CompatibilityUtils.applyPotionEffect(entity, effect);
}
}
}
use of org.bukkit.entity.LivingEntity in project MagicPlugin by elBukkit.
the class Mage method setTarget.
private void setTarget(Entity target) {
if (entityData != null && !entityData.shouldFocusOnDamager())
return;
LivingEntity li = getLivingEntity();
if (li != null && li instanceof Creature && target instanceof LivingEntity) {
Creature creature = ((Creature) li);
if (creature.getTarget() != target) {
sendDebugMessage("Now targeting " + target.getName(), 6);
}
creature.setTarget((LivingEntity) target);
}
}
use of org.bukkit.entity.LivingEntity in project MagicPlugin by elBukkit.
the class SourceLocation method getLocation.
@Nullable
public Location getLocation(CastContext context) {
Mage mage;
Location eyeLocation;
Location feetLocation;
if (isSource) {
mage = context.getMage();
eyeLocation = context.getEyeLocation();
feetLocation = context.getLocation();
} else {
Entity targetEntity = context.getTargetEntity();
if (targetEntity == null) {
mage = null;
feetLocation = context.getTargetLocation();
eyeLocation = context.getTargetLocation();
} else {
mage = context.getController().getRegisteredMage(targetEntity);
feetLocation = targetEntity.getLocation();
eyeLocation = targetEntity instanceof LivingEntity ? ((LivingEntity) targetEntity).getEyeLocation() : targetEntity.getLocation();
}
}
if (mage == null && (locationType == LocationType.CAST || locationType == LocationType.WAND)) {
locationType = LocationType.EYES;
}
Location location = null;
switch(locationType) {
case CAST:
if (isSource) {
location = context.getCastLocation();
} else {
location = mage.getCastLocation();
}
break;
case EYES:
location = eyeLocation;
break;
case FEET:
location = feetLocation;
break;
case WAND:
if (isSource) {
location = context.getWandLocation();
} else {
location = mage.getWandLocation();
}
break;
case BODY:
if (eyeLocation != null && feetLocation != null) {
location = eyeLocation.clone().add(feetLocation).multiply(0.5);
}
break;
case HIT:
location = context.getTargetLocation();
break;
case BLOCK:
if (feetLocation != null) {
location = feetLocation.getBlock().getLocation();
}
break;
}
if (location == null) {
location = feetLocation;
}
Location targetLocation = isSource ? context.getTargetLocation() : context.getLocation();
if (orientToTarget && targetLocation != null && location != null) {
Vector direction = targetLocation.toVector().subtract(location.toVector()).normalize();
if (MathUtils.isFinite(direction.getX()) && MathUtils.isFinite(direction.getY()) && MathUtils.isFinite(direction.getZ())) {
location.setDirection(direction);
}
}
return location;
}
Aggregations