Skip to content

Conversation

nextdayy
Copy link
Contributor

This PR aims to switch the current ClientboundPacketHandler system to using type-safe functional interfaces instead, which are specified for each packet type individually.

Motivations

  • the current system means there is a large amount of boilerplate needed if you wish to add an event handler. by utilising functional interfaces, this can be done in one line, such as registerHandler(ClientboundPartyInfoPacket.class, packet -> partyCallback(packet))
  • the current system means that for every new packet made, more code has to be added to the ClientboundPacketHandler interface, which could become bothersome in the future. Each packet class also had more boilerplate which has been removed as a result.
  • Prevents the handle method from running when it does not need to (for example, invoking a handler which does not have any implementation for onClientHelloPacket) which aids performance (minorly)
  • (At least in my use-case), I do not use every packet available in one handler, so I can avoid writing excess implementation details.

I am, as always, open to feedback on this change. I think it is overall very good in terms of the future extensibility and cleanliness of using the API.

@ConnorLinfoot
Copy link
Member

Thanks! I agree, this does improve the overall usage of the API and will make it nicer to work with especially in the future when more packets are added.

@ConnorLinfoot ConnorLinfoot merged commit b0f3658 into HypixelDev:master Jun 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants