Java Code Examples for com.dsh105.commodus.GeneralUtil#isEnumType()

The following examples show how to use com.dsh105.commodus.GeneralUtil#isEnumType() . 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: PetMenu.java    From SonarPet with GNU General Public License v3.0 5 votes vote down vote up
public PetMenu(IPet pet, ArrayList<MenuOption> options, int size) {
    this.pet = pet;
    this.size = size;
    this.inv = Bukkit.createInventory(pet.getOwner(), size, "EchoPet DataMenu");
    this.options = options;
    for (MenuOption o : this.options) {
        if (o.item.getMenuType() == DataMenu.DataMenuType.BOOLEAN) {
            MenuItem mi = o.item;
            if (GeneralUtil.isEnumType(PetData.class, mi.toString())) {
                PetData pd = PetData.valueOf(mi.toString());
                if (pet.getPetData().contains(pd)) {
                    this.inv.setItem(o.position, o.item.getBoolean(false));
                } else {
                    this.inv.setItem(o.position, o.item.getBoolean(true));
                }
            } else {
                if (mi.toString().equals("HAT")) {
                    if (pet.isHat()) {
                        this.inv.setItem(o.position, o.item.getBoolean(false));
                    } else {
                        this.inv.setItem(o.position, o.item.getBoolean(true));
                    }
                }
                if (mi.toString().equals("RIDE")) {
                    if (pet.isOwnerRiding()) {
                        this.inv.setItem(o.position, o.item.getBoolean(false));
                    } else {
                        this.inv.setItem(o.position, o.item.getBoolean(true));
                    }
                }
            }
        } else {
            this.inv.setItem(o.position, o.item.getItem());
        }
    }
    int book = size - 1;
    this.inv.setItem(book, DataMenuItem.CLOSE.getItem());
}
 
Example 2
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 3
Source File: PetManager.java    From SonarPet with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void loadRiderFromFile(String type, IPet pet) {
    String path = type + "." + pet.getOwnerUUID();
    if (EchoPet.getConfig(EchoPet.ConfigType.DATA).get(path + ".rider.type") != null) {
        ArrayList<PetData> riderData = new ArrayList<>();
        PetType riderPetType = PetType.fromDataString(EchoPet.getConfig(EchoPet.ConfigType.DATA).getString(path + ".rider.type"), riderData);
        String riderName = EchoPet.getConfig(EchoPet.ConfigType.DATA).getString(path + ".rider.name");
        if (Strings.isNullOrEmpty(riderName)) {
            riderName = riderPetType.getDefaultName(pet.getNameOfOwner());
        }
        if (EchoPet.getOptions().allowRidersFor(pet.getPetType())) {
            IPet rider = pet.createRider(riderPetType, true);
            if (rider != null && rider.isSpawned()) {
                rider.setPetName(riderName);
                ConfigurationSection mcs = EchoPet.getConfig(EchoPet.ConfigType.DATA).getConfigurationSection(path + ".rider.data");
                if (mcs != null) {
                    for (String key : mcs.getKeys(false)) {
                        if (GeneralUtil.isEnumType(PetData.class, key.toUpperCase())) {
                            PetData pd = PetData.valueOf(key.toUpperCase());
                            riderData.add(pd);
                        } else {
                            Logger.log(Logger.LogLevel.WARNING, "Error whilst loading data Pet Rider Save Data for " + pet.getNameOfOwner() + ". Unknown enum type: " + key + ".", true);
                        }
                    }
                }
                if (!riderData.isEmpty()) {
                    setData(pet, riderData.toArray(new PetData[riderData.size()]), true);
                }
            }
        }
    }
}
 
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: PetManager.java    From EchoPet with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void loadRiderFromFile(String type, IPet pet) {
    if (pet.getOwner() != null) {
        String path = type + "." + pet.getOwnerIdentification();
        if (EchoPet.getConfig(EchoPet.ConfigType.DATA).get(path + ".rider.type") != null) {
            PetType riderPetType = PetType.valueOf(EchoPet.getConfig(EchoPet.ConfigType.DATA).getString(path + ".rider.type"));
            String riderName = EchoPet.getConfig(EchoPet.ConfigType.DATA).getString(path + ".rider.name");
            if (riderName.equalsIgnoreCase("") || riderName == null) {
                riderName = riderPetType.getDefaultName(pet.getNameOfOwner());
            }
            if (riderPetType == null) return;
            if (EchoPet.getOptions().allowRidersFor(pet.getPetType())) {
                IPet rider = pet.createRider(riderPetType, true);
                if (rider != null && rider.getEntityPet() != null) {
                    rider.setPetName(riderName);
                    ArrayList<PetData> riderData = new ArrayList<PetData>();
                    ConfigurationSection mcs = EchoPet.getConfig(EchoPet.ConfigType.DATA).getConfigurationSection(path + ".rider.data");
                    if (mcs != null) {
                        for (String key : mcs.getKeys(false)) {
                            if (GeneralUtil.isEnumType(PetData.class, key.toUpperCase())) {
                                PetData pd = PetData.valueOf(key.toUpperCase());
                                riderData.add(pd);
                            } else {
                                Logger.log(Logger.LogLevel.WARNING, "Error whilst loading data Pet Rider Save Data for " + pet.getNameOfOwner() + ". Unknown enum type: " + key + ".", true);
                            }
                        }
                    }
                    if (!riderData.isEmpty()) {
                        setData(pet, riderData.toArray(new PetData[riderData.size()]), true);
                    }
                }
            }
        }
    }
}
 
Example 7
Source File: PetMenu.java    From EchoPet with GNU General Public License v3.0 5 votes vote down vote up
public PetMenu(IPet pet, ArrayList<MenuOption> options, int size) {
    this.pet = pet;
    this.size = size;
    this.inv = Bukkit.createInventory(pet.getOwner(), size, "EchoPet DataMenu");
    this.options = options;
    for (MenuOption o : this.options) {
        if (o.item.getMenuType() == DataMenu.DataMenuType.BOOLEAN) {
            MenuItem mi = o.item;
            if (GeneralUtil.isEnumType(PetData.class, mi.toString())) {
                PetData pd = PetData.valueOf(mi.toString());
                if (pet.getPetData().contains(pd)) {
                    this.inv.setItem(o.position, o.item.getBoolean(false));
                } else {
                    this.inv.setItem(o.position, o.item.getBoolean(true));
                }
            } else {
                if (mi.toString().equals("HAT")) {
                    if (pet.isHat()) {
                        this.inv.setItem(o.position, o.item.getBoolean(false));
                    } else {
                        this.inv.setItem(o.position, o.item.getBoolean(true));
                    }
                }
                if (mi.toString().equals("RIDE")) {
                    if (pet.isOwnerRiding()) {
                        this.inv.setItem(o.position, o.item.getBoolean(false));
                    } else {
                        this.inv.setItem(o.position, o.item.getBoolean(true));
                    }
                }
            }
        } else {
            this.inv.setItem(o.position, o.item.getItem());
        }
    }
    int book = size - 1;
    this.inv.setItem(book, DataMenuItem.CLOSE.getItem());
}
 
Example 8
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 9
Source File: PetManager.java    From SonarPet with GNU General Public License v3.0 4 votes vote down vote up
@Override
public IPet createPetFromFile(String type, Player p) {
    if (EchoPet.getOptions().getConfig().getBoolean("loadSavedPets", true)) {
        String path = type + "." + UUIDMigration.getIdentificationFor(p);
        if (EchoPet.getConfig(EchoPet.ConfigType.DATA).get(path) != null) {
            ArrayList<PetData> data = new ArrayList<>();
            PetType petType = PetType.fromDataString(EchoPet.getConfig(EchoPet.ConfigType.DATA).getString(path + ".pet.type"), data);
            String name = EchoPet.getConfig(EchoPet.ConfigType.DATA).getString(path + ".pet.name");
            if (Strings.isNullOrEmpty(name)) {
                name = petType.getDefaultName(p.getName());
            }
            if (!EchoPet.getOptions().allowPetType(petType)) {
                return null;
            }
            IPet pi = this.createPet(p, petType, true);
            if (pi == null) {
                return null;
            }
            //Pet pi = petType.getNewPetInstance(p, petType);
            //Pet pi = new Pet(p, petType);

            pi.setPetName(name);

            ConfigurationSection cs = EchoPet.getConfig(EchoPet.ConfigType.DATA).getConfigurationSection(path + ".pet.data");
            if (cs != null) {
                for (String key : cs.getKeys(false)) {
                    if (GeneralUtil.isEnumType(PetData.class, key.toUpperCase())) {
                        PetData pd = PetData.valueOf(key.toUpperCase());
                        data.add(pd);
                    } else {
                        Logger.log(Logger.LogLevel.WARNING, "Error whilst loading data Pet Save Data for " + pi.getNameOfOwner() + ". Unknown enum type: " + key + ".", true);
                    }
                }
            }

            if (!data.isEmpty()) {
                setData(pi, data.toArray(new PetData[data.size()]), true);
            }

            this.loadRiderFromFile(type, pi);

            forceAllValidData(pi);
            return pi;
        }
    }
    return null;
}
 
Example 10
Source File: PetManager.java    From EchoPet with GNU General Public License v3.0 4 votes vote down vote up
@Override
public IPet createPetFromFile(String type, Player p) {
    if (EchoPet.getOptions().getConfig().getBoolean("loadSavedPets", true)) {
        String path = type + "." + UUIDMigration.getIdentificationFor(p);
        if (EchoPet.getConfig(EchoPet.ConfigType.DATA).get(path) != null) {
            PetType petType = PetType.valueOf(EchoPet.getConfig(EchoPet.ConfigType.DATA).getString(path + ".pet.type"));
            String name = EchoPet.getConfig(EchoPet.ConfigType.DATA).getString(path + ".pet.name");
            if (name.equalsIgnoreCase("") || name == null) {
                name = petType.getDefaultName(p.getName());
            }
            if (petType == null) return null;
            if (!EchoPet.getOptions().allowPetType(petType)) {
                return null;
            }
            IPet pi = this.createPet(p, petType, true);
            if (pi == null) {
                return null;
            }
            //Pet pi = petType.getNewPetInstance(p, petType);
            //Pet pi = new Pet(p, petType);

            pi.setPetName(name);

            ArrayList<PetData> data = new ArrayList<PetData>();
            ConfigurationSection cs = EchoPet.getConfig(EchoPet.ConfigType.DATA).getConfigurationSection(path + ".pet.data");
            if (cs != null) {
                for (String key : cs.getKeys(false)) {
                    if (GeneralUtil.isEnumType(PetData.class, key.toUpperCase())) {
                        PetData pd = PetData.valueOf(key.toUpperCase());
                        data.add(pd);
                    } else {
                        Logger.log(Logger.LogLevel.WARNING, "Error whilst loading data Pet Save Data for " + pi.getNameOfOwner() + ". Unknown enum type: " + key + ".", true);
                    }
                }
            }

            if (!data.isEmpty()) {
                setData(pi, data.toArray(new PetData[data.size()]), true);
            }

            this.loadRiderFromFile(type, pi);

            forceAllValidData(pi);
            return pi;
        }
    }
    return null;
}