package net.minecraft.network.protocol.game;

import net.minecraft.network.PacketListener;
import io.netty.buffer.ByteBuf;
import java.io.IOException;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.network.protocol.Packet;

public class ServerboundCustomPayloadPacket implements Packet<ServerGamePacketListener> {
    public static final ResourceLocation BRAND;
    private ResourceLocation identifier;
    private FriendlyByteBuf data;
    
    public ServerboundCustomPayloadPacket() {
    }
    
    public ServerboundCustomPayloadPacket(final ResourceLocation uh, final FriendlyByteBuf mg) {
        this.identifier = uh;
        this.data = mg;
    }
    
    @Override
    public void read(final FriendlyByteBuf mg) throws IOException {
        this.identifier = mg.readResourceLocation();
        final int integer3 = mg.readableBytes();
        if (integer3 < 0 || integer3 > 32767) {
            throw new IOException("Payload may not be larger than 32767 bytes");
        }
        this.data = new FriendlyByteBuf(mg.readBytes(integer3));
    }
    
    @Override
    public void write(final FriendlyByteBuf mg) throws IOException {
        mg.writeResourceLocation(this.identifier);
        mg.writeBytes(this.data);
    }
    
    @Override
    public void handle(final ServerGamePacketListener qz) {
        qz.handleCustomPayload(this);
        if (this.data != null) {
            this.data.release();
        }
    }
    
    static {
        BRAND = new ResourceLocation("brand");
    }
}
