Release the payload buffer after a plugin message is handled.
Also reset the read index so every data listener can read the complete buffer without having to reset it.
@@ -84,12 +84,17 @@ public void removeListener(RawDataListener listener) {
}
void handlePacket(FMLProxyPacket msg, RemoteConnection con) {
- ChannelBuf payload = SpongeNetworkManager.toChannelBuf(msg.payload());
- Platform.Type side = msg.getTarget().isClient() ? Platform.Type.CLIENT : Platform.Type.SERVER;
- Set<RawDataListener> listeners = this.listeners.get(side);
+ try {
+ final ChannelBuf payload = SpongeNetworkManager.toChannelBuf(msg.payload());
+ final Platform.Type side = msg.getTarget().isClient() ? Platform.Type.CLIENT : Platform.Type.SERVER;
+ final Set<RawDataListener> listeners = this.listeners.get(side);
for (RawDataListener listener : listeners) {
+ payload.setReadIndex(0);
listener.handlePayload(payload, con, side);
}
+ } finally {
+ msg.payload().release();
+ }
}
private FMLProxyPacket createPacket(Consumer<ChannelBuf> payloadConsumer) {
