Search in sources :

Example 1 with ChatPacket

use of org.dragonet.net.packet.minecraft.ChatPacket in project Dragonet-Legacy by DragonetMC.

the class ChatMessageTranslator method handleSpecific.

@Override
public PEPacket[] handleSpecific(ChatMessage packet) {
    String msg = "";
    try {
        //String msg = ((ChatMessage) message).text.asPlaintext();
        Object json = new JSONParser().parse(packet.text.encode());
        if (json instanceof JSONObject) {
            msg = this.getTranslator().translateChatMessage((JSONObject) json);
        } else {
            msg = packet.text.asPlaintext();
        }
    } catch (ParseException ex) {
        return null;
    }
    //if(json)
    ChatPacket pkMessage = new ChatPacket();
    pkMessage.source = "";
    pkMessage.type = ChatPacket.TextType.RAW;
    pkMessage.message = msg;
    return new PEPacket[] { pkMessage };
}
Also used : ChatPacket(org.dragonet.net.packet.minecraft.ChatPacket) JSONObject(org.json.simple.JSONObject) PEPacket(org.dragonet.net.packet.minecraft.PEPacket) JSONObject(org.json.simple.JSONObject) JSONParser(org.json.simple.parser.JSONParser) ParseException(org.json.simple.parser.ParseException)

Aggregations

ChatPacket (org.dragonet.net.packet.minecraft.ChatPacket)1 PEPacket (org.dragonet.net.packet.minecraft.PEPacket)1 JSONObject (org.json.simple.JSONObject)1 JSONParser (org.json.simple.parser.JSONParser)1 ParseException (org.json.simple.parser.ParseException)1