Getting RGB of leather from InventoryClickEvent?

Discussion in 'Spigot Plugin Development' started by Moderance, Jun 23, 2016.

  1. So basically I want to get the RGB of whatever leather a player has clicked rather than writing out 50 if statements depending on what the name is. I've been trying to get it by doing event.getCurrentItem(). but I've tried a bunch of different things and I cant seem to get anything to work.
     
  2. You will need to cast the leathers ItemMeta to LeatherArmorMeta, then you can get the color and from that the RGB value if you wish.
     
  3. MiniDigger

    Supporter

    for your next post, please try to use the right forum sections. this section is for bungeecord plugin development. thats not the same as spigot plugin development...
     
    • Agree Agree x 3
  4. Yeah, I just clicked on the wrong one >.>
     
  5. I get an eventException error when doing;

    Code (Text):
    LeatherArmorMeta helmet = (LeatherArmorMeta) event.getCurrentItem();
    as well as;
    Code (Text):
    ItemMeta helmet = (ItemMeta) event.getCurrentItem();
     
  6. You will want to do something like this:
    Code (Text):

    ItemStack item = event.getCurrentItem();
    if (item.hasItemMeta() && item.getItemMeta() instanceof LeatherArmorMeta) {
        LeatherArmorMeta lMeta = (LeatherArmorMeta)item.getItemMeta();
    }
     
    That's just off the top of my head.
     
  7. MiniDigger

    Supporter

    don't cast your item to LeatherArmorMeta, cast the meta of the current tiem...
     
    • Agree Agree x 1
  8. Man this is the BungeeCord section. Please post it next time in the Spigot section
     
  9. MiniDigger

    Supporter

    if you would actually take the time to read threads you would see that I already notified op about that and that he already apologized...
     
    • Agree Agree x 1