PaperMC / Paper

The most widely used, high performance Minecraft server that aims to fix gameplay and mechanics inconsistencies
https://papermc.io/
Other
9.34k stars 2.2k forks source link

HoverEvent and ClickEvent are not available when changing message from AsyncChatEvent #10980

Closed Elikill58 closed 6 days ago

Elikill58 commented 6 days ago

Expected behavior

I want to add hover content when player send message in chat. So, I change the message value from AsyncChatEvent event.

Observed/Actual behavior

The message is well edited, but there is no hover or click event. If I send the message myself, the hover is well sent

Steps/models to reproduce

@EventHandler
public void onChat(AsyncChatEvent e) {
    e.message(Component.text("something").hoverEvent(HoverEvent.showText(Component.text("This is a test"))));
    e.getPlayer().sendMessage(Component.text("something myself").hoverEvent(HoverEvent.showText(Component.text("This is a test myself"))));
}

Plugin and Datapack List

My plugin test

Paper version

This server is running Paper version git-Paper-497 (MC: 1.20.4) (Implementing API version 1.20.4-R0.1-SNAPSHOT) (Git: d8d54d9 on ver/1.20.4) You are running the latest version Previous version: git-Paper-496 (MC: 1.20.4)

Other

No response

lynxplay commented 6 days ago

I cannot replicate this whatsoever, neither on latest 1.20.4 nor on 1.21. Are you using the vanilla client?

Elikill58 commented 6 days ago

Yes, vanilla without mods. You mean, the line with the formatting is well showing the hover content ?

Note: maybe it need some formatting, as I personally change the format of the message, but idk if it's important

lynxplay commented 6 days ago

image yea, this is how it looks on my end.

Elikill58 commented 6 days ago

Ok, nevermind, it's only when we change the formatting as this for example:

@EventHandler(priority = EventPriority.LOWEST)
public void onChatLow(AsyncPlayerChatEvent e) {
    e.setFormat("%1$s: %2$s");
}

// then the paper event
@EventHandler
public void onChat(AsyncChatEvent e) {
    e.message(e.message().hoverEvent(HoverEvent.showText(Component.text("This is a test"))));
}
electronicboy commented 6 days ago

Because you're using the legacy formatting stuff, which causes us to have to have to populate that renderer format which only supports legacy text in order to retain behavior. You can't miss modern and legacy and expect modern features to work, use the ChatRenderer API

Elikill58 commented 6 days ago

The problem is, in my specific case, it's changed by others plugins. So, I don't know when it will be fine or not. Also, event by using this:

for(Audience a : e.viewers().isEmpty() ? Bukkit.getOnlinePlayers() : e.viewers())
    a.sendMessage(e.renderer().render(p, p.displayName(), message, a));
e.setCancelled(true);

Or this:

e.message(e.renderer().render(p, p.displayName(), message, p));

The issue is still the same (so even by using chat renderer)

Warriorrrr commented 6 days ago

That's not how you use the renderer, you're supposed to implement your own renderer and set it via the setter

electronicboy commented 6 days ago

Once again, the issue here is that the ChatRenderer is a legacy chat render, which does not understand modern text formatting, calling it manually is not going to change that

there is no good solution here which doesn't involve you replacing the chat renderer with something able to actually use components, the only caveat here is that you will induce some behavioral changes as legacy and modern text work differently

Elikill58 commented 6 days ago

Ok, and so, I could fix it by making my own chat renderer that would convert from legacy to modern ?

Do you think it's possible to make a PR to fix it for everyone ? Or change the legacy one (with PR)?

electronicboy commented 6 days ago

Yes

No, because legacy works different to components, i.e. bleedthrough, you'd just break chat formatting plugin behavior