Error comparing 2 colored wools!

Discussion in 'Plugin Development' started by Gonmarte, Nov 14, 2015.

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

    Gonmarte

    Hi,
    Im creating a methd that returns a boolean. The method is like that isSimilar() method BUT bukkit assume that a red wool is == to a blue wool, so i need to create another method that returns true if both of wools have the same color and false if they havent.
    Here is my code, Thank you.
    Code:
    public boolean isSimilarWools(ItemStack wool1, ItemStack wool2){
    
    if (wool1.getType() == Material.WOOL && wool2.getType() == Material.WOOL) {
                                                                                                  
    Dye dye1 = new Dye(Material.WOOL);
                                              // ERROR
    dye1.setColor(DyeColor.getByWoolData(wool1.getData()));
    wool1 = dye1.toItemStack();
    Dye dye2 = new Dye(Material.WOOL);
                                              // ERROR
    dye2.setColor(DyeColor.getByWoolData(wool2.getData()));
    wool2 = dye2.toItemStack();
    if(wool1.getData() == wool2.getData()){
    return true;}
    return false;}
    return false;}
    
     
  2. Offline

    Scimiguy

    So... what's the errors
     
  3. Offline

    Gonmarte

    @Scimiguy It is in red line and it says that getByWoolData (byte) in DyeColor cannot be applied to (org.bukkit.material.MaterialData)
     
  4. Offline

    Scimiguy

    So basically it's saying that you're trying to give getByWoolData a byte variable, but it only takes MaterialData.

    Give it some MaterialData instead?
     
  5. Offline

    Gonmarte

    @Scimiguy But im giving it already the data of the itemstack using the getData() method...
     
  6. Offline

    Scimiguy

  7. Offline

    Gonmarte

    @Scimiguy Its not working because im using ItemStacks instead of blocks :/ How i fix this?
    Code:
    public boolean isSimilarWools(ItemStack wool1, ItemStack wool2){
    
    if (wool1.getType() == Material.WOOL && wool2.getType() == Material.WOOL) {
    //error because im using itemstacks probably..
    Wool w1 = new Wool(wool1.getType(), wool1.getData());
    //the same error..
    Wool w2 = new Wool(wool2.getType() , wool2.getData()); if(w1.getColor() == w2.getColor()){
    return true;}
    return false;}
    return false;}
    
    
    How i use the code format to intellij? cuz [code and /code] doesnt work so well.. Thank you!
     
  8. Offline

    Scimiguy

    Oh ItemStacks, lame

    Well you could try something like
    MaterialData data = ItemStack#getData()
    if (data instanceof Wool)
    (Wool)data#getColor()

    Wool is an extension of MaterialData, and has the getColor() method.

    So if you get the MaterialData of your stack, check if it's wool, then get the colour, you should be right

    This is all in theory, I haven't tested this, nor have I done it prior
     
  9. Offline

    Gonmarte

Thread Status:
Not open for further replies.

Share This Page