use of com.elmakers.mine.bukkit.api.spell.SpellKey in project MagicPlugin by elBukkit.
the class Wand method buildInventory.
protected void buildInventory() {
// Force an update of the display inventory since chest mode is a different size
displayInventory = null;
updateHotbarCount();
for (Inventory hotbar : hotbars) {
hotbar.clear();
}
inventories.clear();
List<ItemStack> unsorted = new ArrayList<>();
for (String key : spells) {
int spellLevel = getSpellLevel(key);
SpellKey spellKey = new SpellKey(key, spellLevel);
SpellTemplate spell = controller.getSpellTemplate(spellKey.getKey());
ItemStack itemStack = createSpellItem(spell, "", controller, getActiveMage(), this, false);
if (itemStack != null) {
Integer slot = spellInventory.get(spell.getSpellKey().getBaseKey());
if (slot == null) {
unsorted.add(itemStack);
} else {
addToInventory(itemStack, slot);
}
}
}
WandMode brushMode = getBrushMode();
for (String brushKey : brushes) {
boolean addToInventory = brushMode == WandMode.INVENTORY || (MaterialBrush.isSpecialMaterialKey(brushKey) && !MaterialBrush.isSchematic(brushKey));
if (addToInventory) {
ItemStack itemStack = createBrushIcon(brushKey);
if (itemStack == null) {
controller.getPlugin().getLogger().warning("Unable to create brush icon for key " + brushKey);
continue;
}
Integer slot = brushInventory.get(brushKey);
if (activeBrush == null || activeBrush.length() == 0)
activeBrush = brushKey;
addToInventory(itemStack, slot);
}
}
for (ItemStack unsortedItem : unsorted) {
addToInventory(unsortedItem);
}
updateHasInventory();
if (openInventoryPage >= inventories.size() && openInventoryPage != 0 && hasInventory) {
setOpenInventoryPage(0);
}
}
use of com.elmakers.mine.bukkit.api.spell.SpellKey in project MagicPlugin by elBukkit.
the class Wand method loadSpells.
protected void loadSpells(Collection<String> spellKeys) {
clearSpells();
WandUpgradePath path = getPath();
for (String spellName : spellKeys) {
String[] pieces = StringUtils.split(spellName, '@');
Integer slot = parseSlot(pieces);
// Handle aliases and upgrades smoothly
String loadedKey = pieces[0].trim();
SpellKey spellKey = new SpellKey(loadedKey);
SpellTemplate spell = controller.getSpellTemplate(loadedKey);
if (limitSpellsToPath && path != null && !path.containsSpell(spellKey.getBaseKey()))
continue;
// Downgrade spells if higher levels have gone missing
while (spell == null && spellKey.getLevel() > 0) {
spellKey = new SpellKey(spellKey.getBaseKey(), spellKey.getLevel() - 1);
spell = controller.getSpellTemplate(spellKey.getKey());
}
if (spell != null) {
spellKey = spell.getSpellKey();
Integer currentLevel = spellLevels.get(spellKey.getBaseKey());
if (spellKey.getLevel() > 1 && (currentLevel == null || currentLevel < spellKey.getLevel())) {
setSpellLevel(spellKey.getBaseKey(), spellKey.getLevel());
}
if (slot != null) {
spellInventory.put(spellKey.getBaseKey(), slot);
}
spells.add(spellKey.getBaseKey());
if (activeSpell == null || activeSpell.length() == 0) {
activeSpell = spellKey.getBaseKey();
}
}
}
}
use of com.elmakers.mine.bukkit.api.spell.SpellKey in project MagicPlugin by elBukkit.
the class Wand method setActiveSpell.
@Override
public void setActiveSpell(String activeSpell) {
if (activeSpell != null) {
SpellKey spellKey = new SpellKey(activeSpell);
this.activeSpell = spellKey.getBaseKey();
} else {
this.activeSpell = null;
}
checkActiveSpell();
setProperty("active_spell", this.activeSpell);
saveState();
updateName();
}
use of com.elmakers.mine.bukkit.api.spell.SpellKey in project MagicPlugin by elBukkit.
the class WandOrganizer method removeHotbar.
protected void removeHotbar(Map<String, Integer> spells, Map<String, Integer> brushes) {
if (wand.getHotbarCount() == 0)
return;
List<Inventory> hotbars = wand.getHotbars();
for (Inventory hotbar : hotbars) {
int hotbarSize = hotbar.getSize();
for (int i = 0; i < hotbarSize; i++) {
ItemStack hotbarItem = hotbar.getItem(i);
if (hotbarItem == null || hotbarItem.getType() == Material.AIR)
continue;
String spellName = Wand.getSpell(hotbarItem);
if (spellName != null) {
SpellKey spellKey = new SpellKey(spellName);
spellName = spellKey.getBaseKey();
}
if (spellName != null) {
spells.remove(spellName);
} else {
String materialKey = Wand.getBrush(hotbarItem);
if (materialKey != null) {
brushes.remove(materialKey);
}
}
}
}
}
use of com.elmakers.mine.bukkit.api.spell.SpellKey in project MagicPlugin by elBukkit.
the class MagicConfigurableExecutor method onLevelSpells.
protected boolean onLevelSpells(String command, CommandSender sender, Player player, CasterProperties caster, Integer maxLevel) {
Collection<String> spells = caster.getSpells();
MageController controller = api.getController();
int levelledCount = 0;
for (String spellKey : spells) {
SpellTemplate spellTemplate = controller.getSpellTemplate(spellKey);
if (spellTemplate == null)
continue;
SpellKey key = spellTemplate.getSpellKey();
int currentLevel = key.getLevel();
if (maxLevel != null && currentLevel >= maxLevel)
continue;
int targetLevel = key.getLevel();
while (spellTemplate != null && (maxLevel == null || targetLevel < maxLevel)) {
key = new SpellKey(key.getBaseKey(), targetLevel + 1);
spellTemplate = controller.getSpellTemplate(key.getKey());
if (spellTemplate != null) {
targetLevel++;
}
}
if (currentLevel >= targetLevel)
continue;
key = new SpellKey(key.getBaseKey(), targetLevel);
caster.addSpell(key.getKey());
levelledCount++;
}
if (sender != player) {
if (levelledCount > 0) {
sender.sendMessage(api.getMessages().getParameterized(command + ".player_spells_levelled", "$name", player.getName(), "$count", Integer.toString(levelledCount)));
} else {
sender.sendMessage(api.getMessages().getParameterized(command + ".player_spells_not_levelled", "$name", player.getName()));
}
} else {
if (levelledCount > 0) {
sender.sendMessage(api.getMessages().getParameterized(command + ".spells_levelled", "$name", player.getName(), "$count", Integer.toString(levelledCount)));
} else {
sender.sendMessage(api.getMessages().getParameterized(command + ".spells_not_levelled", "$name", player.getName()));
}
}
return true;
}
Aggregations