use of com.elmakers.mine.bukkit.api.spell.SpellTemplate in project MagicPlugin by elBukkit.
the class Mage method createSpell.
@Nullable
protected MageSpell createSpell(String key) {
MageSpell playerSpell = spells.get(key);
if (playerSpell != null) {
playerSpell.setMage(this);
return playerSpell;
}
SpellTemplate spellTemplate = controller.getSpellTemplate(key);
if (spellTemplate == null)
return null;
Spell newSpell = spellTemplate.createSpell();
if (newSpell == null || !(newSpell instanceof MageSpell))
return null;
playerSpell = (MageSpell) newSpell;
spells.put(newSpell.getKey(), playerSpell);
playerSpell.setMage(this);
return playerSpell;
}
use of com.elmakers.mine.bukkit.api.spell.SpellTemplate in project MagicPlugin by elBukkit.
the class HeroesSkillSpell method canCast.
@Override
public boolean canCast(Location location) {
if (!isCasting && mage != null && mage.isPlayer() && !heroes.canUseSkill(mage.getPlayer(), skillKey)) {
return false;
}
if (skill instanceof HeroesSpellSkill) {
HeroesSpellSkill spellSkill = (HeroesSpellSkill) skill;
SpellTemplate template = spellSkill.getSpellTemplate();
Spell spell = mage.getSpell(template.getKey());
if (spell != null) {
return spell.canCast(location);
}
}
return super.canCast(location);
}
use of com.elmakers.mine.bukkit.api.spell.SpellTemplate in project MagicPlugin by elBukkit.
the class HeroesSpellSkill method getSkillName.
/**
* This code is redudant, but unfortunately it needs to be since we need to know the
* skill name for the super() constructor call.
*/
private static String getSkillName(Heroes heroes, String spellKey) {
Plugin magicPlugin = heroes.getServer().getPluginManager().getPlugin("Magic");
if (magicPlugin == null || (!(magicPlugin instanceof MagicAPI) && !magicPlugin.isEnabled())) {
heroes.getLogger().warning("MagicHeroes skills require the Magic plugin");
throw new RuntimeException("MagicHeroes skills require the Magic plugin");
}
MagicAPI api = (MagicAPI) magicPlugin;
MageController controller = api.getController();
SpellTemplate spellTemplate = controller.getSpellTemplate(spellKey);
if (spellTemplate == null) {
controller.getLogger().warning("Failed to load Magic skill spell: " + spellKey);
throw new RuntimeException("Failed to load Magic skill spell: " + spellKey);
}
String baseName = ChatColor.stripColor(spellTemplate.getName().replace(" ", ""));
return controller.getHeroesSkillPrefix() + baseName;
}
use of com.elmakers.mine.bukkit.api.spell.SpellTemplate in project MagicPlugin by elBukkit.
the class MagicController method loadSpells.
protected void loadSpells(Map<String, ConfigurationSection> spellConfigs) {
if (spellConfigs == null)
return;
// Reset existing spells.
spells.clear();
spellAliases.clear();
categories.clear();
for (Entry<String, ConfigurationSection> entry : spellConfigs.entrySet()) {
String key = entry.getKey();
if (key.equals("default") || key.equals("override"))
continue;
ConfigurationSection spellNode = entry.getValue();
if (spellNode == null) {
continue;
}
Spell newSpell = null;
try {
newSpell = loadSpell(key, spellNode, this);
} catch (Exception ex) {
newSpell = null;
ex.printStackTrace();
}
if (newSpell == null) {
getLogger().warning("Magic: Error loading spell " + key);
continue;
}
if (!newSpell.hasIcon()) {
String icon = spellNode.getString("icon");
if (icon != null && !icon.isEmpty()) {
getLogger().info("Couldn't load spell icon '" + icon + "' for spell: " + newSpell.getKey());
}
}
addSpell(newSpell);
}
// Second pass to fulfill requirements, which needs all spells loaded
for (Entry<String, ConfigurationSection> entry : spellConfigs.entrySet()) {
SpellTemplate template = getSpellTemplate(entry.getKey());
if (template != null) {
template.loadPrerequisites(entry.getValue());
}
}
// Update registered mages so their spells are current
for (Mage mage : mages.values()) {
if (mage instanceof com.elmakers.mine.bukkit.magic.Mage) {
((com.elmakers.mine.bukkit.magic.Mage) mage).loadSpells(spellConfigurations);
}
}
}
use of com.elmakers.mine.bukkit.api.spell.SpellTemplate in project MagicPlugin by elBukkit.
the class MageCommandExecutor method onMageRemove.
public boolean onMageRemove(CommandSender sender, Player player, String[] parameters) {
if (parameters.length < 1) {
sender.sendMessage("Use: /mage remove <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 remove brush <material:data>");
return true;
}
String materialKey = parameters[1];
if (activeClass.removeBrush(materialKey)) {
mage.sendMessage("Brush '" + materialKey + "' has been removed");
if (sender != player) {
sender.sendMessage("Removed brush '" + materialKey + "' from " + player.getName());
}
} else {
if (sender != player) {
sender.sendMessage(player.getName() + " does not have brush " + materialKey);
}
}
return true;
}
if (activeClass.removeSpell(spellName)) {
SpellTemplate template = api.getSpellTemplate(spellName);
if (template != null) {
spellName = template.getName();
}
mage.sendMessage("Spell '" + spellName + "' has been removed");
if (sender != player) {
sender.sendMessage("Removed '" + spellName + "' from " + player.getName());
}
} else {
if (sender != player) {
sender.sendMessage(player.getName() + " does not have " + spellName);
}
}
return true;
}
Aggregations