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.
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.
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
registerHandler(ClientboundPartyInfoPacket.class, packet -> partyCallback(packet))
ClientboundPacketHandler
interface, which could become bothersome in the future. Each packet class also had more boilerplate which has been removed as a result.handle
method from running when it does not need to (for example, invoking a handler which does not have any implementation foronClientHelloPacket
) which aids performance (minorly)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.