com.dsh105.commodus.config.YAMLConfig Java Examples

The following examples show how to use com.dsh105.commodus.config.YAMLConfig. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SelectorLayout.java    From EchoPet with GNU General Public License v3.0 6 votes vote down vote up
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;
}
 
Example #2
Source File: SelectorLayout.java    From SonarPet with GNU General Public License v3.0 6 votes vote down vote up
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;
}
 
Example #3
Source File: EchoPet.java    From SonarPet with GNU General Public License v3.0 5 votes vote down vote up
public static YAMLConfig getConfig(ConfigType type) {
    switch (type) {
        case DATA:
            return PLUGIN.getPetConfig();
        case LANG:
            return PLUGIN.getLangConfig();
        default:
            return PLUGIN.getMainConfig();
    }
}
 
Example #4
Source File: SelectorLayout.java    From EchoPet with GNU General Public License v3.0 5 votes vote down vote up
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();
}
 
Example #5
Source File: PetNames.java    From EchoPet with GNU General Public License v3.0 5 votes vote down vote up
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;
}
 
Example #6
Source File: EchoPet.java    From EchoPet with GNU General Public License v3.0 5 votes vote down vote up
public static YAMLConfig getConfig(ConfigType type) {
    switch (type) {
        case DATA:
            return PLUGIN.getPetConfig();
        case LANG:
            return PLUGIN.getLangConfig();
        default:
            return PLUGIN.getMainConfig();
    }
}
 
Example #7
Source File: SimpleImageLoader.java    From HoloAPI with GNU General Public License v3.0 5 votes vote down vote up
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.");
    }
}
 
Example #8
Source File: SimpleAnimationLoader.java    From HoloAPI with GNU General Public License v3.0 5 votes vote down vote up
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.");
    }
}
 
Example #9
Source File: UnicodeFormatter.java    From HoloAPI with GNU General Public License v3.0 5 votes vote down vote up
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;
}
 
Example #10
Source File: HoloAPICore.java    From HoloAPI with GNU General Public License v3.0 5 votes vote down vote up
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));
}
 
Example #11
Source File: SelectorLayout.java    From SonarPet with GNU General Public License v3.0 5 votes vote down vote up
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();
}
 
Example #12
Source File: PetNames.java    From SonarPet with GNU General Public License v3.0 5 votes vote down vote up
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;
}
 
Example #13
Source File: EchoPetPlugin.java    From EchoPet with GNU General Public License v3.0 4 votes vote down vote up
@Override
public YAMLConfig getMainConfig() {
    return mainConfig;
}
 
Example #14
Source File: EchoPet.java    From SonarPet with GNU General Public License v3.0 4 votes vote down vote up
public static YAMLConfig getConfig() {
    return getConfig(ConfigType.MAIN);
}
 
Example #15
Source File: ConfigOptions.java    From EchoPet with GNU General Public License v3.0 4 votes vote down vote up
public ConfigOptions(YAMLConfig config) {
    super(config);
    instance = this;
    SelectorLayout.loadLayout();
}
 
Example #16
Source File: EchoPet.java    From EchoPet with GNU General Public License v3.0 4 votes vote down vote up
public static YAMLConfig getConfig() {
    return getConfig(ConfigType.MAIN);
}
 
Example #17
Source File: EchoPetPlugin.java    From EchoPet with GNU General Public License v3.0 4 votes vote down vote up
@Override
public YAMLConfig getLangConfig() {
    return langConfig;
}
 
Example #18
Source File: EchoPetPlugin.java    From SonarPet with GNU General Public License v3.0 4 votes vote down vote up
@Override
public YAMLConfig getMainConfig() {
    return mainConfig;
}
 
Example #19
Source File: EchoPetPlugin.java    From EchoPet with GNU General Public License v3.0 4 votes vote down vote up
@Override
public YAMLConfig getPetConfig() {
    return this.petConfig;
}
 
Example #20
Source File: ConfigOptions.java    From SonarPet with GNU General Public License v3.0 4 votes vote down vote up
public ConfigOptions(YAMLConfig config) {
    super(config);
    instance = this;
    SelectorLayout.loadLayout();
}
 
Example #21
Source File: Settings.java    From HoloAPI with GNU General Public License v3.0 4 votes vote down vote up
public Settings(YAMLConfig config) {
    super(config);
}
 
Example #22
Source File: Lang.java    From HoloAPI with GNU General Public License v3.0 4 votes vote down vote up
public Lang(YAMLConfig config) {
    super(config);
}
 
Example #23
Source File: HoloAPI.java    From HoloAPI with GNU General Public License v3.0 4 votes vote down vote up
public static YAMLConfig getConfig(ConfigType type) {
    return getCore().getConfig(type);
}
 
Example #24
Source File: HoloAPICore.java    From HoloAPI with GNU General Public License v3.0 4 votes vote down vote up
public YAMLConfig getConfig(ConfigType configType) {
    return CONFIG_FILES.get(configType);
}
 
Example #25
Source File: EchoPetPlugin.java    From SonarPet with GNU General Public License v3.0 4 votes vote down vote up
@Override
public YAMLConfig getPetConfig() {
    return this.petConfig;
}
 
Example #26
Source File: EchoPetPlugin.java    From SonarPet with GNU General Public License v3.0 4 votes vote down vote up
@Override
public YAMLConfig getLangConfig() {
    return langConfig;
}
 
Example #27
Source File: IEchoPetPlugin.java    From SonarPet with GNU General Public License v3.0 votes vote down vote up
public YAMLConfig getLangConfig(); 
Example #28
Source File: IEchoPetPlugin.java    From EchoPet with GNU General Public License v3.0 votes vote down vote up
public YAMLConfig getPetConfig(); 
Example #29
Source File: IEchoPetPlugin.java    From EchoPet with GNU General Public License v3.0 votes vote down vote up
public YAMLConfig getMainConfig(); 
Example #30
Source File: IEchoPetPlugin.java    From EchoPet with GNU General Public License v3.0 votes vote down vote up
public YAMLConfig getLangConfig();