Solved Getting Wool from Color?

Discussion in 'Spigot Plugin Development' started by jay275475, Dec 23, 2015.

  1. Code (Text):
            Color color =     Color.fromRGB(plugin.getConfig().getInt("arenas."+plugin.currentArena+".teams."+p.getData("team")+".Color"));
            Wool wool = new Wool(DyeColor.getByColor(color));
            ItemStack teamColor = wool.toItemStack(1);
            e.getPlayer().getInventory().setHelmet(teamColor);
    I'm getting errors from this but I'm not sure why.
     
  2. ctd

    ctd

    In order for that to work, the RGB values need to match one of the enum's RGB values. If you supply one that does not, that method will return null. Using correct values should fix your issue.

    Code (Text):
    WHITE: 255, 255, 255
    SILVER: 192, 192, 192
    GRAY: 128, 128, 128
    BLACK: 0, 0, 0
    RED: 255, 0, 0
    MAROON: 128, 0, 0
    YELLOW: 255, 255, 0
    OLIVE: 128, 128, 0
    LIME: 0, 255, 0
    GREEN: 0, 128, 0
    AQUA: 0, 255, 255
    TEAL: 0, 128, 128
    BLUE: 0, 0, 255
    NAVY: 0, 0, 128
    FUCHSIA: 255, 0, 255
    PURPLE: 128, 0, 128
    ORANGE: 255, 165, 0
     
  3. Mark as solved please.
     
  4. Wait, it doesn't seem to work? If I don't do 255,255,255 it doesn't work??
     
  5. I get the error or setting the color I believe.
     
  6. ctd

    ctd

    Could you please post your stacktrace?
     
  7. I changed it to shorts, and it worked just fine.
     
  8. ctd

    ctd

    Cool! Glad it worked! I had the same issue when I was trying to find the closest color constant to a set of rgb values. In your case it was much easier because you have control over what the values were going to be, whereas I didn't :p
     
  9. @jay275475 why not just use the name of the Color constants?
    @ctd Color isn't an enum ;).
     
  10. ctd

    ctd

    Oops I was thinking of the DyeColor enum when I said that :p

    I was actually going to suggest using the constant name as well initially, but it's a little hackery with the Color class. It's much easier to do with DyeColor since it's an enum.