use of com.elmakers.mine.bukkit.api.spell.MageSpell in project MagicPlugin by elBukkit.
the class MagicController method loadSpell.
@Nullable
public static Spell loadSpell(String name, ConfigurationSection node, MageController controller) {
String className = node.getString("class");
if (className == null || className.equalsIgnoreCase("action") || className.equalsIgnoreCase("actionspell")) {
className = "com.elmakers.mine.bukkit.spell.ActionSpell";
} else if (className.indexOf('.') <= 0) {
className = BUILTIN_SPELL_CLASSPATH + "." + className;
}
Class<?> spellClass = null;
try {
spellClass = Class.forName(className);
} catch (Throwable ex) {
controller.getLogger().log(Level.WARNING, "Error loading spell: " + className, ex);
return null;
}
if (spellClass.getAnnotation(Deprecated.class) != null) {
controller.getLogger().warning("Spell " + name + " is using a deprecated spell class " + className + ". This will be removed in the future, please see the default configs for alternatives.");
}
Object newObject;
try {
newObject = spellClass.getDeclaredConstructor().newInstance();
} catch (Throwable ex) {
controller.getLogger().log(Level.WARNING, "Error loading spell: " + className, ex);
return null;
}
if (newObject == null || !(newObject instanceof MageSpell)) {
controller.getLogger().warning("Error loading spell: " + className + ", does it implement MageSpell?");
return null;
}
MageSpell newSpell = (MageSpell) newObject;
newSpell.initialize(controller);
newSpell.loadTemplate(name, node);
com.elmakers.mine.bukkit.api.spell.SpellCategory category = newSpell.getCategory();
if (category instanceof SpellCategory) {
((SpellCategory) category).addSpellTemplate(newSpell);
}
return newSpell;
}
use of com.elmakers.mine.bukkit.api.spell.MageSpell in project MagicPlugin by elBukkit.
the class MagicController method addSpell.
public void addSpell(Spell variant) {
SpellTemplate conflict = spells.get(variant.getKey());
if (conflict != null) {
getLogger().log(Level.WARNING, "Duplicate spell key: '" + conflict.getKey() + "'");
} else {
spells.put(variant.getKey(), variant);
SpellData data = templateDataMap.get(variant.getSpellKey().getBaseKey());
if (data == null) {
data = new SpellData(variant.getSpellKey().getBaseKey());
templateDataMap.put(variant.getSpellKey().getBaseKey(), data);
}
if (variant instanceof MageSpell) {
((MageSpell) variant).setSpellData(data);
}
String alias = variant.getAlias();
if (alias != null && alias.length() > 0) {
spellAliases.put(alias, variant);
}
}
}
use of com.elmakers.mine.bukkit.api.spell.MageSpell in project MagicPlugin by elBukkit.
the class Mage method deactivateAllSpells.
@Override
public void deactivateAllSpells(boolean force, boolean quiet) {
// Copy this set since spells will get removed while iterating!
List<MageSpell> active = new ArrayList<>(activeSpells);
for (MageSpell spell : active) {
if (spell.deactivate(force, quiet)) {
activeSpells.remove(spell);
}
}
// This is mainly here to prevent multi-wand spamming and for
// Disarm to be more powerful.. because Disarm needs to be more
// powerful :|
cancelPending(false);
}
use of com.elmakers.mine.bukkit.api.spell.MageSpell in project MagicPlugin by elBukkit.
the class Mage method activateSpell.
@Override
public void activateSpell(Spell spell) {
if (spell instanceof MageSpell) {
MageSpell mageSpell = ((MageSpell) spell);
activeSpells.add(mageSpell);
mageSpell.setActive(true);
}
}
use of com.elmakers.mine.bukkit.api.spell.MageSpell in project MagicPlugin by elBukkit.
the class Mage method getSpell.
@Nullable
@Override
public MageSpell getSpell(String key) {
if (loading)
return null;
MageSpell playerSpell = spells.get(key);
if (playerSpell == null) {
playerSpell = createSpell(key);
if (playerSpell != null) {
SpellData spellData = this.spellData.get(key);
if (spellData == null) {
spellData = new SpellData(key);
this.spellData.put(key, spellData);
}
playerSpell.load(spellData);
}
} else {
playerSpell.setMage(this);
}
return playerSpell;
}
Aggregations