[SPIGOT-6001] Hex colors format differently to traditional colours Created: 16/Jul/20 Updated: 18/Jul/20 Resolved: 18/Jul/20 |
|
| Status: | Resolved |
| Project: | Spigot |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Minor |
| Reporter: | FACEGUY | Assignee: | Unassigned |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Attachments: |
|
| Version: | git-Spigot-c3a49df-b0c6dfe (MC: 1.16.1) |
| Guidelines Read: | Yes |
| Description |
|
Using ItemMeta#getLore and then ItemMeta#setLore on a item strips some formatting. Seems to be exclusive to HEX color code lore lines. Here's a before and after. (Note this is when using the stringlist variant of those methods)
Before:
After:
|
| Comments |
| Comment by FACEGUY [ 18/Jul/20 ] |
|
Unfortunately, I'll be unable to do this until at least Sunday, due to a trip. Just mentioning in case somebody else is available or needs a solution sooner. Once back I'll check to see if that works. |
| Comment by md_5 [ 18/Jul/20 ] |
|
Please replace modifier.setColor with RESET.setColor and compile with BuildTools.jar --dont-update and let us know the results. That should make hex and normal colours be handled the same way. |
| Comment by FACEGUY [ 18/Jul/20 ] |
|
This can be easily disproved. It has already been disproved in this conversation. Look up to https://hub.spigotmc.org/jira/browse/SPIGOT-6001?focusedCommentId=37509&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-37509 right here. Hex colored lore lines on items are in italic, classic colors are not. You can see for yourself in the json, they lack "italic":"false" and as such are presented in italic, where as classic colors do not display as italic when used as the leading color in a line. The formatting is also present. I have to RESET before the hex color just to make it not italic, and even if I do that, I run into another problem, getLore and setLore working incorrectly, specifically with hex colors, which leads to the issue for which this ticket was created. |
| Comment by md_5 [ 18/Jul/20 ] |
|
Hex colours are treated exactly the same as normal colours |
| Comment by FACEGUY [ 18/Jul/20 ] |
|
This is indeed the case - I've been having a lot of trouble with getting the hex colors to work without losing 100% of their formatting, and putting reset before it was the latest in my hacky fixes to avoid having to completely rewrite everything I've done. It may not be part of the discussion of this particular issue, but hex color components should REALLY default to being formatted as "italic":"false" if not specified, in order to act like normal color codes, which attach those automatically. In any case, I don't think its reasonable to getLore and setLore to the exact same lore, and have the output be different. This is not intuitive or expected functionality. |
| Comment by blablubbabc [ 17/Jul/20 ] |
|
Okay, with the reset in front of the initial hex color I get: http://prntscr.com/tjw9qm The conversion back from the component representation to plain text is probably not able to reproduce the original reset. I am also not sure if there is an easy way to 'fix' this (since it is not easily possible to check whether a certain text component attribute is present versus whether it is 'false' due to not being set (in which case defaults apply), other than comparing their json serialization) |
| Comment by FACEGUY [ 17/Jul/20 ] |
|
I used the reset code in initial creation in order to fix the formatting being missing (and therefore defaulting to italics). |
| Comment by blablubbabc [ 17/Jul/20 ] |
|
How did you originally create your 'before' item? If I try to create the item like this:
ItemMeta meta = itemInHand.getItemMeta();
meta.setLore(Arrays.asList(
ChatColor.GRAY + "+4 Maximum Barrier",
ChatColor.of("#4EFF4A") + "+8% Fore Resistance"
));
itemInHand.setItemMeta(meta);
I get an item in your 'after' format right away: And this stays the same when getting and re-applying the lore. The only thing I find odd (however, that is unrelated to this ticket), is that the first plain text gets converted to a component representation which renders non-italic, while the second text gets translated to a component representation which renders italic. For consistency they should probably both produce representations which either show as italic or non-italic . |
| Comment by FACEGUY [ 17/Jul/20 ] |
|
... ok here's the code to reproduce. ItemStack stack = sender.getEquipment().getItemInMainHand(); ItemMeta meta = stack.getItemMeta(); List<String> lore = new ArrayList<>(); lore.addAll(meta.getLore()); meta.setLore(lore); stack.setItemMeta(meta); sendMessage(sender, "&atest complete"); |
| Comment by FACEGUY [ 16/Jul/20 ] |
|
For additional info, this item is created via setting the item's lore using ItemMeta#setLore(List<String>); The item's data is formatted correctly through server restart, playerdata save/load, inventory open/close, and dropping and picking up. If I use ItemMeta#getLore to fetch the string list, then set the item meta to that same string list or an identical one, the formatting on the hex color component is stripped, resulting in italics, as seen in the json. |
| Comment by FACEGUY [ 16/Jul/20 ] |
|
Before:
After:
|
| Comment by md_5 [ 16/Jul/20 ] |
|
Please include the code used to produce this lines. It looks to me like you're missing a reset before the colours so its inheriting the default italics of lore. |
| Comment by md_5 [ 16/Jul/20 ] |
|
Which formatting are you suggesting is stripped? Can you include a screenshot of the actual presentation not the JSON. We only care about presentation. See SPIGOT-5063, SPIGOT-5304, SPIGOT-5656, SPIGOT-3206, SPIGOT-5350, SPIGOT-5980, SPIGOT-4672 This is almost certainly a duplicate |