Java Code Examples for com.dsh105.commodus.config.YAMLConfig#getInt()

The following examples show how to use com.dsh105.commodus.config.YAMLConfig#getInt() . 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 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 2
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 3
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 4
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 5
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 6
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();
}