use of com.elmakers.mine.bukkit.api.spell.SpellTemplate in project MagicPlugin by elBukkit.
the class MagicController method getSpellBook.
public ItemStack getSpellBook(com.elmakers.mine.bukkit.api.spell.SpellCategory category, int count) {
Map<String, List<SpellTemplate>> categories = new HashMap<>();
Collection<SpellTemplate> spellVariants = spells.values();
String categoryKey = category == null ? null : category.getKey();
for (SpellTemplate spell : spellVariants) {
if (spell.isHidden() || spell.getSpellKey().isVariant())
continue;
com.elmakers.mine.bukkit.api.spell.SpellCategory spellCategory = spell.getCategory();
if (spellCategory == null)
continue;
String spellCategoryKey = spellCategory.getKey();
if (categoryKey == null || spellCategoryKey.equalsIgnoreCase(categoryKey)) {
List<SpellTemplate> categorySpells = categories.get(spellCategoryKey);
if (categorySpells == null) {
categorySpells = new ArrayList<>();
categories.put(spellCategoryKey, categorySpells);
}
categorySpells.add(spell);
}
}
List<String> categoryKeys = new ArrayList<>(categories.keySet());
Collections.sort(categoryKeys);
// Hrm? So much Copy+paste! :(
CostReducer reducer = null;
ItemStack bookItem = new ItemStack(Material.WRITTEN_BOOK, count);
BookMeta book = (BookMeta) bookItem.getItemMeta();
book.setAuthor(messages.get("books.default.author"));
String title = null;
if (category != null) {
title = messages.get("books.default.title").replace("$category", category.getName());
} else {
title = messages.get("books.all.title");
}
book.setTitle(title);
List<String> pages = new ArrayList<>();
Set<String> paths = WandUpgradePath.getPathKeys();
for (String key : categoryKeys) {
category = getCategory(key);
title = messages.get("books.default.title").replace("$category", category.getName());
String description = "" + ChatColor.BOLD + ChatColor.BLUE + title + "\n\n";
description += "" + ChatColor.RESET + ChatColor.DARK_BLUE + category.getDescription();
pages.add(description);
List<SpellTemplate> categorySpells = categories.get(key);
Collections.sort(categorySpells);
for (SpellTemplate spell : categorySpells) {
List<String> lines = new ArrayList<>();
lines.add("" + ChatColor.GOLD + ChatColor.BOLD + spell.getName());
lines.add("" + ChatColor.RESET);
String spellDescription = spell.getDescription();
if (spellDescription != null && spellDescription.length() > 0) {
lines.add("" + ChatColor.BLACK + spellDescription);
lines.add("");
}
String spellCooldownDescription = spell.getCooldownDescription();
if (spellCooldownDescription != null && spellCooldownDescription.length() > 0) {
spellCooldownDescription = messages.get("cooldown.description").replace("$time", spellCooldownDescription);
lines.add("" + ChatColor.DARK_PURPLE + spellCooldownDescription);
}
String spellMageCooldownDescription = spell.getMageCooldownDescription();
if (spellMageCooldownDescription != null && spellMageCooldownDescription.length() > 0) {
spellMageCooldownDescription = messages.get("cooldown.mage_description").replace("$time", spellMageCooldownDescription);
lines.add("" + ChatColor.RED + spellMageCooldownDescription);
}
Collection<CastingCost> costs = spell.getCosts();
if (costs != null) {
for (CastingCost cost : costs) {
if (!cost.isEmpty(reducer)) {
lines.add(ChatColor.DARK_PURPLE + messages.get("wand.costs_description").replace("$description", cost.getFullDescription(messages, reducer)));
}
}
}
Collection<CastingCost> activeCosts = spell.getActiveCosts();
if (activeCosts != null) {
for (CastingCost cost : activeCosts) {
if (!cost.isEmpty(reducer)) {
lines.add(ChatColor.DARK_PURPLE + messages.get("wand.active_costs_description").replace("$description", cost.getFullDescription(messages, reducer)));
}
}
}
for (String pathKey : paths) {
WandUpgradePath checkPath = WandUpgradePath.getPath(pathKey);
if (!checkPath.isHidden() && (checkPath.hasSpell(spell.getKey()) || checkPath.hasExtraSpell(spell.getKey()))) {
lines.add(ChatColor.DARK_BLUE + messages.get("spell.available_path").replace("$path", checkPath.getName()));
break;
}
}
for (String pathKey : paths) {
WandUpgradePath checkPath = WandUpgradePath.getPath(pathKey);
if (checkPath.requiresSpell(spell.getKey())) {
lines.add(ChatColor.DARK_RED + messages.get("spell.required_path").replace("$path", checkPath.getName()));
break;
}
}
String duration = spell.getDurationDescription(messages);
if (duration != null) {
lines.add(ChatColor.DARK_GREEN + duration);
} else if (spell.showUndoable()) {
if (spell.isUndoable()) {
String undoable = messages.get("spell.undoable", "");
if (undoable != null && !undoable.isEmpty()) {
lines.add(undoable);
}
} else {
String notUndoable = messages.get("spell.not_undoable", "");
if (notUndoable != null && !notUndoable.isEmpty()) {
lines.add(notUndoable);
}
}
}
if (spell.usesBrush()) {
lines.add(ChatColor.DARK_GRAY + messages.get("spell.brush"));
}
SpellKey baseKey = spell.getSpellKey();
SpellKey upgradeKey = new SpellKey(baseKey.getBaseKey(), baseKey.getLevel() + 1);
SpellTemplate upgradeSpell = getSpellTemplate(upgradeKey.getKey());
int spellLevels = 0;
while (upgradeSpell != null) {
spellLevels++;
upgradeKey = new SpellKey(upgradeKey.getBaseKey(), upgradeKey.getLevel() + 1);
upgradeSpell = getSpellTemplate(upgradeKey.getKey());
}
if (spellLevels > 0) {
spellLevels++;
lines.add(ChatColor.DARK_AQUA + messages.get("spell.levels_available").replace("$levels", Integer.toString(spellLevels)));
}
String usage = spell.getUsage();
if (usage != null && usage.length() > 0) {
lines.add("" + ChatColor.GRAY + ChatColor.ITALIC + usage + ChatColor.RESET);
lines.add("");
}
String spellExtendedDescription = spell.getExtendedDescription();
if (spellExtendedDescription != null && spellExtendedDescription.length() > 0) {
lines.add("" + ChatColor.BLACK + spellExtendedDescription);
lines.add("");
}
pages.add(StringUtils.join(lines, "\n"));
}
}
book.setPages(pages);
bookItem.setItemMeta(book);
return bookItem;
}
use of com.elmakers.mine.bukkit.api.spell.SpellTemplate in project MagicPlugin by elBukkit.
the class MagicController method getWorth.
@Nullable
@Override
public Double getWorth(ItemStack item) {
String spellKey = Wand.getSpell(item);
if (spellKey != null) {
SpellTemplate spell = getSpellTemplate(spellKey);
if (spell != null) {
return spell.getWorth();
}
}
int amount = item.getAmount();
item.setAmount(1);
ItemData configuredItem = items.get(item);
item.setAmount(amount);
if (configuredItem == null) {
return null;
}
return configuredItem.getWorth() * amount;
}
use of com.elmakers.mine.bukkit.api.spell.SpellTemplate 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.SpellTemplate in project MagicPlugin by elBukkit.
the class CastCommandExecutor method onTabComplete.
@Override
public Collection<String> onTabComplete(CommandSender sender, String commandName, String[] args) {
Collection<String> options = new HashSet<>();
String permissionKey = "cast";
if (commandName.contains("castp")) {
permissionKey = "castp";
if (args.length == 1) {
options.addAll(api.getPlayerNames());
return options;
} else if (args.length > 1) {
args = Arrays.copyOfRange(args, 1, args.length);
}
}
if (args.length == 1) {
Collection<SpellTemplate> spellList = api.getController().getSpellTemplates(true);
for (SpellTemplate spell : spellList) {
addIfPermissible(sender, options, "Magic." + permissionKey + ".", spell.getKey());
}
}
if (args.length > 1 && sender.hasPermission("Magic.commands.cast.parameters")) {
String spellName = args[0];
SpellTemplate spell = api.getSpellTemplate(spellName);
if (spell != null) {
if (args.length % 2 == 0) {
spell.getParameters(options);
} else {
spell.getParameterOptions(options, args[args.length - 2]);
}
}
}
return options;
}
use of com.elmakers.mine.bukkit.api.spell.SpellTemplate in project MagicPlugin by elBukkit.
the class MageCommandExecutor method onTabComplete.
@Override
public Collection<String> onTabComplete(CommandSender sender, String commandName, String[] args) {
List<String> options = new ArrayList<>();
if (args.length == 1) {
addIfPermissible(sender, options, "Magic.commands.mage.", "add");
addIfPermissible(sender, options, "Magic.commands.mage.", "remove");
addIfPermissible(sender, options, "Magic.commands.mage.", "configure");
addIfPermissible(sender, options, "Magic.commands.mage.", "describe");
addIfPermissible(sender, options, "Magic.commands.mage.", "upgrade");
addIfPermissible(sender, options, "Magic.commands.mage.", "getdata");
addIfPermissible(sender, options, "Magic.commands.mage.", "setdata");
addIfPermissible(sender, options, "Magic.commands.mage.", "check");
addIfPermissible(sender, options, "Magic.commands.mage.", "debug");
addIfPermissible(sender, options, "Magic.commands.mage.", "reset");
addIfPermissible(sender, options, "Magic.commands.mage.", "unbind");
addIfPermissible(sender, options, "Magic.commands.mage.", "activate");
addIfPermissible(sender, options, "Magic.commands.mage.", "unlock");
addIfPermissible(sender, options, "Magic.commands.mage.", "lock");
addIfPermissible(sender, options, "Magic.commands.mage.", "levelspells");
addIfPermissible(sender, options, "Magic.commands.mage.", "attribute");
} else if (args.length == 2 && sender.hasPermission("Magic.commands.mage.others")) {
options.addAll(api.getPlayerNames());
}
if (args.length == 3 || args.length == 2) {
CommandSender target = args.length == 2 ? sender : DeprecatedUtils.getPlayer(args[1]);
String subCommand = args[0];
String subCommandPNode = "Magic.commands.mage." + subCommand;
if (subCommand.equalsIgnoreCase("setdata") || subCommand.equalsIgnoreCase("getdata")) {
if (target != null) {
Mage mage = controller.getMage(target);
ConfigurationSection data = mage.getData();
options.addAll(data.getKeys(false));
}
}
if (subCommand.equalsIgnoreCase("add")) {
Collection<SpellTemplate> spellList = api.getSpellTemplates(sender.hasPermission("Magic.bypass_hidden"));
for (SpellTemplate spell : spellList) {
addIfPermissible(sender, options, subCommandPNode, spell.getKey(), true);
}
addIfPermissible(sender, options, subCommandPNode, "brush", true);
}
if (subCommand.equalsIgnoreCase("remove")) {
if (target != null) {
Mage mage = controller.getMage(target);
MageClass mageClass = mage.getActiveClass();
if (mageClass != null) {
options.addAll(mageClass.getSpells());
}
}
options.add("brush");
}
if (subCommand.equalsIgnoreCase("configure") || subCommand.equalsIgnoreCase("describe") || subCommand.equalsIgnoreCase("upgrade")) {
for (String key : BaseMagicProperties.PROPERTY_KEYS) {
options.add(key);
}
for (String protection : api.getController().getDamageTypes()) {
options.add("protection." + protection);
}
}
if (subCommand.equalsIgnoreCase("attribute")) {
for (String attribute : api.getController().getAttributes()) {
options.add(attribute);
}
}
if (subCommand.equalsIgnoreCase("add")) {
Collection<SpellTemplate> spellList = api.getSpellTemplates(sender.hasPermission("Magic.bypass_hidden"));
for (SpellTemplate spell : spellList) {
addIfPermissible(sender, options, subCommandPNode, spell.getKey(), true);
}
addIfPermissible(sender, options, subCommandPNode, "brush", true);
}
if (args[0].equalsIgnoreCase("lock") || args[0].equalsIgnoreCase("unlock") || args[0].equalsIgnoreCase("activate")) {
options.addAll(api.getController().getMageClassKeys());
}
}
return options;
}
Aggregations