Search in sources :

Example 96 with ChatColor

use of org.bukkit.ChatColor in project MagicPlugin by elBukkit.

the class ChatUtils method getSimpleMessage.

@SuppressWarnings("unchecked")
protected static void getSimpleMessage(Map<String, Object> mapped, StringBuilder plainMessage, boolean onlyText, String commandPrefix, String commandSuffix) {
    for (Map.Entry<String, Object> entry : mapped.entrySet()) {
        if (entry.getKey().equals("text")) {
            plainMessage.append(entry.getValue());
        } else if (entry.getKey().equals("extra")) {
            Object rawExtra = entry.getValue();
            if (rawExtra instanceof List) {
                List<Map<String, Object>> mapList = (List<Map<String, Object>>) rawExtra;
                for (Map<String, Object> child : mapList) {
                    getSimpleMessage(child, plainMessage, onlyText);
                }
            }
        } else if (entry.getKey().equals("keybind")) {
            String key = entry.getValue().toString().replace("key.", "");
            if (messages != null) {
                key = messages.get("keybind." + key, key);
            }
            plainMessage.append(commandPrefix + key + commandSuffix);
        } else if (onlyText) {
            continue;
        } else if (entry.getKey().equals("color")) {
            String colorKey = entry.getValue().toString();
            try {
                ChatColor color = ChatColor.valueOf(colorKey.toUpperCase());
                plainMessage.append(color);
            } catch (Exception ignore) {
            }
        } else if (entry.getKey().equals("clickEvent")) {
            Map<String, Object> properties = (Map<String, Object>) entry.getValue();
            if (properties.containsKey("action") && properties.containsKey("value")) {
                String value = properties.get("value").toString();
                String action = properties.get("action").toString();
                switch(action) {
                    case "open_url":
                    case "run_command":
                    case "suggest_command":
                        plainMessage.append(commandPrefix + value + commandSuffix);
                        break;
                }
            }
        }
    }
}
Also used : List(java.util.List) Map(java.util.Map) ChatColor(org.bukkit.ChatColor)

Example 97 with ChatColor

use of org.bukkit.ChatColor in project MagicPlugin by elBukkit.

the class SpellProgressAction method perform.

@Override
public SpellResult perform(CastContext context) {
    Mage mage = context.getMage();
    CasterProperties casterProperties = context.getActiveProperties();
    this.context = context;
    Player player = mage.getPlayer();
    if (player == null) {
        return SpellResult.PLAYER_REQUIRED;
    }
    Collection<String> spells = casterProperties.getSpells();
    Collection<ItemStack> upgrades = new ArrayList<>();
    Messages messages = context.getController().getMessages();
    for (String spellKey : spells) {
        MageSpell spell = mage.getSpell(spellKey);
        if (spell == null) {
            context.getLogger().info("Player " + mage.getName() + " has spell " + spellKey + " but returned null");
            continue;
        }
        SpellTemplate upgradeSpell = spell.getUpgrade();
        ProgressionPath currentPath = casterProperties.getPath();
        if (upgradeSpell != null) {
            ItemStack spellItem = MagicPlugin.getAPI().createSpellItem(upgradeSpell.getKey());
            if (spellItem != null) {
                long requiredCastCount = spell.getRequiredUpgradeCasts();
                String requiredPathKey = spell.getRequiredUpgradePath();
                Set<String> requiredPathTags = spell.getRequiredUpgradeTags();
                ItemMeta meta = spellItem.getItemMeta();
                List<String> lore = new ArrayList<>();
                String levelDescription = upgradeSpell.getLevelDescription();
                if (levelDescription == null || levelDescription.isEmpty()) {
                    levelDescription = upgradeSpell.getName();
                }
                lore.add(levelDescription);
                String upgradeDescription = upgradeSpell.getUpgradeDescription();
                if (upgradeDescription != null && !upgradeDescription.isEmpty()) {
                    CompatibilityLib.getInventoryUtils().wrapText(upgradeDescription, context.getController().getMessages().get("spell.upgrade_description_prefix"), lore);
                }
                if (requiredPathKey != null && currentPath == null) {
                    continue;
                }
                if (!upgradeSpell.getName().equals(spell.getName())) {
                    CompatibilityLib.getInventoryUtils().wrapText(context.getMessage("upgrade_name_change", "&r&4Upgrades: &r$name").replace("$name", spell.getName()), lore);
                }
                if (requiredPathKey != null && !currentPath.hasPath(requiredPathKey)) {
                    requiredPathKey = currentPath.translatePath(requiredPathKey);
                    com.elmakers.mine.bukkit.wand.WandUpgradePath upgradePath = com.elmakers.mine.bukkit.wand.WandUpgradePath.getPath(requiredPathKey);
                    if (upgradePath == null)
                        continue;
                    CompatibilityLib.getInventoryUtils().wrapText(context.getMessage("level_requirement").replace("$path", upgradePath.getName()), lore);
                }
                if (requiredPathTags != null && !requiredPathTags.isEmpty() && !currentPath.hasAllTags(requiredPathTags)) {
                    Set<String> tags = currentPath.getMissingTags(requiredPathTags);
                    CompatibilityLib.getInventoryUtils().wrapText(context.getMessage("tags_requirement").replace("$tags", messages.formatList("tags", tags, "name")), lore);
                }
                long castCount = Math.min(spell.getCastCount(), requiredCastCount);
                ChatColor prefixColor = castCount == requiredCastCount ? ChatColor.GREEN : ChatColor.RED;
                CompatibilityLib.getInventoryUtils().wrapText(prefixColor + context.getMessage("cast_requirement").replace("$current", Long.toString(castCount)).replace("$required", Long.toString(requiredCastCount)), lore);
                meta.setLore(lore);
                spellItem.setItemMeta(meta);
                upgrades.add(spellItem);
            }
        }
    }
    String inventoryTitle = context.getMessage("title", "Spell Upgrades");
    int invSize = ((upgrades.size() + 9) / 9) * 9;
    Inventory displayInventory = CompatibilityLib.getCompatibilityUtils().createInventory(null, invSize, inventoryTitle);
    for (ItemStack item : upgrades) {
        displayInventory.addItem(item);
    }
    mage.activateGUI(this, displayInventory);
    return SpellResult.CAST;
}
Also used : ProgressionPath(com.elmakers.mine.bukkit.api.magic.ProgressionPath) CasterProperties(com.elmakers.mine.bukkit.api.magic.CasterProperties) Player(org.bukkit.entity.Player) Messages(com.elmakers.mine.bukkit.api.magic.Messages) ArrayList(java.util.ArrayList) Mage(com.elmakers.mine.bukkit.api.magic.Mage) ItemStack(org.bukkit.inventory.ItemStack) ChatColor(org.bukkit.ChatColor) MageSpell(com.elmakers.mine.bukkit.api.spell.MageSpell) ItemMeta(org.bukkit.inventory.meta.ItemMeta) Inventory(org.bukkit.inventory.Inventory) SpellTemplate(com.elmakers.mine.bukkit.api.spell.SpellTemplate)

Example 98 with ChatColor

use of org.bukkit.ChatColor in project MagicPlugin by elBukkit.

the class CasterProperties method describe.

@Override
public void describe(CommandSender sender, @Nullable Set<String> ignoreProperties, @Nullable Set<String> overriddenProperties) {
    super.describe(sender, ignoreProperties, overriddenProperties);
    ProgressionPath path = getPath();
    if (path != null && pathOverridesAllowed()) {
        ConfigurationSection pathProperties = path.getProperties();
        if (pathProperties != null) {
            sender.sendMessage(ChatColor.GOLD + "Path Properties Override:");
            Set<String> keys = pathProperties.getKeys(false);
            for (String key : keys) {
                Object value = pathProperties.get(key);
                if (value != null && (ignoreProperties == null || !ignoreProperties.contains(key))) {
                    ChatColor propertyColor = ChatColor.YELLOW;
                    sender.sendMessage(propertyColor.toString() + key + ChatColor.GRAY + ": " + ChatColor.WHITE + describeProperty(value));
                }
            }
        }
    }
}
Also used : ProgressionPath(com.elmakers.mine.bukkit.api.magic.ProgressionPath) ChatColor(org.bukkit.ChatColor) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Example 99 with ChatColor

use of org.bukkit.ChatColor in project MagicPlugin by elBukkit.

the class MagicCommandExecutor method onMagicList.

protected boolean onMagicList(CommandSender sender, String subCommand, String[] args) {
    String usage = "Usage: magic list <wands|map|automata|tasks|schematics|entities|blocks>";
    String listCommand = "";
    if (args.length > 1) {
        listCommand = args[1];
        if (!api.hasPermission(sender, "magic.commands.magic." + subCommand + "." + listCommand)) {
            sendNoPermission(sender);
            return false;
        }
    } else {
        sender.sendMessage(ChatColor.GRAY + "For more specific information, add 'tasks', 'wands', 'maps', 'schematics', 'entities', 'blocks' or 'automata' parameter.");
        long timeout = controller.getPhysicsTimeout();
        if (timeout > 0) {
            long seconds = (timeout - System.currentTimeMillis()) / 1000;
            sender.sendMessage(ChatColor.GREEN + "Physics handler active for another " + ChatColor.DARK_GREEN + seconds + ChatColor.GREEN + " seconds");
        }
        int spawnsProcessed = controller.getWorlds().getSpawnListener().getProcessedSpawns();
        if (spawnsProcessed > 0) {
            sender.sendMessage(ChatColor.AQUA + "Spawns Replaced: " + ChatColor.LIGHT_PURPLE + spawnsProcessed);
        }
        int chunkSpawnsProcessed = controller.getWorlds().getSpawnListener().getProcessedChunkSpawns();
        if (chunkSpawnsProcessed > 0) {
            sender.sendMessage(ChatColor.AQUA + "Chunk Gen Spawns Replaced: " + ChatColor.LIGHT_PURPLE + chunkSpawnsProcessed);
        }
        Collection<Mage> mages = controller.getMages();
        int lockedChunks = controller.getLockedChunks().size();
        if (lockedChunks > 0) {
            sender.sendMessage(ChatColor.AQUA + "Locked Chunks: " + ChatColor.LIGHT_PURPLE + lockedChunks);
        }
        sender.sendMessage(ChatColor.AQUA + "Modified blocks: " + ChatColor.LIGHT_PURPLE + UndoList.getRegistry().getModified().size());
        sender.sendMessage(ChatColor.AQUA + "Watching blocks: " + ChatColor.LIGHT_PURPLE + UndoList.getRegistry().getWatching().size());
        int breakingCount = UndoList.getRegistry().getBreaking().size();
        if (breakingCount > 0) {
            sender.sendMessage(ChatColor.AQUA + "Registered breaking: " + ChatColor.LIGHT_PURPLE + breakingCount);
        }
        int breakableCount = UndoList.getRegistry().getBreakable().size();
        if (breakableCount > 0) {
            sender.sendMessage(ChatColor.AQUA + "Registered breakable: " + ChatColor.LIGHT_PURPLE + breakableCount);
        }
        int reflectiveCount = UndoList.getRegistry().getReflective().size();
        if (reflectiveCount > 0) {
            sender.sendMessage(ChatColor.AQUA + "Registered reflective: " + ChatColor.LIGHT_PURPLE + reflectiveCount);
        }
        int lightCount = controller.getLightCount();
        if (lightCount > 0) {
            sender.sendMessage(ChatColor.AQUA + "Registered lights: " + ChatColor.LIGHT_PURPLE + lightCount);
        }
        sender.sendMessage(ChatColor.LIGHT_PURPLE + "Active mages: " + ChatColor.LIGHT_PURPLE + mages.size());
        Collection<com.elmakers.mine.bukkit.api.block.UndoList> pendingUndo = api.getPendingUndo();
        sender.sendMessage(ChatColor.AQUA + "Pending undo (" + ChatColor.LIGHT_PURPLE + pendingUndo.size() + ChatColor.AQUA + "): ");
        long now = System.currentTimeMillis();
        for (com.elmakers.mine.bukkit.api.block.UndoList undo : pendingUndo) {
            long remainingTime = (undo.getScheduledTime() - now) / 1000;
            sender.sendMessage(ChatColor.AQUA + undo.getName() + ChatColor.GRAY + " will undo in " + ChatColor.WHITE + "" + remainingTime + "" + ChatColor.GRAY + " seconds");
        }
        Collection<Mage> pending = api.getMagesWithPendingBatches();
        sender.sendMessage(ChatColor.AQUA + "Pending casts (" + ChatColor.LIGHT_PURPLE + pending.size() + ChatColor.AQUA + "): ");
        for (Mage mage : pending) {
            int totalSize = 0;
            int totalRemaining = 0;
            Collection<Batch> pendingBatches = mage.getPendingBatches();
            String names = "";
            if (pendingBatches.size() > 0) {
                List<String> nameList = new ArrayList<>();
                for (Batch batch : pendingBatches) {
                    nameList.add(batch.getName());
                    totalSize += batch.size();
                    totalRemaining += batch.remaining();
                }
                names = StringUtils.join(nameList, ChatColor.GRAY + "," + ChatColor.YELLOW);
            }
            int percent = totalSize > 0 ? totalRemaining * 100 / totalSize : 100;
            percent = 100 - Math.min(100, percent);
            sender.sendMessage(ChatColor.AQUA + mage.getName() + ChatColor.GRAY + " has " + ChatColor.WHITE + "" + pendingBatches.size() + "" + ChatColor.GRAY + " pending (" + ChatColor.GOLD + percent + ChatColor.WHITE + "%" + ChatColor.GRAY + ") (" + ChatColor.YELLOW + names + ChatColor.GRAY + ")");
        }
        controller.checkLogs(sender);
        return true;
    }
    if (listCommand.equalsIgnoreCase("schematics")) {
        List<String> schematics = new ArrayList<>();
        try {
            Plugin plugin = (Plugin) api;
            // Find built-in schematics
            CodeSource src = MagicAPI.class.getProtectionDomain().getCodeSource();
            if (src != null) {
                URL jar = src.getLocation();
                try (InputStream is = jar.openStream();
                    ZipInputStream zip = new ZipInputStream(is)) {
                    while (true) {
                        ZipEntry e = zip.getNextEntry();
                        if (e == null)
                            break;
                        String name = e.getName();
                        if (name.startsWith("schematics/")) {
                            schematics.add(name.replace("schematics/", ""));
                        }
                    }
                }
            }
            // Check extra path first
            File configFolder = plugin.getDataFolder();
            File magicSchematicFolder = new File(configFolder, "schematics");
            if (magicSchematicFolder.exists()) {
                for (File nextFile : magicSchematicFolder.listFiles()) {
                    schematics.add(nextFile.getName());
                }
            }
            String extraSchematicFilePath = controller.getExtraSchematicFilePath();
            if (extraSchematicFilePath != null && extraSchematicFilePath.length() > 0) {
                File schematicFolder = new File(configFolder, "../" + extraSchematicFilePath);
                if (schematicFolder.exists() && !schematicFolder.equals(magicSchematicFolder)) {
                    for (File nextFile : schematicFolder.listFiles()) {
                        schematics.add(nextFile.getName());
                    }
                }
            }
        } catch (Exception ex) {
            sender.sendMessage("Error loading schematics: " + ex.getMessage());
            ex.printStackTrace();
            ;
        }
        sender.sendMessage(ChatColor.DARK_AQUA + "Found " + ChatColor.LIGHT_PURPLE + schematics.size() + ChatColor.DARK_AQUA + " schematics");
        Collections.sort(schematics);
        for (String schematic : schematics) {
            if (schematic.indexOf(".schematic") > 0) {
                sender.sendMessage(ChatColor.AQUA + schematic.replace(".schematic", ""));
            }
        }
        return true;
    }
    if (listCommand.equalsIgnoreCase("tasks")) {
        List<BukkitTask> tasks = Bukkit.getScheduler().getPendingTasks();
        HashMap<String, Integer> pluginCounts = new HashMap<>();
        HashMap<String, HashMap<String, Integer>> taskCounts = new HashMap<>();
        for (BukkitTask task : tasks) {
            String pluginName = task.getOwner().getName();
            HashMap<String, Integer> pluginTaskCounts = taskCounts.get(pluginName);
            if (pluginTaskCounts == null) {
                pluginTaskCounts = new HashMap<>();
                taskCounts.put(pluginName, pluginTaskCounts);
            }
            String className = "(Unknown)";
            Runnable taskRunnable = CompatibilityLib.getCompatibilityUtils().getTaskRunnable(task);
            if (taskRunnable != null) {
                Class<? extends Runnable> taskClass = taskRunnable.getClass();
                className = taskClass.getName();
            }
            Integer count = pluginTaskCounts.get(className);
            if (count == null)
                count = 0;
            count++;
            pluginTaskCounts.put(className, count);
            Integer totalCount = pluginCounts.get(pluginName);
            if (totalCount == null)
                totalCount = 0;
            totalCount++;
            pluginCounts.put(pluginName, totalCount);
        }
        sender.sendMessage(ChatColor.LIGHT_PURPLE + "Active tasks: " + tasks.size());
        for (Entry<String, HashMap<String, Integer>> pluginEntry : taskCounts.entrySet()) {
            String pluginName = pluginEntry.getKey();
            sender.sendMessage(" " + ChatColor.DARK_PURPLE + pluginName + ": " + ChatColor.LIGHT_PURPLE + pluginCounts.get(pluginName));
            for (Entry<String, Integer> taskEntry : pluginEntry.getValue().entrySet()) {
                sender.sendMessage("  " + ChatColor.DARK_PURPLE + taskEntry.getKey() + ": " + ChatColor.LIGHT_PURPLE + taskEntry.getValue());
            }
        }
        return true;
    }
    if (listCommand.equalsIgnoreCase("wands")) {
        String owner = "";
        if (args.length > 2) {
            owner = args[2];
        }
        Collection<LostWand> lostWands = api.getLostWands();
        int shown = 0;
        for (LostWand lostWand : lostWands) {
            Location location = lostWand.getLocation();
            if (location == null)
                continue;
            if (owner.length() > 0 && !owner.equalsIgnoreCase(lostWand.getOwner())) {
                continue;
            }
            shown++;
            sender.sendMessage(ChatColor.AQUA + lostWand.getName() + ChatColor.WHITE + " (" + lostWand.getOwner() + ") @ " + ChatColor.BLUE + location.getWorld().getName() + " " + location.getBlockX() + " " + location.getBlockY() + " " + location.getBlockZ());
        }
        sender.sendMessage(shown + " lost wands found" + (owner.length() > 0 ? " for " + owner : ""));
        return true;
    }
    if (listCommand.equalsIgnoreCase("automata")) {
        Collection<Mage> automata = api.getAutomata();
        for (Mage automaton : automata) {
            Location location = automaton.getLocation();
            String worldName = location.getWorld().getName();
            boolean isOnline = false;
            World world = Bukkit.getWorld(worldName);
            if (worldName != null) {
                isOnline = world.isChunkLoaded(location.getBlockX() >> 4, location.getBlockZ() >> 4);
            }
            ChatColor nameColor = isOnline ? ChatColor.AQUA : ChatColor.GRAY;
            sender.sendMessage(nameColor + automaton.getName() + ChatColor.WHITE + " @ " + ChatColor.BLUE + worldName + " " + location.getBlockX() + " " + location.getBlockY() + " " + location.getBlockZ());
        }
        sender.sendMessage(automata.size() + " automata active");
        return true;
    }
    if (listCommand.equalsIgnoreCase("maps")) {
        String keyword = "";
        for (int i = 2; i < args.length; i++) {
            if (i != 2)
                keyword = keyword + " ";
            keyword = keyword + args[i];
        }
        MagicMapCommandExecutor.onMapList(api.getController(), sender, keyword);
        return true;
    }
    if (listCommand.equalsIgnoreCase("blocks")) {
        for (BlockData blockData : UndoList.getRegistry().getModified().values()) {
            BlockVector blockLocation = blockData.getLocation();
            Block block = blockData.getBlock();
            com.elmakers.mine.bukkit.api.block.UndoList undoList = blockData.getUndoList();
            String listName = undoList == null ? "Unknown" : undoList.getName();
            String blockDescription = block == null ? "Unloaded" : block.getType().toString();
            sender.sendMessage(ChatColor.BLUE + "Block at " + ChatColor.GRAY + blockLocation.getBlockX() + ChatColor.DARK_GRAY + "," + ChatColor.GRAY + blockLocation.getBlockY() + ChatColor.DARK_GRAY + "," + ChatColor.GRAY + blockLocation.getBlockZ() + ChatColor.GRAY + " " + blockData.getWorldName() + ChatColor.BLUE + " stored as " + ChatColor.AQUA + blockData.getMaterial() + ChatColor.BLUE + " is currently " + ChatColor.AQUA + blockDescription + ChatColor.BLUE + " from " + ChatColor.GOLD + listName);
        }
        return true;
    }
    if (listCommand.equalsIgnoreCase("mages")) {
        for (Mage mage : api.getController().getMages()) {
            Entity mageEntity = mage.getEntity();
            Location location = mage.getLocation();
            ChatColor mageColor = ChatColor.YELLOW;
            if (mage instanceof com.elmakers.mine.bukkit.magic.Mage && ((com.elmakers.mine.bukkit.magic.Mage) mage).isForget()) {
                mageColor = ChatColor.RED;
            } else if (mage.isAutomaton()) {
                mageColor = ChatColor.GOLD;
            }
            String mageType = mageEntity == null ? "Non-Entity" : mageEntity.getType().name();
            String message = ChatColor.AQUA + "Mage " + mageColor + mage.getId() + ChatColor.GRAY + " (" + mage.getName() + ")" + ChatColor.AQUA + " of type " + ChatColor.DARK_AQUA + mageType + ChatColor.AQUA;
            if (location != null) {
                String worldName = location.getWorld() != null ? location.getWorld().getName() : "(Unknown world)";
                message = message + " is at " + ChatColor.BLUE + worldName + " " + ChatColor.DARK_PURPLE + " " + location.getBlockX() + " " + location.getBlockY() + " " + location.getBlockZ();
            }
            sender.sendMessage(message);
        }
        return true;
    }
    if (listCommand.equalsIgnoreCase("entities")) {
        World world = Bukkit.getWorlds().get(0);
        if (sender instanceof Player) {
            world = ((Player) sender).getLocation().getWorld();
        }
        NumberFormat formatter = new DecimalFormat("#0.0");
        List<EntityType> types = Arrays.asList(EntityType.values());
        Collections.sort(types, new Comparator<EntityType>() {

            @Override
            public int compare(EntityType o1, EntityType o2) {
                return o1.name().compareTo(o2.name());
            }
        });
        Collection<? extends Player> players = Bukkit.getServer().getOnlinePlayers();
        for (Player player : players) {
            showEntityInfo(sender, player, EntityType.PLAYER.name() + ChatColor.GRAY + " (" + player.getName() + " [" + (player.isSneaking() ? "sneaking" : "standing") + "])", formatter);
            break;
        }
        Collection<? extends Entity> entities = world.getEntities();
        for (Entity entity : entities) {
            showEntityInfo(sender, entity, entity.getType().name(), formatter);
        }
        return true;
    }
    sender.sendMessage(usage);
    return true;
}
Also used : Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) World(org.bukkit.World) LostWand(com.elmakers.mine.bukkit.api.wand.LostWand) Player(org.bukkit.entity.Player) CodeSource(java.security.CodeSource) EntityType(org.bukkit.entity.EntityType) ZipInputStream(java.util.zip.ZipInputStream) Mage(com.elmakers.mine.bukkit.api.magic.Mage) Block(org.bukkit.block.Block) File(java.io.File) ChatColor(org.bukkit.ChatColor) ZipEntry(java.util.zip.ZipEntry) DecimalFormat(java.text.DecimalFormat) URL(java.net.URL) UndoList(com.elmakers.mine.bukkit.block.UndoList) Batch(com.elmakers.mine.bukkit.api.batch.Batch) BlockData(com.elmakers.mine.bukkit.api.block.BlockData) MagicAPI(com.elmakers.mine.bukkit.api.magic.MagicAPI) ZipInputStream(java.util.zip.ZipInputStream) InputStream(java.io.InputStream) BukkitTask(org.bukkit.scheduler.BukkitTask) WandCleanupRunnable(com.elmakers.mine.bukkit.wand.WandCleanupRunnable) BlockVector(org.bukkit.util.BlockVector) Plugin(org.bukkit.plugin.Plugin) Location(org.bukkit.Location) NumberFormat(java.text.NumberFormat)

Example 100 with ChatColor

use of org.bukkit.ChatColor in project MagicPlugin by elBukkit.

the class MageCommandExecutor method onMageDescribe.

public boolean onMageDescribe(CommandSender sender, Player player, String[] parameters) {
    Mage mage = controller.getMage(player);
    MageClass activeClass = mage.getActiveClass();
    MagicProperties mageProperties = mage.getProperties();
    if (parameters.length == 0) {
        sender.sendMessage(ChatColor.AQUA + "Mage " + ChatColor.GOLD + mage.getName());
        sender.sendMessage(ChatColor.GRAY + mage.getId());
        sender.sendMessage(ChatColor.BLUE + "Use " + ChatColor.AQUA + "/mage describe <property>" + ChatColor.BLUE + " for specific properties");
        sender.sendMessage(ChatColor.BLUE + "Use " + ChatColor.AQUA + "/mage activate" + ChatColor.BLUE + " to change or clear the active class");
        Collection<String> classKeys = mage.getClassKeys();
        if (classKeys.size() > 0) {
            Collection<String> coloredClasses = new ArrayList<>();
            for (String classKey : classKeys) {
                ChatColor color = mage.hasClassUnlocked(classKey) ? ChatColor.GREEN : ChatColor.GRAY;
                coloredClasses.add(color + classKey);
            }
            sender.sendMessage(ChatColor.AQUA + "Classes: " + ChatColor.GREEN + StringUtils.join(coloredClasses, ","));
        }
        Collection<String> modifierKeys = mage.getModifierKeys();
        if (!modifierKeys.isEmpty()) {
            sender.sendMessage(ChatColor.AQUA + "Modifiers:");
            for (String modifierKey : modifierKeys) {
                MageModifier modifier = mage.getModifier(modifierKey);
                String modifierDescription = ChatColor.DARK_AQUA + modifier.getName();
                if (modifier.hasDuration()) {
                    int timeRemaining = modifier.getTimeRemaining();
                    modifierDescription += ChatColor.GRAY + " (" + ChatColor.WHITE + controller.getMessages().getTimeDescription(timeRemaining) + ChatColor.GRAY + ")";
                }
                sender.sendMessage(modifierDescription);
            }
        }
        if (!mageProperties.isEmpty()) {
            sender.sendMessage(ChatColor.AQUA + "Mage properties:");
            mageProperties.describe(sender, BaseMagicProperties.HIDDEN_PROPERTY_KEYS);
        }
        ConfigurationSection variables = mage.getVariables();
        Set<String> keys = variables.getKeys(false);
        if (!keys.isEmpty()) {
            sender.sendMessage(ChatColor.AQUA + "Mage variables:");
            for (String key : keys) {
                Object value = variables.get(key);
                if (value != null) {
                    sender.sendMessage(ChatColor.DARK_AQUA + key + ChatColor.GRAY + ": " + ChatColor.WHITE + CompatibilityLib.getInventoryUtils().describeProperty(value, CompatibilityConstants.MAX_PROPERTY_DISPLAY_LENGTH));
                }
            }
        }
        if (activeClass != null) {
            sender.sendMessage(ChatColor.AQUA + "Active class: " + ChatColor.GREEN + activeClass.getKey());
        } else {
            sender.sendMessage(ChatColor.DARK_GREEN + "No active class");
        }
        Set<Spell> activeSpells = mage.getActiveSpells();
        if (activeSpells != null && !activeSpells.isEmpty()) {
            Collection<String> spellNames = new ArrayList<>();
            for (Spell spell : activeSpells) {
                spellNames.add(spell.getName());
            }
            sender.sendMessage(ChatColor.AQUA + "Active spells: " + ChatColor.DARK_AQUA + StringUtils.join(spellNames, ","));
        }
        if (activeClass != null) {
            activeClass.describe(sender, BaseMagicProperties.HIDDEN_PROPERTY_KEYS);
        }
    } else {
        Object property = activeClass.getProperty(parameters[0]);
        if (property == null) {
            sender.sendMessage(ChatColor.DARK_AQUA + parameters[0] + ChatColor.GRAY + ": " + ChatColor.RED + "(Not Set)");
        } else {
            sender.sendMessage(ChatColor.DARK_AQUA + parameters[0] + ChatColor.GRAY + ": " + ChatColor.WHITE + CompatibilityLib.getInventoryUtils().describeProperty(property));
        }
    }
    return true;
}
Also used : MageClass(com.elmakers.mine.bukkit.api.magic.MageClass) MageModifier(com.elmakers.mine.bukkit.api.magic.MageModifier) ArrayList(java.util.ArrayList) BaseMagicProperties(com.elmakers.mine.bukkit.magic.BaseMagicProperties) MagicProperties(com.elmakers.mine.bukkit.api.magic.MagicProperties) Spell(com.elmakers.mine.bukkit.api.spell.Spell) MageSpell(com.elmakers.mine.bukkit.api.spell.MageSpell) Mage(com.elmakers.mine.bukkit.api.magic.Mage) ChatColor(org.bukkit.ChatColor) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Aggregations

ChatColor (org.bukkit.ChatColor)128 ArrayList (java.util.ArrayList)23 Player (org.bukkit.entity.Player)17 Matcher (java.util.regex.Matcher)9 World (org.bukkit.World)9 JSONObject (org.json.simple.JSONObject)9 ItemStack (org.bukkit.inventory.ItemStack)8 DyeColor (org.bukkit.DyeColor)7 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)7 ItemMeta (org.bukkit.inventory.meta.ItemMeta)7 Material (org.bukkit.Material)6 Team (org.bukkit.scoreboard.Team)6 Method (java.lang.reflect.Method)5 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 LinkedList (java.util.LinkedList)4 Mage (com.elmakers.mine.bukkit.api.magic.Mage)3 List (java.util.List)3 UUID (java.util.UUID)3 Scoreboard (org.bukkit.scoreboard.Scoreboard)3