Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GsonComponentSerializer doesn't properly handle "null" string #447

Closed
Camotoy opened this issue Sep 20, 2021 · 1 comment · Fixed by #481
Closed

GsonComponentSerializer doesn't properly handle "null" string #447

Camotoy opened this issue Sep 20, 2021 · 1 comment · Fixed by #481

Comments

@Camotoy
Copy link
Contributor

Camotoy commented Sep 20, 2021

Tested with Adventure 4.9.1.

A Minecraft server can send a set title packet (https://wiki.vg/Protocol#Set_Title_Text) with its contents set as the String null and a 1.17.1 vanilla Java client will accept it with no errors. The Minecraft client (tested on 1.17.1 using a Fabric mod) deserializes the Component as literal null:

(Yarn mappings)

@Mixin(ClientPlayNetworkHandler.class)
public class ClassNameLol {

    @Inject(method = "onTitle", at = @At("HEAD"))
    public void onSetTitle(TitleS2CPacket packet, CallbackInfo ci) {
        System.out.println(packet.getTitle()); // will be a literal null in this case
    }
}

It appears that this just clears the title in Minecraft 1.17.1 - the same thing that the clear title packet does, except only for the title and not the subtitle.

This behavior can be seen with the BetterRTP plugin: https://www.spigotmc.org/resources/betterrtp-random-wild-teleport.36081/ . Installing the plugin and doing /rtp will show the issue to any Adventure deserializer listening on the client's packets. This can be replicated on Paper 1.16.5 by executing Player#sendTitle(null, ""). It does not manifest with Paper 1.17.1 build 259; it does manifest with Paper 1.16.5 [691 and 788] and https://ci.viaversion.com/job/ViaVersion/553/.

Adventure currently errors on this code as such:

com.google.gson.JsonParseException: Don't know how to turn null into a Component
	at net.kyori.adventure.text.serializer.gson.ComponentSerializerImpl.notSureHowToDeserialize(ComponentSerializerImpl.java:323)
	at net.kyori.adventure.text.serializer.gson.GsonComponentSerializerImpl.deserialize(GsonComponentSerializerImpl.java:85)
	at net.kyori.adventure.text.serializer.gson.GsonComponentSerializerImpl.deserialize(GsonComponentSerializerImpl.java:37)
	at com.github.steveice10.mc.protocol.packet.ingame.server.title.ServerSetTitleTextPacket.read(ServerSetTitleTextPacket.java:22)

Source code: https://github.com/GeyserMC/MCProtocolLib/blob/feature/1.17.1/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/title/ServerSetTitleTextPacket.java#L22 which calls https://github.com/GeyserMC/MCProtocolLib/blob/feature/1.17.1/src/main/java/com/github/steveice10/mc/protocol/data/DefaultComponentSerializer.java#L8

It seems this was initially caused by #212 and its commit.

@Camotoy
Copy link
Contributor Author

Camotoy commented Sep 28, 2021

Updated with what Minecraft does with the null text and easier replication steps using the Bukkit API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants