use of com.elmakers.mine.bukkit.api.spell.SpellKey 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.SpellKey in project MagicPlugin by elBukkit.
the class CasterProperties method hasSpell.
@Override
public boolean hasSpell(String key) {
SpellKey spellKey = new SpellKey(key);
if (!getBaseSpells().contains(spellKey.getBaseKey()))
return false;
int level = getSpellLevel(spellKey.getBaseKey());
return (level >= spellKey.getLevel());
}
use of com.elmakers.mine.bukkit.api.spell.SpellKey in project MagicPlugin by elBukkit.
the class CasterProperties method removeSpell.
public boolean removeSpell(String spellKey) {
Collection<String> spells = getBaseSpells();
SpellKey key = new SpellKey(spellKey);
boolean modified = spells.remove(key.getBaseKey());
if (modified) {
setProperty("spells", new ArrayList<>(spells));
Map<String, Integer> spellLevels = getSpellLevels();
if (spellLevels.remove(key.getBaseKey()) != null) {
setProperty("spell_levels", spellLevels);
}
}
return modified;
}
use of com.elmakers.mine.bukkit.api.spell.SpellKey in project MagicPlugin by elBukkit.
the class CasterProperties method addItem.
@Override
public boolean addItem(ItemStack item) {
if (Wand.isSpell(item) && !Wand.isSkill(item)) {
String spell = Wand.getSpell(item);
SpellKey spellKey = new SpellKey(spell);
Map<String, Integer> spellLevels = getSpellLevels();
Integer currentLevel = spellLevels.get(spellKey.getBaseKey());
if ((currentLevel == null || currentLevel < spellKey.getLevel()) && addSpell(spell)) {
return true;
}
} else if (Wand.isBrush(item)) {
String materialKey = Wand.getBrush(item);
Set<String> materials = getBrushes();
if (!materials.contains(materialKey) && addBrush(materialKey)) {
return true;
}
}
Mage mage = getMage();
if (mage != null && !mage.isAtMaxSkillPoints() && controller.skillPointItemsEnabled()) {
Integer sp = Wand.getSP(item);
if (sp != null) {
int amount = (int) Math.floor(mage.getSPMultiplier() * sp * item.getAmount());
mage.addSkillPoints(amount);
return true;
}
}
return false;
}
use of com.elmakers.mine.bukkit.api.spell.SpellKey in project MagicPlugin by elBukkit.
the class SpellProgressAction method clicked.
@Override
public void clicked(InventoryClickEvent event) {
event.setCancelled(true);
if (context != null) {
Mage mage = context.getMage();
Wand wand = context.getWand();
ItemStack item = event.getCurrentItem();
if (wand != null && com.elmakers.mine.bukkit.wand.Wand.isSpell(item)) {
String spellKey = com.elmakers.mine.bukkit.wand.Wand.getSpell(item);
SpellKey upgradeKey = new SpellKey(spellKey);
wand.setActiveSpell(upgradeKey.getBaseKey());
}
mage.deactivateGUI();
}
}
Aggregations