use of com.elmakers.mine.bukkit.api.magic.Mage in project MagicPlugin by elBukkit.
the class CommandAction method perform.
@Override
public SpellResult perform(CastContext context) {
Mage mage = context.getMage();
MageController controller = context.getController();
CommandSender sender = asConsole ? Bukkit.getConsoleSender() : mage.getCommandSender();
if (sender == null) {
return SpellResult.FAIL;
}
Queue<String> conversationCommands = new ArrayDeque<>(commands.size());
boolean isOp = sender.isOp();
if (opPlayer && !isOp) {
sender.setOp(true);
}
for (String command : commands) {
try {
String converted = context.parameterize(command);
if (converted.contains("@arg")) {
conversationCommands.add(converted);
} else {
controller.getPlugin().getServer().dispatchCommand(sender, converted);
}
} catch (Exception ex) {
controller.getLogger().log(Level.WARNING, "Error running command: " + command, ex);
}
}
if (opPlayer && !isOp) {
sender.setOp(false);
}
if (!conversationCommands.isEmpty()) {
runConversations(context, conversationCommands, opPlayer);
}
return SpellResult.CAST;
}
use of com.elmakers.mine.bukkit.api.magic.Mage in project MagicPlugin by elBukkit.
the class ModifyManaAction method perform.
@Override
public SpellResult perform(CastContext context) {
Entity target = context.getTargetEntity();
if (target == null) {
return SpellResult.NO_TARGET;
}
MageController controller = context.getController();
Mage mage = controller.getRegisteredMage(target);
if (mage == null) {
return SpellResult.NO_TARGET;
}
Player player = mage.getPlayer();
if (player == null) {
return SpellResult.PLAYER_REQUIRED;
}
double currentMana = mage.getMana();
if (mana < 0 && currentMana <= 0) {
return SpellResult.NO_TARGET;
}
int manaMax = mage.getManaMax();
if (mana > 0 && currentMana >= manaMax) {
return SpellResult.NO_TARGET;
}
if (fillMana) {
currentMana = manaMax;
} else {
currentMana = Math.min(Math.max(0, currentMana + mana), manaMax);
}
mage.setMana((float) currentMana);
mage.updateMana();
return SpellResult.CAST;
}
use of com.elmakers.mine.bukkit.api.magic.Mage in project MagicPlugin by elBukkit.
the class ModifyPropertiesAction method perform.
@Override
public SpellResult perform(CastContext context) {
if (modify == null) {
return SpellResult.FAIL;
}
Entity entity = context.getTargetEntity();
Mage mage = entity == null ? null : context.getController().getRegisteredMage(entity);
if (mage == null) {
return SpellResult.NO_TARGET;
}
CasterProperties properties = null;
if (modifyTarget.equals("wand")) {
properties = mage.getActiveWand();
} else if (modifyTarget.equals("player")) {
properties = mage.getProperties();
} else {
properties = mage.getClass(modifyTarget);
}
// I am now wishing I hadn't made a base class called "mage" :(
if (properties == null && modifyTarget.equals("mage")) {
properties = mage.getProperties();
}
if (properties == null) {
return SpellResult.NO_TARGET;
}
ConfigurationSection original = new MemoryConfiguration();
ConfigurationSection changed = new MemoryConfiguration();
for (ModifyProperty property : modify) {
Object originalValue = properties.getProperty(property.path);
Object newValue = property.value;
if ((originalValue == null || originalValue instanceof Number) && property.value instanceof String) {
EquationTransform transform = EquationStore.getInstance().getTransform((String) property.value);
originalValue = originalValue == null ? null : NumberConversions.toDouble(originalValue);
double defaultValue = property.defaultValue == null ? 0 : property.defaultValue;
if (transform.isValid()) {
if (originalValue == null) {
originalValue = defaultValue;
} else if (property.max != null && (Double) originalValue >= property.max) {
continue;
} else if (property.min != null && (Double) originalValue <= property.min) {
continue;
}
transform.setVariable("x", (Double) originalValue);
double transformedValue = transform.get();
if (!Double.isNaN(transformedValue)) {
if (property.max != null) {
transformedValue = Math.min(transformedValue, property.max);
}
if (property.min != null) {
transformedValue = Math.max(transformedValue, property.min);
}
newValue = transformedValue;
}
}
}
changed.set(property.path, newValue);
original.set(property.path, originalValue);
}
if (changed.getKeys(false).isEmpty())
return SpellResult.NO_TARGET;
if (upgrade)
properties.upgrade(changed);
else
properties.configure(changed);
context.registerForUndo(new ModifyPropertyUndoAction(original, properties));
return SpellResult.CAST;
}
use of com.elmakers.mine.bukkit.api.magic.Mage in project MagicPlugin by elBukkit.
the class ModifySPAction method perform.
@Override
public SpellResult perform(CastContext context) {
Mage mage = context.getMage();
MageController controller = context.getController();
int currentSP = mage.getSkillPoints();
if (sp < 0 && currentSP <= 0) {
return SpellResult.NO_TARGET;
}
int spMax = controller.getSPMaximum();
if (sp > 0 && currentSP >= spMax) {
return SpellResult.NO_TARGET;
}
mage.addSkillPoints(sp);
return SpellResult.CAST;
}
use of com.elmakers.mine.bukkit.api.magic.Mage in project MagicPlugin by elBukkit.
the class IgniteAction method perform.
@Override
public SpellResult perform(CastContext context) {
int ticks = duration * 20 / 1000;
Entity entity = context.getTargetEntity();
MageController controller = context.getController();
boolean isElemental = controller.isElemental(entity);
if (!isElemental && entity.getFireTicks() == ticks) {
return SpellResult.NO_TARGET;
}
context.registerDamaged(entity);
if (isElemental) {
Mage mage = context.getMage();
controller.damageElemental(entity, 0, ticks, mage.getCommandSender());
} else {
entity.setFireTicks(ticks);
}
return SpellResult.CAST;
}
Aggregations