Java源码示例:com.dsh105.commodus.config.YAMLConfig

示例1
public static ItemStack getSelectorItem() {
    YAMLConfig config = ConfigOptions.instance.getConfig();
    String name = config.getString("petSelector.item.name", "&aPets");
    int materialId = config.getInt("petSelector.item.materialId", Material.BONE.getId());
    int materialData = config.getInt("petSelector.item.materialData", 0);
    List<String> lore = config.config().getStringList("petSelector.item.lore");
    if (lore == null) {
        lore = new ArrayList<String>();
    }
    ItemStack i = new ItemStack(materialId, 1, (short) materialData);
    ItemMeta meta = i.getItemMeta();
    meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', name));
    ArrayList<String> loreList = new ArrayList<String>();
    if (lore.size() > 0) {
        for (String s : lore) {
            loreList.add(ChatColor.translateAlternateColorCodes('&', s));
        }
    }
    if (!loreList.isEmpty()) {
        meta.setLore(loreList);
    }
    i.setItemMeta(meta);
    return i;
}
 
示例2
public static ItemStack getSelectorItem() {
    YAMLConfig config = ConfigOptions.instance.getConfig();
    String name = config.getString("petSelector.item.name", "&aPets");
    int materialId = config.getInt("petSelector.item.materialId", Material.BONE.getId());
    int materialData = config.getInt("petSelector.item.materialData", 0);
    List<String> lore = config.config().getStringList("petSelector.item.lore");
    if (lore == null) {
        lore = new ArrayList<String>();
    }
    ItemStack i = new ItemStack(materialId, 1, (short) materialData);
    ItemMeta meta = i.getItemMeta();
    meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', name));
    ArrayList<String> loreList = new ArrayList<String>();
    if (lore.size() > 0) {
        for (String s : lore) {
            loreList.add(ChatColor.translateAlternateColorCodes('&', s));
        }
    }
    if (!loreList.isEmpty()) {
        meta.setLore(loreList);
    }
    i.setItemMeta(meta);
    return i;
}
 
示例3
public static YAMLConfig getConfig(ConfigType type) {
    switch (type) {
        case DATA:
            return PLUGIN.getPetConfig();
        case LANG:
            return PLUGIN.getLangConfig();
        default:
            return PLUGIN.getMainConfig();
    }
}
 
示例4
public static boolean allow(String input, IPet pet) {
    YAMLConfig config = ConfigOptions.instance.getConfig();
    String nameToCheck = ChatColor.stripColor(input);
    ConfigurationSection cs = config.getConfigurationSection("petNames");
    if (cs != null) {
        for (String key : cs.getKeys(false)) {
            if (key.equalsIgnoreCase(nameToCheck)) {
                String value = config.getString("petNames." + key);
                return pet.getOwner().hasPermission("echopet.pet.name.override") || !(value.equalsIgnoreCase("deny") || value.equalsIgnoreCase("false"));
            }
        }
    }

    if (config.getBoolean("petNamesRegexMatching")) {
        List<Map<String, String>> csRegex = (List<Map<String, String>>) config.get("petNamesRegex");
        if (!csRegex.isEmpty()) {
            for (Map<String, String> regexMap : csRegex) {
                for (Map.Entry<String, String> entry : regexMap.entrySet()) {
                    if (nameToCheck.matches(entry.getKey())) {
                        return pet.getOwner().hasPermission("echopet.pet.name.override")
                                || !(entry.getValue().equalsIgnoreCase("deny")
                                || entry.getValue().equalsIgnoreCase("false"));
                    }
                }
            }
        }
    }
    return true;
}
 
示例5
public static void loadLayout() {
    if (selectorMenu != null) {
        HandlerList.unregisterAll(selectorMenu);
    }

    selectorLayout.clear();
    YAMLConfig config = ConfigOptions.instance.getConfig();
    String s = "petSelector.menu";
    int size = config.getInt(s + ".slots");
    for (int i = 1; i <= size; i++) {
        String cmd = config.getString(s + ".slot-" + i + ".command");
        String petType = config.getString(s + ".slot-" + i + ".petType");
        PetType pt = null;
        if (petType != null && GeneralUtil.isEnumType(PetType.class, petType.toUpperCase())) {
            pt = PetType.valueOf(petType.toUpperCase());
        }
        int id = config.getInt(s + ".slot-" + i + ".materialId");
        int data = config.getInt(s + ".slot-" + i + ".materialData");
        String name = config.getString(s + ".slot-" + i + ".name");
        if (name == null) {
            continue;
        }
        List<String> lore = config.config().getStringList(s + ".slot-" + i + ".lore");
        if (lore == null) {
            lore = new ArrayList<String>();
        }
        ArrayList<String> loreList = new ArrayList<String>();
        if (lore.size() > 0) {
            for (String part : lore) {
                loreList.add(ChatColor.translateAlternateColorCodes('&', part));
            }
        }
        Material type = Material.getMaterial(id);
        selectorLayout.add(new SelectorIcon(i - 1, cmd, pt, ItemData.create(type, data).withDisplayName(name.trim().isEmpty() ? Optional.empty() : Optional.of(name)).withLore(loreList)));
    }

    selectorMenu = new SelectorMenu();
}
 
示例6
public void loadConfiguration() {
    configManager = new YAMLConfigManager(this);
    YAMLConfig config,
            dataConfig,
            langConfig;

    config = configManager.getNewConfig("config.yml", new String[]{
            "HoloAPI",
            "---------------------",
            "Configuration File",
            "",
            "See the HoloAPI Wiki before editing this file",
            "(https://github.com/DSH105/HoloAPI/wiki)"
    });
    langConfig = configManager.getNewConfig("messages.yml", new String[]{"HoloAPI", "---------------------", "Language Configuration File"});
    dataConfig = configManager.getNewConfig("data.yml");

    CONFIG_FILES.put(ConfigType.MAIN, config);
    CONFIG_FILES.put(ConfigType.LANG, langConfig);
    CONFIG_FILES.put(ConfigType.DATA, dataConfig);

    for (YAMLConfig yamlConfig : CONFIG_FILES.values()) {
        yamlConfig.reloadConfig();
    }

    SETTINGS.put(ConfigType.MAIN, new Settings(config));
    SETTINGS.put(ConfigType.LANG, new Lang(langConfig));
}
 
示例7
public static String replaceAll(String s) {
    YAMLConfig config = HoloAPI.getConfig(ConfigType.MAIN);
    ConfigurationSection cs = config.getConfigurationSection("specialCharacters");
    if (cs != null) {
        for (String key : cs.getKeys(false)) {
            if (s.contains(key)) {
                s = s.replace(key, StringEscapeUtils.unescapeJava("\\u" + config.getString("specialCharacters." + key)));
            }
        }
    }
    return s;
}
 
示例8
public void loadAnimationConfiguration(YAMLConfig config) {
    KEY_TO_IMAGE_MAP.clear();
    URL_UNLOADED.clear();
    File imageFolder = new File(HoloAPI.getCore().getDataFolder() + File.separator + "animations");
    if (!imageFolder.exists()) {
        imageFolder.mkdirs();
    }
    ConfigurationSection cs = config.getConfigurationSection("animations");
    if (cs != null) {
        for (String key : cs.getKeys(false)) {
            String path = "animations." + key + ".";
            String imagePath = config.getString(path + "path");
            if (imagePath == null) {
                HoloAPI.LOG.info("Failed to load animation: " + key + ". Invalid path");
                continue;
            }
            int imageHeight = config.getInt(path + "height", 10);
            int frameRate = config.getInt(path + "frameRate", 10);
            boolean requiresBorder = config.getBoolean(path + "requiresBorder", true);
            String imageChar = config.getString(path + "characterType", ImageChar.BLOCK.getHumanName());
            String imageType = config.getString(path + "type", "FILE");
            if (!GeneralUtil.isEnumType(ImageLoader.ImageLoadType.class, imageType.toUpperCase())) {
                HoloAPI.LOG.info("Failed to load animation: " + key + ". Invalid image type.");
                continue;
            }
            AnimationLoadType type = AnimationLoadType.valueOf(imageType.toUpperCase());

            AnimatedImageGenerator generator = findGenerator(type, key, imagePath, frameRate, imageHeight, imageChar, requiresBorder);
            if (generator != null) {
                this.KEY_TO_IMAGE_MAP.put(key, generator);
            }
        }
    }
    loaded = true;
    if (!KEY_TO_IMAGE_MAP.isEmpty() || !URL_UNLOADED.isEmpty()) {
        HoloAPI.LOG.info("Animations loaded.");
    }
}
 
示例9
public void loadImageConfiguration(YAMLConfig config) {
    KEY_TO_IMAGE_MAP.clear();
    URL_UNLOADED.clear();
    File imageFolder = new File(HoloAPI.getCore().getDataFolder() + File.separator + "images");
    if (!imageFolder.exists()) {
        imageFolder.mkdirs();
    }
    ConfigurationSection cs = config.getConfigurationSection("images");
    if (cs != null) {
        for (String key : cs.getKeys(false)) {
            String path = "images." + key + ".";
            String imagePath = config.getString(path + "path");
            int imageHeight = config.getInt(path + "height", 10);
            String imageChar = config.getString(path + "characterType", ImageChar.BLOCK.getHumanName());
            String imageType = config.getString(path + "type", "FILE");
            boolean requiresBorder = config.getBoolean(path + "requiresBorder", true);
            if (!GeneralUtil.isEnumType(ImageLoader.ImageLoadType.class, imageType.toUpperCase())) {
                HoloAPI.LOG.info("Failed to load image: " + key + ". Invalid image type.");
                continue;
            }
            ImageLoader.ImageLoadType type = ImageLoader.ImageLoadType.valueOf(imageType.toUpperCase());

            ImageGenerator generator = findGenerator(type, key, imagePath, imageHeight, imageChar, requiresBorder);
            if (generator != null) {
                this.KEY_TO_IMAGE_MAP.put(key, generator);
            }
        }
    }
    loaded = true;
    if (!KEY_TO_IMAGE_MAP.isEmpty() || !URL_UNLOADED.isEmpty()) {
        HoloAPI.LOG.info("Images loaded.");
    }
}
 
示例10
public static YAMLConfig getConfig(ConfigType type) {
    switch (type) {
        case DATA:
            return PLUGIN.getPetConfig();
        case LANG:
            return PLUGIN.getLangConfig();
        default:
            return PLUGIN.getMainConfig();
    }
}
 
示例11
public static boolean allow(String input, IPet pet) {
    YAMLConfig config = ConfigOptions.instance.getConfig();
    String nameToCheck = ChatColor.stripColor(input);
    ConfigurationSection cs = config.getConfigurationSection("petNames");
    if (cs != null) {
        for (String key : cs.getKeys(false)) {
            if (key.equalsIgnoreCase(nameToCheck)) {
                String value = config.getString("petNames." + key);
                return pet.getOwner().hasPermission("echopet.pet.name.override") || !(value.equalsIgnoreCase("deny") || value.equalsIgnoreCase("false"));
            }
        }
    }

    if (config.getBoolean("petNamesRegexMatching")) {
        List<Map<String, String>> csRegex = (List<Map<String, String>>) config.get("petNamesRegex");
        if (!csRegex.isEmpty()) {
            for (Map<String, String> regexMap : csRegex) {
                for (Map.Entry<String, String> entry : regexMap.entrySet()) {
                    if (nameToCheck.matches(entry.getKey())) {
                        return pet.getOwner().hasPermission("echopet.pet.name.override")
                                || !(entry.getValue().equalsIgnoreCase("deny")
                                || entry.getValue().equalsIgnoreCase("false"));
                    }
                }
            }
        }
    }
    return true;
}
 
示例12
public static void loadLayout() {
    if (selectorMenu != null) {
        HandlerList.unregisterAll(selectorMenu);
    }

    selectorLayout.clear();
    YAMLConfig config = ConfigOptions.instance.getConfig();
    String s = "petSelector.menu";
    int size = config.getInt(s + ".slots");
    for (int i = 1; i <= size; i++) {
        String cmd = config.getString(s + ".slot-" + i + ".command");
        String petType = config.getString(s + ".slot-" + i + ".petType");
        PetType pt = null;
        if (petType != null && GeneralUtil.isEnumType(PetType.class, petType.toUpperCase())) {
            pt = PetType.valueOf(petType.toUpperCase());
        }
        int id = config.getInt(s + ".slot-" + i + ".materialId");
        int data = config.getInt(s + ".slot-" + i + ".materialData");
        String name = config.getString(s + ".slot-" + i + ".name");
        if (name == null) {
            continue;
        }
        List<String> lore = config.config().getStringList(s + ".slot-" + i + ".lore");
        if (lore == null) {
            lore = new ArrayList<String>();
        }
        ArrayList<String> loreList = new ArrayList<String>();
        if (lore.size() > 0) {
            for (String part : lore) {
                loreList.add(ChatColor.translateAlternateColorCodes('&', part));
            }
        }
        selectorLayout.add(new SelectorIcon(i - 1, cmd, pt, id, data, name, loreList.toArray(new String[0])));
    }

    selectorMenu = new SelectorMenu();
}
 
示例13
public static YAMLConfig getConfig() {
    return getConfig(ConfigType.MAIN);
}
 
示例14
public ConfigOptions(YAMLConfig config) {
    super(config);
    instance = this;
    SelectorLayout.loadLayout();
}
 
示例15
@Override
public YAMLConfig getPetConfig() {
    return this.petConfig;
}
 
示例16
@Override
public YAMLConfig getMainConfig() {
    return mainConfig;
}
 
示例17
@Override
public YAMLConfig getLangConfig() {
    return langConfig;
}
 
示例18
public YAMLConfig getConfig(ConfigType configType) {
    return CONFIG_FILES.get(configType);
}
 
示例19
public static YAMLConfig getConfig(ConfigType type) {
    return getCore().getConfig(type);
}
 
示例20
public Lang(YAMLConfig config) {
    super(config);
}
 
示例21
public Settings(YAMLConfig config) {
    super(config);
}
 
示例22
@Override
public YAMLConfig getPetConfig() {
    return this.petConfig;
}
 
示例23
@Override
public YAMLConfig getMainConfig() {
    return mainConfig;
}
 
示例24
@Override
public YAMLConfig getLangConfig() {
    return langConfig;
}
 
示例25
public static YAMLConfig getConfig() {
    return getConfig(ConfigType.MAIN);
}
 
示例26
public ConfigOptions(YAMLConfig config) {
    super(config);
    instance = this;
    SelectorLayout.loadLayout();
}
 
示例27
public YAMLConfig getPetConfig(); 
示例28
public YAMLConfig getMainConfig(); 
示例29
public YAMLConfig getLangConfig(); 
示例30
public YAMLConfig getPetConfig();