Include original packet in `FramedPacket` for debugging/listening purpose

This commit is contained in:
TheMode 2021-08-13 19:58:14 +02:00
parent 17f9eb45ca
commit d4f74abc64
2 changed files with 11 additions and 2 deletions

View File

@ -1,5 +1,7 @@
package net.minestom.server.network.packet;
import net.minestom.server.network.packet.server.ServerPacket;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import java.nio.ByteBuffer;
@ -8,13 +10,16 @@ import java.nio.ByteBuffer;
* Represents a packet which is already framed. (packet id+payload) + optional compression
* Can be used if you want to send the exact same buffer to multiple clients without processing it more than once.
*/
@ApiStatus.Internal
public final class FramedPacket {
private final int packetId;
private final ByteBuffer body;
private final ServerPacket packet;
public FramedPacket(int packetId, @NotNull ByteBuffer body) {
public FramedPacket(int packetId, @NotNull ByteBuffer body, @NotNull ServerPacket packet) {
this.packetId = packetId;
this.body = body;
this.packet = packet;
}
public int packetId() {
@ -24,4 +29,8 @@ public final class FramedPacket {
public @NotNull ByteBuffer body() {
return body;
}
public @NotNull ServerPacket packet() {
return packet;
}
}

View File

@ -94,7 +94,7 @@ public final class PacketUtils {
if (!PACKET_LISTENER_MANAGER.processServerPacket(packet, players))
return;
final ByteBuffer finalBuffer = createFramedPacket(packet);
final FramedPacket framedPacket = new FramedPacket(packet.getId(), finalBuffer);
final FramedPacket framedPacket = new FramedPacket(packet.getId(), finalBuffer, packet);
// Send packet to all players
for (Player player : players) {
if (!player.isOnline() || !playerValidator.isValid(player))