Workaround for the default Italic in 1.13

Discussion in 'Spigot Plugin Development' started by anakinsky249, Aug 5, 2018.

  1. So, here's the issue. Everytime I try to set the display name of an item, it gets in italic, no matter what. Here's what I tried to fix it:
    Code (Java):
    meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', "&r" + displayName));
    It still doesn't fix it. It works for lore, but not for the display name.

    Anybody knows how to fix it ?
     
    • Optimistic Optimistic x 1
  2. I'm trying to add it to a custom inventory, so I can't use it that way.
     
  3. Try changing &r to &f
     
  4. Why not?
    Use org.bukkit.inventory.meta.ItemMeta#setDisplayName
    And pass the JSON string to this method.
    You need to be more optimistic like @ME1312 suggested.

    Probably #setDisplayName will not be able to directly handle JSON strings, in this case you need to have a look into the CraftBukkit source to find out what the method does and where to hook into. In worst case you need to hook into NMS. Or you wait until the Bukkit API supports JSON encoded display names.
     
  5. I don't think that's quite what that meant..
     
    • Agree Agree x 2
  6. Nah, it doesn't work like that. Afaik, &f is to reset color, not formatting. Tried it just incase, but nope.
     
  7. &f is white, not reset. And I suggested it because, as far as I know, color codes after a formatting code break that previous formatting. I don't seem to have this issue, though.
     
  8. DavidDevelops

    Supporter

    Okay skipped most the replies,
    But, why can't you use "ChatColor.stripColor(string)"? that clears formatting too...
    Suprised no one above mentioned it,
    Example:
    Code (Text):
    String displayName = ChatColor.strip(displayName);
    meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', displayName));
     
    That should leave it with no colors or formatting, although thinking about it it may not work, but worth a try x) (Also i have never noticed this problem so.. make sure you are using the newest build?)
     
    • Agree Agree x 1
    • Like Like x 2
    • Like Like x 1
  9. Of course!