use of com.elmakers.mine.bukkit.api.magic.Mage in project MagicPlugin by elBukkit.
the class CastContext method finish.
@Override
public void finish() {
if (finished)
return;
finished = true;
Mage mage = getMage();
if (finishedHandlers != null) {
for (ActionHandlerContext context : finishedHandlers) {
context.finish();
}
finishedHandlers = null;
}
if (undoSpell != null && undoSpell.isUndoable()) {
if (!undoList.isScheduled()) {
getController().update(undoList);
}
mage.registerForUndo(undoList);
}
result = result.max(initialResult);
if (spell != null) {
mage.sendDebugMessage(ChatColor.WHITE + "Finish " + ChatColor.GOLD + spell.getName() + ChatColor.WHITE + ": " + ChatColor.AQUA + result.name().toLowerCase(), 2);
spell.finish(this);
}
String resultName = result.name().toLowerCase();
castMessageKey(resultName + "_finish");
playEffects(resultName + "_finish");
}
use of com.elmakers.mine.bukkit.api.magic.Mage in project MagicPlugin by elBukkit.
the class AbsorbAction method perform.
@SuppressWarnings("deprecation")
@Override
public SpellResult perform(CastContext context) {
Block target = context.getTargetBlock();
Mage mage = context.getMage();
Wand wand = context.getWand();
if (wand == null) {
return SpellResult.FAIL;
}
MageController controller = context.getController();
Material material = target.getType();
byte data = target.getData();
MaterialSet buildingMaterials = controller.getBuildingMaterialSet();
MaterialSet restrictedMaterials = mage.getRestrictedMaterialSet();
if (material == null || material == Material.AIR) {
return SpellResult.NO_TARGET;
}
if (!mage.getCommandSender().hasPermission("Magic.bypass_restricted") && (!buildingMaterials.testBlock(target) || restrictedMaterials.testBlock(target))) {
return SpellResult.NO_TARGET;
}
// Add to the wand
MaterialAndData mat = new MaterialAndData(material, data);
if (!wand.addBrush(mat.getKey())) {
// Still try and activate it
wand.setActiveBrush(mat.getKey());
return SpellResult.NO_TARGET;
}
// And activate it
wand.setActiveBrush(mat.getKey());
return SpellResult.CAST;
}
use of com.elmakers.mine.bukkit.api.magic.Mage in project MagicPlugin by elBukkit.
the class ApplyCooldownAction method perform.
@Override
public SpellResult perform(CastContext context) {
Mage targetMage = context.getMage();
if (!targetCaster) {
Entity entity = context.getTargetEntity();
MageController controller = context.getController();
if (entity == null || !controller.isMage(entity)) {
return SpellResult.NO_TARGET;
}
targetMage = controller.getMage(entity);
}
int amount = cooldownAmount;
if (!bypassReduction && cooldownAmount > 0) {
double cooldownReduction = targetMage.getCooldownReduction();
if (cooldownReduction < 1) {
amount = (int) Math.ceil((1.0f - cooldownReduction) * amount);
} else {
amount = 0;
}
}
if (spells != null) {
Wand wand = targetMage.getActiveWand();
for (String spellName : spells) {
Spell spell = null;
if (wand != null) {
spell = wand.getSpell(spellName);
}
if (spell == null) {
spell = targetMage.getSpell(spellName);
}
if (spell != null) {
if (clear) {
spell.clearCooldown();
}
if (amount > 0) {
spell.setRemainingCooldown(amount);
}
}
}
} else if (excludeSpells != null) {
Collection<Spell> allSpells = targetMage.getSpells();
for (Spell spell : allSpells) {
if (!excludeSpells.contains(spell.getSpellKey().getBaseKey())) {
if (clear) {
spell.clearCooldown();
}
if (amount > 0) {
spell.setRemainingCooldown(amount);
}
}
}
} else {
if (clear) {
targetMage.clearCooldown();
}
if (amount > 0) {
targetMage.setRemainingCooldown(amount);
}
}
return SpellResult.CAST;
}
use of com.elmakers.mine.bukkit.api.magic.Mage in project MagicPlugin by elBukkit.
the class AreaOfEffectAction method addEntities.
@Override
public void addEntities(CastContext context, List<WeakReference<Entity>> entities) {
Mage mage = context.getMage();
Entity sourceEntity = context.getMage().getEntity();
Location sourceLocation = context.getTargetLocation();
if (mage.getDebugLevel() > 8) {
mage.sendDebugMessage(ChatColor.GREEN + "AOE Targeting from " + ChatColor.GRAY + sourceLocation.getBlockX() + ChatColor.DARK_GRAY + "," + ChatColor.GRAY + sourceLocation.getBlockY() + ChatColor.DARK_GRAY + "," + ChatColor.GRAY + sourceLocation.getBlockZ() + ChatColor.DARK_GREEN + " with radius of " + ChatColor.GREEN + radius + ChatColor.GRAY + " self? " + ChatColor.DARK_GRAY + context.getTargetsCaster(), 14);
}
List<Entity> candidates = CompatibilityUtils.getNearbyEntities(sourceLocation, radius, yRadius, radius);
if (targetCount > 0) {
List<Target> targets = new ArrayList<>();
Entity targetEntity = context.getTargetEntity();
for (Entity entity : candidates) {
boolean canTarget = true;
if (entity == sourceEntity && !context.getTargetsCaster())
canTarget = false;
if (entity == targetEntity && !targetSource)
canTarget = false;
if (canTarget && context.canTarget(entity)) {
Target target = new Target(sourceLocation, entity, radius, 0);
targets.add(target);
mage.sendDebugMessage(ChatColor.DARK_GREEN + "Target " + ChatColor.GREEN + entity.getType() + ChatColor.DARK_GREEN + ": " + ChatColor.YELLOW + target.getScore(), 12);
} else if (mage.getDebugLevel() > 7) {
mage.sendDebugMessage(ChatColor.DARK_RED + "Skipped Target " + ChatColor.GREEN + entity.getType(), 16);
}
}
Collections.sort(targets);
for (int i = 0; i < targetCount && i < targets.size(); i++) {
Target target = targets.get(i);
entities.add(new WeakReference<>(target.getEntity()));
}
} else {
for (Entity entity : candidates) {
if ((context.getTargetsCaster() || !entity.equals(sourceEntity)) && context.canTarget(entity)) {
entities.add(new WeakReference<>(entity));
mage.sendDebugMessage(ChatColor.DARK_GREEN + "Target " + ChatColor.GREEN + entity.getType(), 12);
} else if (mage.getDebugLevel() > 7) {
mage.sendDebugMessage(ChatColor.DARK_RED + "Skipped Target " + ChatColor.GREEN + entity.getType(), 16);
}
}
}
}
use of com.elmakers.mine.bukkit.api.magic.Mage in project MagicPlugin by elBukkit.
the class BaseShopAction method checkContext.
public SpellResult checkContext(CastContext context) {
Mage mage = context.getMage();
MageController controller = mage.getController();
Player player = mage.getPlayer();
if (player == null) {
return SpellResult.PLAYER_REQUIRED;
}
if (permissionNode != null && !player.hasPermission(permissionNode)) {
return SpellResult.INSUFFICIENT_PERMISSION;
}
if (!requireWand) {
return SpellResult.CAST;
}
Wand wand = mage.getActiveWand();
if (wand == null) {
context.showMessage("no_wand", getDefaultMessage(context, "no_wand"));
return SpellResult.FAIL;
}
WandUpgradePath path = wand.getPath();
if (requiredTemplate != null) {
String template = wand.getTemplateKey();
if (template == null || !template.equals(requiredTemplate)) {
context.showMessage(context.getMessage("no_template", getDefaultMessage(context, "no_template")).replace("$wand", wand.getName()));
return SpellResult.FAIL;
}
}
// Check path requirements
if (requiredPath != null || exactPath != null) {
if (path == null) {
context.showMessage(context.getMessage("no_path", getDefaultMessage(context, "no_path")).replace("$wand", wand.getName()));
return SpellResult.FAIL;
}
if (requiredPath != null && !path.hasPath(requiredPath)) {
WandUpgradePath requiresPath = controller.getPath(requiredPath);
if (requiresPath != null) {
context.showMessage(context.getMessage("no_required_path", getDefaultMessage(context, "no_required_path")).replace("$path", requiresPath.getName()));
} else {
context.getLogger().warning("Invalid path specified in Shop action: " + requiredPath);
}
return SpellResult.FAIL;
}
if (exactPath != null && !exactPath.equals(path.getKey())) {
WandUpgradePath requiresPath = controller.getPath(exactPath);
if (requiresPath != null) {
context.showMessage(context.getMessage("no_path_exact", getDefaultMessage(context, "no_path_exact")).replace("$path", requiresPath.getName()));
} else {
context.getLogger().warning("Invalid path specified in Shop action: " + exactPath);
}
return SpellResult.FAIL;
}
if (requiresCompletedPath != null) {
if (path.canEnchant(wand)) {
context.showMessage(context.getMessage("no_path_end", getDefaultMessage(context, "no_path_end")).replace("$path", path.getName()));
return SpellResult.FAIL;
}
}
}
return SpellResult.CAST;
}
Aggregations