Solved [1.9] Seeing if a colored name is equal to another string

Discussion in 'Spigot Plugin Development' started by tokyojack, May 23, 2016.

  1. Hello people!

    I'm having a problem with this:
    Code (Text):
    //In InventoryClickEvent
    //Drug1inv() is a ItemStack which has a colored name from the config using TranslateAltColorCode

    ItemStack clicked = event.getCurrentItem();
    if(clicked.getItemMeta().getDisplayName().equals
    (ChatColor.stripColor(Drug1inv().getItemMeta().getDisplayName())))
    I want it too see if the clicked item has the same name as the ItemName in the Config. I bet theirs a simple solution, but theirs nothing on google explaining this! Additions/improvents are very much welcomed!

    Jack!

    PS: I removed most of the code, I just put the problem part.
     
  2. any error? Try broadcasting the displaynames and seeing the difference, it doesn't look like you stripped the color from the clicked item displayname.
     
  3. As said above, debug it.

    Broadcast both clicked.getItemMeta().getDisplayName()
    and ChatColor.stripColor(Drug1inv().getItemMeta().getDisplayName()

    I've had some problems with stripColor() not working properly before.
     
  4. Yup, I've debugged it before I posted this. No errors at all.
     
  5. You are only stripping the colours from one of the two strings. Are they both coloured? If they are, why don't you just compare the two directly?
     
  6. Oh darn it, I just discovered that "getDisplayName()" also gets the color, so I just had to remove the StripColor.
    This always happens to me, discovering the mistake 5 minutes after I post a thread. Thanks all for helping me!

    For anyone trying to fix this aswell:
    Code (Text):
    //In InventoryClickEvent
    ItemStack clicked = event.getCurrentItem();
    if(clicked.getItemMeta().getDisplayName().equals
    (aItemStack.getItemMeta().getDisplayName()))
    "getDisplayName()" also gets the color, so you don't need to strip the second String of color also.

    SOLVED

    PS:Thanks @Cewlt for helping me again <3
     
    • Friendly Friendly x 1