package net.minecraft.network.protocol.game;

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

public class ServerboundChatPacket implements Packet<ServerGamePacketListener> {
    private String message;
    
    public ServerboundChatPacket() {
    }
    
    public ServerboundChatPacket(String string) {
        if (string.length() > 256) {
            string = string.substring(0, 256);
        }
        this.message = string;
    }
    
    @Override
    public void read(final FriendlyByteBuf kv) throws IOException {
        this.message = kv.readUtf(256);
    }
    
    @Override
    public void write(final FriendlyByteBuf kv) throws IOException {
        kv.writeUtf(this.message);
    }
    
    @Override
    public void handle(final ServerGamePacketListener pl) {
        pl.handleChat(this);
    }
    
    public String getMessage() {
        return this.message;
    }
}
