use of com.elmakers.mine.bukkit.api.spell.SpellTemplate in project MagicPlugin by elBukkit.
the class MageCommandExecutor method onMageAdd.
public boolean onMageAdd(CommandSender sender, Player player, String[] parameters) {
if (parameters.length < 1) {
sender.sendMessage("Use: /mage add <spell|material> [material:data]");
return true;
}
Mage mage = controller.getMage(player);
MageClass activeClass = mage.getActiveClass();
if (activeClass == null) {
sender.sendMessage("Can't modify player " + player.getName());
return true;
}
String spellName = parameters[0];
if (spellName.equals("material") || spellName.equals("brush")) {
if (parameters.length < 2) {
sender.sendMessage("Use: /mage add brush <material:data>");
return true;
}
String materialKey = parameters[1];
if (!MaterialBrush.isValidMaterial(materialKey, false)) {
sender.sendMessage(materialKey + " is not a valid brush");
return true;
}
if (activeClass.addBrush(materialKey)) {
if (sender != player) {
sender.sendMessage("Added brush '" + materialKey + "' to " + player.getName());
} else {
sender.sendMessage(api.getMessages().get("mage.brush_added").replace("$name", materialKey));
}
}
return true;
}
Spell spell = mage.getSpell(spellName);
if (spell == null) {
sender.sendMessage("Spell '" + spellName + "' unknown, Use /spells for spell list");
return true;
}
SpellTemplate currentSpell = activeClass.getSpellTemplate(spellName);
if (activeClass.addSpell(spellName)) {
if (currentSpell != null) {
String levelDescription = spell.getLevelDescription();
if (levelDescription == null || levelDescription.isEmpty()) {
levelDescription = spell.getName();
}
if (sender != player) {
sender.sendMessage(api.getMessages().get("mage.player_spell_upgraded").replace("$player", player.getName()).replace("$name", currentSpell.getName()).replace("$level", levelDescription));
}
} else {
if (sender != player) {
sender.sendMessage("Added '" + spell.getName() + "' to " + player.getName());
}
}
} else if (sender != player) {
sender.sendMessage("Could not add " + spellName + " to " + player.getName());
}
return true;
}
use of com.elmakers.mine.bukkit.api.spell.SpellTemplate in project MagicPlugin by elBukkit.
the class HeroesSpellSkill method getDefaultConfig.
@Override
public ConfigurationSection getDefaultConfig() {
ConfigurationSection node = super.getDefaultConfig();
// Add in all configured spell parameters
// Change keys to match heroes-format
ConfigurationSection spellParameters = spellTemplate.getSpellParameters();
if (spellParameters != null) {
Set<String> parameterKeys = spellParameters.getKeys(false);
for (String parameterKey : parameterKeys) {
if (!spellParameters.isConfigurationSection(parameterKey) && !spellParameters.isList(parameterKey)) {
String heroesKey = magicToHeroes(parameterKey);
Object value = spellParameters.get(parameterKey);
node.set(heroesKey, value);
parameters.set(heroesKey, value);
}
}
}
node.set("icon-url", spellTemplate.getIconURL());
MaterialAndData icon = spellTemplate.getIcon();
if (icon != null && icon.getMaterial() != Material.AIR) {
node.set("icon", icon.getKey());
}
MaterialAndData disabledIcon = spellTemplate.getDisabledIcon();
if (disabledIcon != null && disabledIcon.getMaterial() != Material.AIR) {
node.set("icon-disabled", disabledIcon.getKey());
}
node.set("icon-url", spellTemplate.getIconURL());
node.set("icon-disabled-url", spellTemplate.getDisabledIconURL());
node.set("cooldown", spellTemplate.getCooldown());
node.set("name", spellTemplate.getName());
Collection<CastingCost> costs = spellTemplate.getCosts();
if (costs != null) {
for (CastingCost cost : costs) {
if (cost.getMana() > 0) {
node.set(SkillSetting.MANA.node(), cost.getMana());
}
// TODO: Reagent costs from item costs
}
}
// Check for an upgrade, set tier if present
SpellKey upgradeKey = new SpellKey(spellTemplate.getSpellKey().getBaseKey(), 2);
SpellTemplate upgrade = controller.getSpellTemplate(upgradeKey.getKey());
if (upgrade != null) {
int maxUpgrade = 2;
while (upgrade != null) {
upgradeKey = new SpellKey(spellTemplate.getSpellKey().getBaseKey(), maxUpgrade + 1);
upgrade = controller.getSpellTemplate(upgradeKey.getKey());
if (upgrade != null)
maxUpgrade++;
}
node.set("tier", 1);
node.set("tier-max", maxUpgrade);
}
return node;
}
use of com.elmakers.mine.bukkit.api.spell.SpellTemplate in project MagicPlugin by elBukkit.
the class BaseMagicConfigurable method upgradeOverrides.
private boolean upgradeOverrides(Object value) {
boolean modified = false;
@SuppressWarnings("unchecked") Collection<String> overrides = value instanceof String ? Arrays.asList(StringUtils.split((String) value, ',')) : (List<String>) value;
Set<String> upgradedSpells = new HashSet<>();
for (String override : overrides) {
override = override.replace("\\|", ",");
String[] pairs = StringUtils.split(override, ' ');
if (pairs.length > 1) {
if (addOverride(pairs[0], pairs[1])) {
sendDebug("Added override: " + pairs[0] + " " + pairs[1]);
String[] pieces = StringUtils.split(pairs[0], '.');
if (pieces.length > 1 && !upgradedSpells.contains(pieces[0])) {
upgradedSpells.add(pieces[0]);
SpellTemplate spell = controller.getSpellTemplate(pieces[0]);
if (spell != null) {
sendAddMessage("spell_override_upgraded", spell.getName());
}
}
modified = true;
}
}
}
return modified;
}
use of com.elmakers.mine.bukkit.api.spell.SpellTemplate in project MagicPlugin by elBukkit.
the class CasterProperties method addSpell.
@Override
public boolean addSpell(String spellKey) {
BaseMagicConfigurable storage = getStorage("spells");
if (storage != this && storage != null) {
return storage.addSpell(spellKey);
}
SpellTemplate template = controller.getSpellTemplate(spellKey);
if (template == null) {
controller.getLogger().warning("Tried to add unknown spell: " + spellKey);
return false;
}
// Convert to spell if aliased
spellKey = template.getKey();
Collection<String> spells = getBaseSpells();
SpellKey key = new SpellKey(spellKey);
SpellTemplate currentSpell = getSpellTemplate(spellKey);
boolean modified = spells.add(key.getBaseKey());
if (modified) {
setProperty("spells", new ArrayList<>(spells));
}
boolean levelModified = false;
if (key.getLevel() > 1) {
levelModified = upgradeSpellLevel(key.getBaseKey(), key.getLevel());
}
if (!modified && !levelModified) {
return false;
}
// Special handling for spells to remove
Collection<SpellKey> spellsToRemove = template.getSpellsToRemove();
for (SpellKey removeKey : spellsToRemove) {
removeSpell(removeKey.getBaseKey());
}
Mage mage = getMage();
if (mage != null) {
if (currentSpell != null) {
String levelDescription = template.getLevelDescription();
if (levelDescription == null || levelDescription.isEmpty()) {
levelDescription = template.getName();
}
sendLevelMessage("spell_upgraded", currentSpell.getName(), levelDescription);
String upgradeDescription = template.getUpgradeDescription().replace("$name", currentSpell.getName());
if (!upgradeDescription.isEmpty()) {
mage.sendMessage(controller.getMessages().get("spell.upgrade_description_prefix") + upgradeDescription);
}
SpellUpgradeEvent upgradeEvent = new SpellUpgradeEvent(mage, getWand(), currentSpell, template);
Bukkit.getPluginManager().callEvent(upgradeEvent);
} else {
// This is a little hacky, but it is here to fix duplicate spell messages from the spellshop.
if (mage.getActiveGUI() == null)
sendAddMessage("spell_added", template.getName());
AddSpellEvent addEvent = new AddSpellEvent(mage, getWand(), template);
Bukkit.getPluginManager().callEvent(addEvent);
}
}
return true;
}
use of com.elmakers.mine.bukkit.api.spell.SpellTemplate in project MagicPlugin by elBukkit.
the class GiveItemAction method getParameterOptions.
@Override
public void getParameterOptions(Spell spell, String parameterKey, Collection<String> examples) {
if (parameterKey.equals("item") || parameterKey.equals("require")) {
MagicAPI api = MagicPlugin.getAPI();
Collection<SpellTemplate> spellList = api.getSpellTemplates();
for (SpellTemplate spellTemplate : spellList) {
examples.add(spellTemplate.getKey());
}
Collection<String> allWands = api.getWandKeys();
for (String wandKey : allWands) {
examples.add(wandKey);
}
examples.addAll(api.getBrushes());
} else {
super.getParameterOptions(spell, parameterKey, examples);
}
}
Aggregations