Search in sources :

Example 1 with TreeSpecies

use of org.bukkit.TreeSpecies in project BKCommonLib by bergerhealer.

the class ParseUtil method parseMaterialData.

/**
     * Tries to parse the text to a data value for a Material
     *
     * @param text to parse
     * @param material to parse the text against
     * @param def to return on failure (hint: use -1)
     * @return Parsed or default value
     */
public static int parseMaterialData(String text, Material material, int def) {
    try {
        return Integer.parseInt(text);
    } catch (NumberFormatException ex) {
        if (material == Material.WOOD) {
            TreeSpecies ts = parseTreeSpecies(text, null);
            if (ts != null) {
                return MaterialUtil.getRawData(ts);
            }
            return def;
        } else {
            MaterialData dat = MaterialUtil.getData(material, 0);
            if (dat instanceof TexturedMaterial) {
                TexturedMaterial tdat = (TexturedMaterial) dat;
                Material mat = parseMaterial(text, null);
                if (mat == null) {
                    return def;
                }
                tdat.setMaterial(mat);
            } else if (dat instanceof Wool) {
                Wool wdat = (Wool) dat;
                DyeColor color = parseEnum(DyeColor.class, text, null);
                if (color == null) {
                    return def;
                }
                wdat.setColor(color);
            } else if (dat instanceof Tree) {
                Tree tdat = (Tree) dat;
                TreeSpecies species = parseTreeSpecies(text, null);
                if (species == null) {
                    return def;
                }
                tdat.setSpecies(species);
            } else if (dat instanceof Leaves) {
                Leaves tdat = (Leaves) dat;
                TreeSpecies species = parseTreeSpecies(text, null);
                if (species == null) {
                    return def;
                }
                tdat.setSpecies(species);
            } else if (dat instanceof LongGrass) {
                LongGrass ldat = (LongGrass) dat;
                GrassSpecies species = parseEnum(GrassSpecies.class, text, null);
                if (species == null) {
                    return def;
                }
                ldat.setSpecies(species);
            } else {
                return def;
            }
            return MaterialUtil.getRawData(dat);
        }
    }
}
Also used : GrassSpecies(org.bukkit.GrassSpecies) TreeSpecies(org.bukkit.TreeSpecies) Material(org.bukkit.Material) DyeColor(org.bukkit.DyeColor)

Aggregations

DyeColor (org.bukkit.DyeColor)1 GrassSpecies (org.bukkit.GrassSpecies)1 Material (org.bukkit.Material)1 TreeSpecies (org.bukkit.TreeSpecies)1