Search in sources :

Example 6 with SpellCategory

use of com.elmakers.mine.bukkit.api.spell.SpellCategory in project MagicPlugin by elBukkit.

the class SpellsCommandExecutor method listSpellsByCategory.

public void listSpellsByCategory(CommandSender sender, String category) {
    List<SpellTemplate> categorySpells = new ArrayList<>();
    Collection<SpellTemplate> spellVariants = api.getSpellTemplates(sender.hasPermission("Magic.bypass_hidden"));
    Player player = sender instanceof Player ? (Player) sender : null;
    for (SpellTemplate spell : spellVariants) {
        SpellCategory spellCategory = spell.getCategory();
        if (spellCategory != null && spellCategory.getKey().equalsIgnoreCase(category) && (player == null || spell.hasCastPermission(player))) {
            categorySpells.add(spell);
        }
    }
    if (categorySpells.size() == 0) {
        String message = api.getMessages().get("general.no_spells_in_category");
        message = message.replace("$category", category);
        sender.sendMessage(message);
        return;
    }
    sender.sendMessage(category + ":");
    Collections.sort(categorySpells);
    for (SpellTemplate spell : categorySpells) {
        String name = spell.getName();
        String description = spell.getDescription();
        if (!name.equals(spell.getKey())) {
            description = name + " : " + description;
        }
        sender.sendMessage(ChatColor.AQUA + spell.getKey() + ChatColor.BLUE + " [" + spell.getIcon().getName() + "] : " + ChatColor.YELLOW + description);
    }
}
Also used : Player(org.bukkit.entity.Player) SpellCategory(com.elmakers.mine.bukkit.api.spell.SpellCategory) ArrayList(java.util.ArrayList) SpellTemplate(com.elmakers.mine.bukkit.api.spell.SpellTemplate)

Aggregations

SpellCategory (com.elmakers.mine.bukkit.api.spell.SpellCategory)6 SpellTemplate (com.elmakers.mine.bukkit.api.spell.SpellTemplate)5 ArrayList (java.util.ArrayList)4 Player (org.bukkit.entity.Player)2 MaterialAndData (com.elmakers.mine.bukkit.api.block.MaterialAndData)1 CastEvent (com.elmakers.mine.bukkit.api.event.CastEvent)1 PreCastEvent (com.elmakers.mine.bukkit.api.event.PreCastEvent)1 MageController (com.elmakers.mine.bukkit.api.magic.MageController)1 Messages (com.elmakers.mine.bukkit.api.magic.Messages)1 MageSpell (com.elmakers.mine.bukkit.api.spell.MageSpell)1 Spell (com.elmakers.mine.bukkit.api.spell.Spell)1 SpellKey (com.elmakers.mine.bukkit.api.spell.SpellKey)1 SpellResult (com.elmakers.mine.bukkit.api.spell.SpellResult)1 Wand (com.elmakers.mine.bukkit.api.wand.Wand)1 WandUpgradePath (com.elmakers.mine.bukkit.api.wand.WandUpgradePath)1 Wand (com.elmakers.mine.bukkit.wand.Wand)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1