crashdemons / DisplayItem-Spigot

rewrite of DisplayItem for use in Spigot 1.13+ (uses BungeeChat components)
5 stars 0 forks source link

1.16.x and above hex colour formats break display #5

Closed Ayymoss closed 4 years ago

Ayymoss commented 4 years ago

Title, example: https://i.imgur.com/IThSRbV.png

Anything that's not using the old Minecraft colours gets converted to &0.

crashdemons commented 4 years ago

can you give an example of how you made the item?

crashdemons commented 4 years ago

also, it looks like this may be partly a spigot issue (as to why it appears black) https://hub.spigotmc.org/jira/browse/SPIGOT-5829 supposedly it was fixed by a commit but possibly not fully. (are you up to date with the latest spigot?)

but when that is fixed, it will also probably need some advanced support in the plugin so that it appears styled at all. this is because the item replacement uses Spigot's ItemMeta.getDisplayName method which is supposed to be the name of the item with formatting codes included. There (probably?) arent formatting codes for the hex colors, so if the previous issue is fixed, the name will probably appear white or uncolored/unstyled.

to solve this properly, there needs to be an API method that can retrieve the ChatComponents of the item name, which isn't available in the Spigot-API that I can see.

But, I don't really get my hopes up about this being officially supported in Spigot because even the inbuilt chat event in spigot still only supports strings (no tags), The only way that this plugin is able to send messages with items is with the special Player.Spigot Draft API method for sending component messages (which then cannot be seen by events).

crashdemons commented 4 years ago

image

27.06 18:33:24 [Server] Server thread/INFO This server is running CraftBukkit version git-Spigot-6f4ff1b-983305b (MC: 1.16.1) (Implementing API version 1.16.1-R0.1-SNAPSHOT) 27.06 18:33:24 [Server] Server thread/INFO Checking version, please wait... 27.06 18:33:24 [Server] Thread-112/INFO You are running the latest version

Correction: it seems to have a formatting code corresponding to the last letter of the hex color

123456 was translated to &6 in getDisplayName

12345a was translated to &a in getDisplayName

seems there's still a bug

Ayymoss commented 4 years ago

I'll restart my server later today as I'm using some ancient version (2.4.1) see if that fixes anything.

After that, I'll let you know.

But I use CMI for colour handling and the format is {#FFFFFF} which I used in an Anvil with some text. Printing [item] to chat returns the black item name.

Ayymoss commented 4 years ago

Decided to test on a different server, yep still broken.

As explained how I colour the items in-game it returns black item name.

Using 2.6.0.

crashdemons commented 4 years ago

I imagine there is still a lot of difference between servers on how getDisplayName decides how to format things it can't possibly represent.

I'll have to research a lot into how to accomplish this specifically for DisplayItem. In particular Spigot/Bukkit don't support hex colors except in the bugeechat API, while I have to get item names from the Bukkit API. Getting the fully formatted name may require me to do some extra work with the item's NBT, which I generally avoid because it introduces version-specific dependencies/behavior.

I'm imagining it will work like this, hypothetically:

As you can see there is a lot of work to be done for this, the other problem with this approach is NMS code can change a lot between versions so you have to make a decision:

anyway not that any of this interesting to you, just planning ahead. For now, there is no immediate fix possible to support hex colors wiithout considerable work, but if you want the item names to stop being black, you can negate/deny the displayitem.colorname permission for regular users, which should prevent it from being having any color formatting at all aside from what you use in the config.

crashdemons commented 4 years ago

I've made an experimental edit to the plugin acf02476c493aa7ee2d2d3383865c2b079dd05b5 which works for me a dev build is available here https://ci.meme.tips/job/DisplayItem-Spigot/21/

However, I still need to do testing to ensure that the new approach doesn't reintroduce a crash from items with too much NBT for chat, and then I need to remove debug lines that may spam the console when sharing an item.

crashdemons commented 4 years ago

While the above build works, it reintroduces the NBT limit issue. Attempting to share a shulker box in chat with 11 custom-textured heads

crashdemons commented 4 years ago

dev build 22 should fix the remaining issues: https://ci.meme.tips/job/DisplayItem-Spigot/22/ but I recommend lowering your personal config's jsonlimit value to 8000

Ayymoss commented 4 years ago

Yep - This build works with CMI on my server. :)

Much appreciated.