use of org.bukkit.entity.LivingEntity in project MagicPlugin by elBukkit.
the class FlingSpell method onCast.
@Override
public SpellResult onCast(ConfigurationSection parameters) {
int height = 0;
Block playerBlock = getLocation().getBlock();
LivingEntity entity = mage.getLivingEntity();
if (entity == null) {
return SpellResult.LIVING_ENTITY_REQUIRED;
}
int maxSpeedAtElevation = parameters.getInt("cruising_altitude", defaultMaxSpeedAtElevation);
double minMagnitude = parameters.getDouble("min_speed", defaultMinMagnitude);
double maxMagnitude = parameters.getDouble("max_speed", defaultMaxMagnitude);
safetyLength = parameters.getLong("safety", safetyLength);
while (height < maxSpeedAtElevation && playerBlock.getType() == Material.AIR) {
playerBlock = playerBlock.getRelative(BlockFace.DOWN);
height++;
}
double heightModifier = maxSpeedAtElevation > 0 ? ((double) height / maxSpeedAtElevation) : 1;
double magnitude = (minMagnitude + ((maxMagnitude - minMagnitude) * heightModifier));
Vector velocity = getDirection();
if (mage.getLocation().getBlockY() >= 256) {
velocity.setY(0);
}
velocity.multiply(magnitude);
registerVelocity(entity);
registerMoved(entity);
SafetyUtils.setVelocity(entity, velocity);
if (safetyLength > 0) {
mage.registerEvent(SpellEventType.PLAYER_DAMAGE, this);
}
lastFling = System.currentTimeMillis();
registerForUndo();
return SpellResult.CAST;
}
use of org.bukkit.entity.LivingEntity in project MagicPlugin by elBukkit.
the class ForceSpell method onCast.
@Override
public SpellResult onCast(ConfigurationSection parameters) {
effectColor = mage.getEffectColor();
if (effectColor == null) {
effectColor = Color.fromRGB(Integer.parseInt(parameters.getString("effect_color", "FF0000"), 16));
}
if (targetEntity != null) {
Location location = getLocation();
World targetWorld = targetEntity.getWorld();
if (!targetEntity.isValid() || targetEntity.isDead()) {
releaseTarget();
} else if (targetWorld == null || location == null || !targetWorld.getName().equals(location.getWorld().getName())) {
releaseTarget();
} else if (location.distanceSquared(targetEntity.getLocation()) > getMaxRangeSquared()) {
releaseTarget();
}
// Check for protected Mages
if (targetEntity != null && controller.isMage(targetEntity)) {
Mage targetMage = controller.getMage(targetEntity);
// Check for protected players (admins, generally...)
if (isSuperProtected(targetMage)) {
releaseTarget();
}
}
}
if (targetEntity == null) {
Target target = getTarget();
if (!target.hasEntity() || !(target.getEntity() instanceof LivingEntity)) {
return SpellResult.NO_TARGET;
}
releaseTarget();
LivingEntity checkTarget = (LivingEntity) target.getEntity();
// Check for protected Mages
if (checkTarget != null && controller.isMage(checkTarget)) {
Mage targetMage = controller.getMage(checkTarget);
// Check for protected players
if (isSuperProtected(targetMage)) {
return SpellResult.NO_TARGET;
}
}
selectTarget(checkTarget);
activate();
return SpellResult.TARGET_SELECTED;
}
double multiplier = parameters.getDouble("size", 1);
int magnitude = parameters.getInt("entity_force", DEFAULT_MAGNITUDE);
forceEntity(targetEntity, multiplier, magnitude);
return SpellResult.CAST;
}
use of org.bukkit.entity.LivingEntity in project MagicPlugin by elBukkit.
the class GrowSpell method onCast.
@Override
public SpellResult onCast(ConfigurationSection parameters) {
Target target = getTarget();
if (!target.hasEntity()) {
return SpellResult.NO_TARGET;
}
Entity targetEntity = target.getEntity();
if (controller.isElemental(targetEntity)) {
double elementalSize = controller.getElementalScale(targetEntity);
elementalSize *= 1.2;
controller.setElementalScale(targetEntity, elementalSize);
return SpellResult.CAST;
}
if (!(targetEntity instanceof LivingEntity))
return SpellResult.NO_TARGET;
LivingEntity li = (LivingEntity) targetEntity;
if (li instanceof Ageable && !((Ageable) li).isAdult() && !(li instanceof Player)) {
registerModified(li);
((Ageable) li).setAdult();
} else if (li instanceof Zombie) {
registerModified(li);
Zombie zombie = (Zombie) li;
if (!zombie.isBaby()) {
UndoList spawnedList = com.elmakers.mine.bukkit.block.UndoList.getUndoList(li);
Location targetLocation = li.getLocation();
li.remove();
Entity giant = targetLocation.getWorld().spawnEntity(targetLocation, EntityType.GIANT);
registerForUndo(giant);
if (spawnedList != null) {
spawnedList.add(giant);
}
} else {
((Zombie) li).setBaby(false);
}
} else if (li instanceof PigZombie && ((PigZombie) li).isBaby()) {
registerModified(li);
((PigZombie) li).setBaby(false);
} else if (li instanceof Slime) {
registerModified(li);
Slime slime = (Slime) li;
slime.setSize(slime.getSize() + 1);
} else {
return SpellResult.NO_TARGET;
}
registerForUndo();
return SpellResult.CAST;
}
use of org.bukkit.entity.LivingEntity in project MagicPlugin by elBukkit.
the class CastContext method messageTargets.
@Override
public void messageTargets(String messageKey) {
Mage mage = getMage();
if (mage.isStealth())
return;
Collection<Entity> targets = getTargetedEntities();
if (targets == null || targets.isEmpty())
return;
MageController controller = getController();
LivingEntity sourceEntity = mage.getLivingEntity();
String playerMessage = getMessage(messageKey);
if (playerMessage.length() > 0) {
playerMessage = playerMessage.replace("$spell", spell.getName());
for (Entity target : targets) {
UUID targetUUID = target.getUniqueId();
if (target instanceof Player && target != sourceEntity && !targetMessagesSent.contains(targetUUID)) {
targetMessagesSent.add(targetUUID);
Mage targetMage = controller.getRegisteredMage(target);
if (targetMage != null) {
targetMage.sendMessage(playerMessage);
}
}
}
}
}
use of org.bukkit.entity.LivingEntity in project MagicPlugin by elBukkit.
the class AggroAction method perform.
@Override
public SpellResult perform(CastContext context) {
Entity target = context.getTargetEntity();
if (!(target instanceof Creature)) {
return SpellResult.NO_TARGET;
}
LivingEntity source = context.getLivingEntity();
if (source == null) {
return SpellResult.NO_TARGET;
}
Creature creatureTarget = (Creature) target;
LivingEntity current = creatureTarget.getTarget();
if (source == current) {
return SpellResult.NO_ACTION;
}
((Creature) target).setTarget(source);
return SpellResult.CAST;
}
Aggregations