use of com.elmakers.mine.bukkit.utility.Target in project MagicPlugin by elBukkit.
the class TargetingSpell method findTarget.
protected Target findTarget(CastContext context) {
Location source = getEyeLocation();
TargetType targetType = targeting.getTargetType();
boolean isBlock = targetType == TargetType.BLOCK || targetType == TargetType.SELECT;
if (!isBlock && targetEntity != null) {
return targeting.overrideTarget(context, new Target(source, targetEntity));
}
if (targetType != TargetType.SELF && targetLocation != null) {
return targeting.overrideTarget(context, new Target(source, targetLocation.getBlock()));
}
Target target = targeting.target(context, getMaxRange());
return targeting.getResult() == Targeting.TargetingResult.MISS && !allowMaxRange ? new Target(source) : target;
}
use of com.elmakers.mine.bukkit.utility.Target in project MagicPlugin by elBukkit.
the class TargetingSpell method processBlockEffects.
protected Target processBlockEffects() {
Target target = targeting.getTarget();
Target originalTarget = target;
final Block block = target.getBlock();
Double backfireAmount = currentCast.getReflective(block);
if (backfireAmount != null) {
if (random.nextDouble() < backfireAmount) {
final Entity mageEntity = mage.getEntity();
final Location location = getLocation();
final Location originLocation = block.getLocation();
Vector direction = location.getDirection();
originLocation.setDirection(direction.multiply(-1));
this.location = originLocation;
backfire();
final Collection<com.elmakers.mine.bukkit.api.effect.EffectPlayer> effects = getEffects("cast");
if (effects.size() > 0) {
Bukkit.getScheduler().runTaskLater(controller.getPlugin(), new Runnable() {
@Override
public void run() {
for (com.elmakers.mine.bukkit.api.effect.EffectPlayer player : effects) {
player.setMaterial(getEffectMaterial());
player.setColor(mage.getEffectColor());
player.start(originLocation, null, location, mageEntity);
}
}
}, 5L);
}
target = new Target(getEyeLocation(), mageEntity);
}
}
if (targetBreakables > 0 && originalTarget.isValid() && block != null && currentCast.isBreakable(block)) {
targeting.breakBlock(currentCast, block, targetBreakables);
}
return target;
}
use of com.elmakers.mine.bukkit.utility.Target in project MagicPlugin by elBukkit.
the class TargetingSpell method getTarget.
protected Target getTarget(CastContext context) {
Target target = findTarget(context);
if (instantBlockEffects) {
target = processBlockEffects();
}
if (originAtTarget && target.isValid()) {
Location previous = this.location;
if (previous == null && mage != null) {
previous = mage.getLocation();
}
location = target.getLocation().clone();
if (previous != null) {
location.setPitch(previous.getPitch());
location.setYaw(previous.getYaw());
}
}
Entity targetEntity = target != null ? target.getEntity() : null;
Location targetLocation = target != null ? target.getLocation() : null;
context.setTargetLocation(targetLocation);
context.setTargetEntity(targetEntity);
return target;
}
use of com.elmakers.mine.bukkit.utility.Target in project MagicPlugin by elBukkit.
the class TargetingSpell method getMessage.
@Override
public String getMessage(String messageKey, String def) {
String message = super.getMessage(messageKey, def);
// Escape targeting parameters
String useTargetName = null;
if (currentCast != null) {
useTargetName = currentCast.getTargetName();
}
if (useTargetName == null) {
Target target = targeting.getTarget();
if (target != null) {
if (target.hasEntity() && getTargetType() != TargetType.BLOCK) {
useTargetName = controller.getEntityDisplayName(target.getEntity());
} else if (target.isValid() && getTargetType() != TargetType.OTHER_ENTITY && getTargetType() != TargetType.ANY_ENTITY) {
MaterialAndData material = target.getTargetedMaterial();
if (material != null) {
useTargetName = material.getName();
}
}
}
}
if (useTargetName == null) {
message = message.replace("$target", "Nothing");
} else {
message = message.replace("$target", useTargetName);
}
return message;
}
use of com.elmakers.mine.bukkit.utility.Target in project MagicPlugin by elBukkit.
the class TargetingSpell method getEffectMaterial.
@Nullable
@Override
public com.elmakers.mine.bukkit.api.block.MaterialAndData getEffectMaterial() {
Target target = targeting.getTarget();
if (target != null && target.isValid()) {
Block block = target.getBlock();
MaterialAndData targetMaterial = new MaterialAndData(block);
if (targetMaterial.getMaterial() == Material.AIR) {
targetMaterial.setMaterial(DEFAULT_EFFECT_MATERIAL);
}
return targetMaterial;
}
return super.getEffectMaterial();
}
Aggregations