use of com.elmakers.mine.bukkit.api.spell.SpellResult in project MagicPlugin by elBukkit.
the class ArmorStandProjectileAction method step.
@Override
public SpellResult step(CastContext context) {
SpellResult result = super.step(context);
if (entity == null) {
return SpellResult.FAIL;
}
ArmorStand armorStand = (ArmorStand) entity;
update(armorStand);
if (stepCount == visibleDelayTicks) {
armorStand.setItemInHand(rightArmItem);
armorStand.setHelmet(helmetItem);
armorStand.setChestplate(chestplateItem);
armorStand.setLeggings(leggingsItem);
armorStand.setBoots(bootsItem);
}
stepCount++;
return result;
}
use of com.elmakers.mine.bukkit.api.spell.SpellResult in project MagicPlugin by elBukkit.
the class BaseProjectileAction method step.
@Override
public SpellResult step(CastContext context) {
if (tracking == null || tracking.size() == 0) {
tracking = null;
return SpellResult.CAST;
}
if (System.currentTimeMillis() > expiration) {
for (Entity entity : tracking) {
entity.removeMetadata("track", context.getPlugin());
entity.removeMetadata("damaged", context.getPlugin());
entity.removeMetadata("hit", context.getPlugin());
entity.remove();
}
context.getMage().sendDebugMessage(ChatColor.DARK_GRAY + "Projectiles expired", 4);
tracking = null;
return SpellResult.NO_TARGET;
}
for (Entity entity : tracking) {
if (!entity.isValid() || entity.hasMetadata("hit")) {
tracking.remove(entity);
Plugin plugin = context.getPlugin();
Entity targetEntity = null;
Block targetBlock = null;
Location targetLocation = entity.getLocation();
List<MetadataValue> metadata = entity.getMetadata("hit");
for (MetadataValue value : metadata) {
if (value.getOwningPlugin().equals(plugin)) {
Object o = value.value();
if (o != null && o instanceof WeakReference) {
WeakReference<?> reference = (WeakReference<?>) o;
o = reference.get();
if (o != null && o instanceof Entity) {
targetEntity = (Entity) o;
targetLocation = targetEntity.getLocation();
}
break;
} else if (o != null && o instanceof Block) {
targetBlock = (Block) o;
break;
}
}
}
entity.removeMetadata("track", plugin);
if (targetEntity == null) {
context.getMage().sendDebugMessage(ChatColor.GRAY + "Projectile missed", 4);
} else {
context.getMage().sendDebugMessage(ChatColor.GREEN + "Projectile hit " + ChatColor.GOLD + targetEntity.getType());
}
entity.removeMetadata("hit", plugin);
Location sourceLocation = entity.getLocation();
// So.. projectile X direction is backwards. See: https://hub.spigotmc.org/jira/browse/SPIGOT-3867
// The direction of the entity is adjusted to account for the orientation of the models.
// I'm using the fix suggested by md_5, which is to use the velocity rather than orientation.
// This feels cleaner than inverting the x-component of direction, just in case Mojang ever
// fixes this issue.
Vector direction = entity.getVelocity().normalize();
sourceLocation.setDirection(direction);
if (targetBlock != null) {
// If we have a target block, try to approximate the hit location but ensure that it's on the edge of the block.
// This makes this appear similar to how raycast targeting would work
context.getMage().sendDebugMessage(ChatColor.GREEN + "Projectile at " + TextUtils.printLocation(entity.getLocation()) + ChatColor.GREEN + " hit block at " + TextUtils.printBlock(targetBlock) + " facing " + TextUtils.printVector(sourceLocation.getDirection()), 13);
// Set previous location, this is mainly so the Teleport action works right.
context.setPreviousBlock(sourceLocation.getBlock());
targetLocation = targetBlock.getLocation();
// raycast from entity through block
Vector startPoint = sourceLocation.toVector();
Vector endPoint = startPoint.clone().add(direction.clone().normalize().multiply(2));
BoundingBox hitbox = new BoundingBox(targetLocation.toVector(), 0.001, 0.998, 0.001, 0.998, 0.001, 0.998);
Vector hit = hitbox.getIntersection(startPoint, endPoint);
if (hit != null) {
targetLocation.setX(hit.getX());
targetLocation.setY(hit.getY());
targetLocation.setZ(hit.getZ());
}
} else {
context.getMage().sendDebugMessage(ChatColor.GRAY + "Projectile hit at " + TextUtils.printLocation(entity.getLocation()) + " facing " + TextUtils.printVector(sourceLocation.getDirection()), 132);
}
createActionContext(context, context.getMage().getEntity(), sourceLocation, targetEntity, targetLocation);
actionContext.playEffects("hit");
SpellResult result = startActions();
if (targetEntity != null) {
result = result.min(SpellResult.CAST);
} else {
result = result.min(SpellResult.NO_TARGET);
}
context.addResult(result);
return result;
}
}
return SpellResult.PENDING;
}
use of com.elmakers.mine.bukkit.api.spell.SpellResult in project MagicPlugin by elBukkit.
the class CancelAction method perform.
@Override
public SpellResult perform(CastContext context) {
Entity targetEntity = context.getTargetEntity();
MageController controller = context.getController();
if (targetEntity == null || !controller.isMage(targetEntity)) {
return SpellResult.NO_TARGET;
}
SpellResult result = SpellResult.NO_TARGET;
Mage targetMage = controller.getMage(targetEntity);
if (spellKeys == null) {
Batch batch = targetMage.cancelPending(force);
if (batch != null) {
result = SpellResult.CAST;
undoListName = batch.getName();
}
} else {
for (String spellKey : spellKeys) {
Batch batch = targetMage.cancelPending(spellKey, force);
if (batch != null) {
result = SpellResult.CAST;
undoListName = batch.getName();
}
}
}
return result;
}
use of com.elmakers.mine.bukkit.api.spell.SpellResult in project MagicPlugin by elBukkit.
the class UndoSpell method onCast.
@Override
public SpellResult onCast(ConfigurationSection parameters) {
Target target = getTarget();
int timeout = parameters.getInt("target_timeout", 0);
boolean targetSelf = parameters.getBoolean("target_up_self", false);
boolean targetDown = parameters.getBoolean("target_down_block", false);
Entity targetEntity = target.getEntity();
SpellResult result = SpellResult.CAST;
if (targetSelf && isLookingUp()) {
targetEntity = mage.getEntity();
getCurrentCast().setTargetName(mage.getName());
result = SpellResult.ALTERNATE_UP;
}
if (targetEntity != null && controller.isMage(targetEntity)) {
Mage targetMage = controller.getMage(targetEntity);
Batch batch = targetMage.cancelPending();
if (batch != null) {
undoListName = (batch instanceof SpellBatch) ? ((SpellBatch) batch).getSpell().getName() : null;
return SpellResult.ALTERNATE;
}
UndoQueue queue = targetMage.getUndoQueue();
UndoList undoList = queue.undoRecent(timeout);
if (undoList != null) {
undoListName = undoList.getName();
}
return undoList != null ? result : SpellResult.NO_TARGET;
}
if (!parameters.getBoolean("target_blocks", true)) {
return SpellResult.NO_TARGET;
}
Block targetBlock = target.getBlock();
if (targetDown && isLookingDown()) {
targetBlock = getLocation().getBlock();
}
if (targetBlock != null) {
boolean targetAll = mage.isSuperPowered();
if (targetAll) {
UndoList undid = controller.undoRecent(targetBlock, timeout);
if (undid != null) {
Mage targetMage = undid.getOwner();
undoListName = undid.getName();
getCurrentCast().setTargetName(targetMage.getName());
return result;
}
} else {
getCurrentCast().setTargetName(mage.getName());
UndoList undoList = mage.undo(targetBlock);
if (undoList != null) {
undoListName = undoList.getName();
return result;
}
}
}
return SpellResult.NO_TARGET;
}
use of com.elmakers.mine.bukkit.api.spell.SpellResult in project MagicPlugin by elBukkit.
the class MountArmorStandAction method mount.
@Override
protected SpellResult mount(CastContext context) {
Mage mage = context.getMage();
Player player = mage.getPlayer();
if (player == null && mountWand) {
return SpellResult.PLAYER_REQUIRED;
}
item = null;
if (mountWand) {
Wand wand = context.getWand();
if (wand == null) {
return SpellResult.NO_TARGET;
}
wand.deactivate();
item = wand.getItem();
if (item == null || item.getType() == Material.AIR) {
return SpellResult.FAIL;
}
slotNumber = wand.getHeldSlot();
}
if (!mountTarget && !mountNewArmorStand(context)) {
return SpellResult.FAIL;
}
if (mountWand) {
player.getInventory().setItem(slotNumber, new ItemStack(Material.AIR));
}
SpellResult result = super.mount(context);
;
if (mount == null || !(mount instanceof ArmorStand)) {
result = SpellResult.FAIL;
}
return result;
}
Aggregations