package net.minecraft.network.protocol.game;

import net.minecraft.network.PacketListener;
import java.io.IOException;
import net.minecraft.network.FriendlyByteBuf;
import java.util.UUID;
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;
    private UUID sender;
    
    public ClientboundChatPacket() {
    }
    
    public ClientboundChatPacket(final Component mr, final ChatType mo, final UUID uUID) {
        this.message = mr;
        this.type = mo;
        this.sender = uUID;
    }
    
    @Override
    public void read(final FriendlyByteBuf mg) throws IOException {
        this.message = mg.readComponent();
        this.type = ChatType.getForIndex(mg.readByte());
        this.sender = mg.readUUID();
    }
    
    @Override
    public void write(final FriendlyByteBuf mg) throws IOException {
        mg.writeComponent(this.message);
        mg.writeByte(this.type.getIndex());
        mg.writeUUID(this.sender);
    }
    
    @Override
    public void handle(final ClientGamePacketListener nl) {
        nl.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;
    }
    
    public UUID getSender() {
        return this.sender;
    }
    
    @Override
    public boolean isSkippable() {
        return true;
    }
}
