    001package net.minecraft.network.packet;
    002
    003import java.io.DataInputStream;
    004import java.io.DataOutputStream;
    005import java.io.IOException;
    006
    007public class Packet3Chat extends Packet
    008{
    009    /** Maximum number of characters allowed in chat string in each packet. */
    010    public static int maxChatLength = 119;
    011
    012    /** The message being sent. */
    013    public String message;
    014    private boolean isServer;
    015
    016    public Packet3Chat()
    017    {
    018        this.isServer = true;
    019    }
    020
    021    public Packet3Chat(String par1Str)
    022    {
    023        this(par1Str, true);
    024    }
    025
    026    public Packet3Chat(String par1Str, boolean par2)
    027    {
    028        this.isServer = true;
    029
    030        if (par1Str.length() > maxChatLength)
    031        {
    032            par1Str = par1Str.substring(0, maxChatLength);
    033        }
    034
    035        this.message = par1Str;
    036        this.isServer = par2;
    037    }
    038
    039    /**
    040     * Abstract. Reads the raw packet data from the data stream.
    041     */
    042    public void readPacketData(DataInputStream par1DataInputStream) throws IOException
    043    {
    044        this.message = readString(par1DataInputStream, maxChatLength);
    045    }
    046
    047    /**
    048     * Abstract. Writes the raw packet data to the data stream.
    049     */
    050    public void writePacketData(DataOutputStream par1DataOutputStream) throws IOException
    051    {
    052        writeString(this.message, par1DataOutputStream);
    053    }
    054
    055    /**
    056     * Passes this Packet on to the NetHandler for processing.
    057     */
    058    public void processPacket(NetHandler par1NetHandler)
    059    {
    060        par1NetHandler.handleChat(this);
    061    }
    062
    063    /**
    064     * Abstract. Return the size of the packet (not counting the header).
    065     */
    066    public int getPacketSize()
    067    {
    068        return 2 + this.message.length() * 2;
    069    }
    070
    071    /**
    072     * Get whether this is a server
    073     */
    074    public boolean getIsServer()
    075    {
    076        return this.isServer;
    077    }
    078
    079    /**
    080     * If this returns true, the packet may be processed on any thread; otherwise it is queued for the main thread to
    081     * handle.
    082     */
    083    public boolean canProcessAsync()
    084    {
    085        return !this.message.startsWith("/");
    086    }
    087}