ProtocolLib

3M Downloads

Custom field in JSON reply on the SERVER_INFO packet

SrDum opened this issue ยท 2 comments

commented

Make sure you're doing the following

  • You're using the latest build for your server version
  • This isn't an issue caused by another plugin
  • You've checked for duplicate issues
  • You didn't use /reload

Describe the question
Is there a way to add a custom field to the JSON reply? The WrapperServerPing class provides methods to edit existing ones, but what i really need is to add a new entry into the json.

API method(s) used
event.getPacket().getServerPings().read();
event.getPacket().getServerPings().write();
WrapperServerPing (basically everything in this class)

Expected behavior
Be able to add a new field.

Additional context
My first instinct was to extend WrapperServerPing and add my new field with its gets and setters and hope it was just being parsed by GSON internally, but that doesnt work, it drops my new field from the reply anyways

commented

Since I think you're talking about older versions (not 1.19+), I have a very cheeky solution for you.

The PacketPlayOutServerInfo holds a Gson instance used to serialize the outgoing ServerPing. You can access it using basic reflection and then modify it's type adapters using the field called typeTokenCache. If you replace the existing entry with your custom implementation you should be g2g.

If you want I can send the code-snippet to you later, but right now I don't have the time to write it myself.

commented

Basically you cannot do this because the WrapperServerPing just wraps nms.ServerPing which has no way to add a custom field to it.