Solved Cannot cast MaterialData to Dye and DOUBLE_STEP

Discussion in 'Plugin Development' started by Jessy1237, Jan 27, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    Jessy1237

    Well i have been trying to squash this bug for ages I'm not to experienced with the MaterialData class nor integer to bytes but the code that i am using used to work before bukkit update to 1.4. i was wondering if someone could look over my code for me and tell what is wrong with it and why it doesn't work for the new versions bukkit

    Code:
    //Gets the clean name of the item from the data
    public static String getCleanName(ItemStack item) {
            if (item == null)
                return "NULL";
            if (item.getData() == null || item.getData().getData() == -1)
                return item.getType().toString();
     
            switch (item.getType()) {
            case WOOD_STAIRS:
                return ((WoodenStep) item.getData()).getSpecies() + " Wooden Stairs";
            case INK_SACK:
                switch (((Dye) item.getData()).getColor()) {
                case WHITE:
                    return "Bone Meal";
                case ORANGE:
                    return "Orange Dye";
                case MAGENTA:
                    return "Magenta Dye";
                case LIGHT_BLUE:
                    return "Light Blue Dye";
                case YELLOW:
                    return "Dandelion Yellow";
                case LIME:
                    return "Lime Dye";
                case PINK:
                    return "Pink Dye";
                case GRAY:
                    return "Gray Dye";
                case SILVER:
                    return "Light Gray Dye";
                case CYAN:
                    return "Cyan Dye";
                case PURPLE:
                    return "Purple Dye";
                case BLUE:
                    return "Lapis Lazuli";
                case BROWN:
                    return "Cocoa Beans";
                case GREEN:
                    return "Cactus Green";
                case RED:
                    return "Rose Red";
                case BLACK:
                    return "Ink Sac";
                default:
                    return String.format("Unknown Dye(%d)", item.getData().getData());
                }
            case SAPLING:
                    return ((Tree) item.getData()).getSpecies() + " Sapling";
            case LOG:
                return ((Tree) item.getData()).getSpecies() + " Log";
            case LEAVES:
                return ((Tree) item.getData()).getSpecies() + " Leaves";
            case WOOL:
                return ((Wool) item.getData()).getColor() + " Wool";
            case DOUBLE_STEP:
                return ((Step) item.getData()).getMaterial() + " Double Slab";
            case CROPS:
                return ((Crops) item.getData()).getState() + " Crops";
            case COAL:
                return ((Coal) item.getData()).getType().toString();
            default:
                return item.getType().toString();
            }
        }
     
    //Reads the item from the CSV and sets the data value. String example 351:04
    public static ItemStack parseItem(String info) {
            String[] pts = info.split(":");
            int data = (pts.length == 1 ? -1 : Integer.parseInt(pts[1]));
            int item = -1;
     
            try {
                item = Integer.parseInt(pts[0]);
            } catch (NumberFormatException e) {
                Material mat = Material.getMaterial(pts[0]);
                if (mat == null) {
                    System.out.println("DC ERROR: Could not parse material: " + info);
                    return null;
                }
                item = mat.getId();
            }
            ItemStack item1 = new ItemStack(item);
            item1.setData(new MaterialData(item1.getTypeId(), (data == -1 ? (byte)-1 : (byte)(data & 0xFF))));
            System.out.println(data);
            return item1;
        }
    Thanks so much i have been trying to fix this for hours and i'm up to the point where i'm starting to get frustrated. Its really late where i am so i will check back in the morning. Thank you again for your replies.
     
  2. Offline

    Jombi

    Don't worry about MaterialData.
    Block b = loc.getBlock();
    if b.getTypeId() == 35 // its wool!
    {
    if (byte)b.getData() == 14 //its red wool!
    }
    and just iterate for all the other block colors or types
     
  3. Offline

    Jessy1237

    Ok i will do that, i still wonder though why in 1.4 it stopped working. Something must have changed in the bukkit API somewhere relating to these classes.
     
Thread Status:
Not open for further replies.

Share This Page