PaperMC / Paper

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

AsyncPlayerChatEvent does not reflect changes made in AsyncChatDecorateEvent #8308

Closed treecaptcha closed 2 years ago

treecaptcha commented 2 years ago

Expected behavior

I expect that when AsyncPlayerChatEvent is called it should have the changes made to the component made by AsyncChatDecorateEvent.

Observed/Actual behavior

AsyncPlayerChatEvent does not reflect changes made in AsyncChatDecorateEvent The code writes the current state of the text after the event name and priority.

[15:23:42 INFO]: iCaffeine[/127.0.0.1:44206] logged in with entity id 151 at ([world]-160.61336335512064, 124.0, 428.30000001192093)
[15:23:46 WARN]: [Uwuify] AsyncChatDecorateEvent NORMAL
[15:23:46 INFO]: [Uwuify] TextComponentImpl{content="h", style=StyleImpl{obfuscated=not_set, bold=not_set, strikethrough=not_set, underlined=not_set, italic=not_set, color=null, clickEvent=null, hoverEvent=null, insertion=null, font=null}, children=[]}
[15:23:46 WARN]: [Uwuify] AsyncChatDecorateEvent HIGH
[15:23:46 INFO]: [Uwuify] TextComponentImpl{content="h", style=StyleImpl{obfuscated=not_set, bold=not_set, strikethrough=not_set, underlined=not_set, italic=not_set, color=null, clickEvent=null, hoverEvent=null, insertion=null, font=null}, children=[]}
[15:23:47 WARN]: [Uwuify] AsyncChatDecorateEvent NORMAL
[15:23:47 INFO]: [Uwuify] TextComponentImpl{content="hello", style=StyleImpl{obfuscated=not_set, bold=not_set, strikethrough=not_set, underlined=not_set, italic=not_set, color=null, clickEvent=null, hoverEvent=null, insertion=null, font=null}, children=[]}
[15:23:47 WARN]: [Uwuify] AsyncChatDecorateEvent HIGH
[15:23:47 INFO]: [Uwuify] TextComponentImpl{content="hewwo", style=StyleImpl{obfuscated=not_set, bold=not_set, strikethrough=not_set, underlined=not_set, italic=not_set, color=null, clickEvent=null, hoverEvent=null, insertion=null, font=null}, children=[]}
[15:23:50 WARN]: [Uwuify] AsyncPlayerChatEvent NORMAL
[15:23:50 INFO]: [Uwuify] hello
[15:23:50 INFO]: <iCaffeine> hewwo

Steps/models to reproduce

Register the following listeners

    @EventHandler
    public void chateTest(AsyncPlayerChatEvent e ){
        Uwuify.uwu.getLogger().log(Level.WARNING, "AsyncPlayerChatEvent NORMAL");
        Uwuify.uwu.getLogger().log(Level.INFO, e.getMessage().toString());
    }

    @EventHandler(priority = EventPriority.HIGH)
    public void onPlayesrPreview(AsyncChatDecorateEvent e) {
        Uwuify.uwu.getLogger().log(Level.WARNING, "AsyncChatDecorateEvent HIGH");
        Uwuify.uwu.getLogger().log(Level.INFO, e.result().toString());
    }

    @EventHandler
    public void onPlayerPreview(AsyncChatDecorateEvent event) {
        if(event.isPreview() && !Configuration.USE_PREVIEW) return;
        Uwuify.uwu.getLogger().log(Level.WARNING, "AsyncChatDecorateEvent NORMAL");
        Uwuify.uwu.getLogger().log(Level.INFO, event.result().toString());
        PlainTextComponentSerializer serializer = PlainTextComponentSerializer.plainText();
        event.result(Component.text(Uwuifier.uwuifyMessage(serializer.serialize(event.result()))));
    }

Plugin and Datapack List

[15:27:40 INFO]: There are 2 data packs enabled: [vanilla (built-in)], [file/bukkit (world)]
[15:28:03 INFO]: Plugins (1): Uwuify

Paper version

> icanhasbukkit
[15:29:26 INFO]: Checking version, please wait...
[15:29:27 INFO]: This server is running Paper version git-Paper-130 (MC: 1.19.2) (Implementing API version 1.19.2-R0.1-SNAPSHOT) (Git: 4ba43fe)
You are running the latest version
Previous version: git-Paper-125 (MC: 1.19.2)

Other

No response

Machine-Maker commented 2 years ago

You should use AsyncChatEvent, not AsyncPlayerChatEvent. The changes made in AsyncChatDecorateEvent are there in the (Async)ChatEvents. The reason they are not present in the legacy player chat events, is to maintain compat with how bukkit (legacy) chose to handle previews. If you use the legacy preview event and the legacy chat events, the changes made in the preview event are also not present in the chat event. You should be using the decorate event with the chat events, not the player chat events.

Machine-Maker commented 2 years ago

Closing as Works As Intended for now. This system will be better documented once full support for signed messages and chat decoration is implemented (pending an Adventure update).