use of com.elmakers.mine.bukkit.api.magic.MageModifier in project MagicPlugin by elBukkit.
the class ModifierAction method perform.
@Override
public SpellResult perform(CastContext context) {
Entity targetEntity = context.getTargetEntity();
Mage targetMage = context.getController().getMage(targetEntity);
boolean effected = false;
if (removeModifiers != null) {
for (String remove : removeModifiers) {
MageModifier removed = targetMage.removeModifier(remove);
if (removed != null) {
context.registerModifier(targetEntity, removed);
effected = true;
}
}
}
if (addModifiers != null && !addModifiers.isEmpty()) {
effected = true;
for (String key : addModifiers.keySet()) {
int duration = this.duration;
ConfigurationSection configuration = addModifiers.get(key);
if (configuration != null) {
duration = configuration.getInt("duration", duration);
}
if (targetMage.addModifier(key, duration, configuration)) {
context.registerModifierForRemoval(targetEntity, key);
effected = true;
if (removeOnFinish) {
if (added == null) {
added = new ArrayList<>();
}
added.add(key);
}
}
}
}
return effected ? SpellResult.CAST : SpellResult.NO_TARGET;
}
use of com.elmakers.mine.bukkit.api.magic.MageModifier in project MagicPlugin by elBukkit.
the class MageCommandExecutor method onMageRemoveModifier.
public boolean onMageRemoveModifier(CommandSender sender, Player player, String[] parameters) {
Mage mage = controller.getMage(player);
String modifierKey = parameters[0];
MageModifier modifier = mage.removeModifier(modifierKey);
if (modifier != null) {
sender.sendMessage(controller.getMessages().get("commands.modifier.remove.success").replace("$name", modifier.getName()).replace("$player", player.getName()));
} else {
sender.sendMessage(controller.getMessages().get("commands.modifier.remove.fail").replace("$name", modifierKey).replace("$player", player.getName()));
}
return true;
}
use of com.elmakers.mine.bukkit.api.magic.MageModifier in project MagicPlugin by elBukkit.
the class MageCommandExecutor method onMageAddModifier.
public boolean onMageAddModifier(CommandSender sender, Player player, String[] parameters) {
Mage mage = controller.getMage(player);
String modifierKey = parameters[0];
MageModifier modifier = null;
int duration = 0;
if (parameters.length > 1) {
try {
duration = Integer.parseInt(parameters[1]);
} catch (Exception ex) {
sender.sendMessage(controller.getMessages().get("commands.modifier.add.invalid").replace("$input", parameters[1]));
return true;
}
}
if (mage.addModifier(modifierKey, duration)) {
modifier = mage.getModifier(modifierKey);
if (modifier != null) {
String message = duration > 0 ? "commands.modifier.add.success_duration" : "commands.modifier.add.success";
sender.sendMessage(controller.getMessages().get(message).replace("$name", modifier.getName()).replace("$player", player.getName()).replace("$duration", controller.getMessages().getTimeDescription(duration)));
}
}
if (modifier == null) {
sender.sendMessage(controller.getMessages().get("commands.modifier.add.fail").replace("$name", modifierKey).replace("$player", player.getName()));
}
return true;
}
use of com.elmakers.mine.bukkit.api.magic.MageModifier in project MagicPlugin by elBukkit.
the class MageCommandExecutor method onMageDescribe.
public boolean onMageDescribe(CommandSender sender, Player player, String[] parameters) {
Mage mage = controller.getMage(player);
MageClass activeClass = mage.getActiveClass();
MagicProperties mageProperties = mage.getProperties();
if (parameters.length == 0) {
sender.sendMessage(ChatColor.AQUA + "Mage " + ChatColor.GOLD + mage.getName());
sender.sendMessage(ChatColor.GRAY + mage.getId());
sender.sendMessage(ChatColor.BLUE + "Use " + ChatColor.AQUA + "/mage describe <property>" + ChatColor.BLUE + " for specific properties");
sender.sendMessage(ChatColor.BLUE + "Use " + ChatColor.AQUA + "/mage activate" + ChatColor.BLUE + " to change or clear the active class");
Collection<String> classKeys = mage.getClassKeys();
if (classKeys.size() > 0) {
Collection<String> coloredClasses = new ArrayList<>();
for (String classKey : classKeys) {
ChatColor color = mage.hasClassUnlocked(classKey) ? ChatColor.GREEN : ChatColor.GRAY;
coloredClasses.add(color + classKey);
}
sender.sendMessage(ChatColor.AQUA + "Classes: " + ChatColor.GREEN + StringUtils.join(coloredClasses, ","));
}
Collection<String> modifierKeys = mage.getModifierKeys();
if (!modifierKeys.isEmpty()) {
sender.sendMessage(ChatColor.AQUA + "Modifiers:");
for (String modifierKey : modifierKeys) {
MageModifier modifier = mage.getModifier(modifierKey);
String modifierDescription = ChatColor.DARK_AQUA + modifier.getName();
if (modifier.hasDuration()) {
int timeRemaining = modifier.getTimeRemaining();
modifierDescription += ChatColor.GRAY + " (" + ChatColor.WHITE + controller.getMessages().getTimeDescription(timeRemaining) + ChatColor.GRAY + ")";
}
sender.sendMessage(modifierDescription);
}
}
if (!mageProperties.isEmpty()) {
sender.sendMessage(ChatColor.AQUA + "Mage properties:");
mageProperties.describe(sender, BaseMagicProperties.HIDDEN_PROPERTY_KEYS);
}
ConfigurationSection variables = mage.getVariables();
Set<String> keys = variables.getKeys(false);
if (!keys.isEmpty()) {
sender.sendMessage(ChatColor.AQUA + "Mage variables:");
for (String key : keys) {
Object value = variables.get(key);
if (value != null) {
sender.sendMessage(ChatColor.DARK_AQUA + key + ChatColor.GRAY + ": " + ChatColor.WHITE + CompatibilityLib.getInventoryUtils().describeProperty(value, CompatibilityConstants.MAX_PROPERTY_DISPLAY_LENGTH));
}
}
}
if (activeClass != null) {
sender.sendMessage(ChatColor.AQUA + "Active class: " + ChatColor.GREEN + activeClass.getKey());
} else {
sender.sendMessage(ChatColor.DARK_GREEN + "No active class");
}
Set<Spell> activeSpells = mage.getActiveSpells();
if (activeSpells != null && !activeSpells.isEmpty()) {
Collection<String> spellNames = new ArrayList<>();
for (Spell spell : activeSpells) {
spellNames.add(spell.getName());
}
sender.sendMessage(ChatColor.AQUA + "Active spells: " + ChatColor.DARK_AQUA + StringUtils.join(spellNames, ","));
}
if (activeClass != null) {
activeClass.describe(sender, BaseMagicProperties.HIDDEN_PROPERTY_KEYS);
}
} else {
Object property = activeClass.getProperty(parameters[0]);
if (property == null) {
sender.sendMessage(ChatColor.DARK_AQUA + parameters[0] + ChatColor.GRAY + ": " + ChatColor.RED + "(Not Set)");
} else {
sender.sendMessage(ChatColor.DARK_AQUA + parameters[0] + ChatColor.GRAY + ": " + ChatColor.WHITE + CompatibilityLib.getInventoryUtils().describeProperty(property));
}
}
return true;
}
Aggregations