package net.minecraft.network.protocol.game;

import net.minecraft.network.PacketListener;
import java.io.IOException;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.chat.ChatType;
import net.minecraft.network.chat.Component;
import net.minecraft.network.protocol.Packet;

public class ClientboundChatPacket implements Packet<ClientGamePacketListener> {
    private Component message;
    private ChatType type;
    
    public ClientboundChatPacket() {
    }
    
    public ClientboundChatPacket(final Component lf) {
        this(lf, ChatType.SYSTEM);
    }
    
    public ClientboundChatPacket(final Component lf, final ChatType ld) {
        this.message = lf;
        this.type = ld;
    }
    
    @Override
    public void read(final FriendlyByteBuf kv) throws IOException {
        this.message = kv.readComponent();
        this.type = ChatType.getForIndex(kv.readByte());
    }
    
    @Override
    public void write(final FriendlyByteBuf kv) throws IOException {
        kv.writeComponent(this.message);
        kv.writeByte(this.type.getIndex());
    }
    
    @Override
    public void handle(final ClientGamePacketListener lw) {
        lw.handleChat(this);
    }
    
    public Component getMessage() {
        return this.message;
    }
    
    public boolean isSystem() {
        return this.type == ChatType.SYSTEM || this.type == ChatType.GAME_INFO;
    }
    
    public ChatType getType() {
        return this.type;
    }
    
    @Override
    public boolean isSkippable() {
        return true;
    }
}
