Search in sources :

Example 1 with ChatMessage

use of net.glowstone.net.message.play.game.ChatMessage in project Glowstone by GlowstoneMC.

the class TellrawCommand method execute.

@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (!testPermission(sender))
        return true;
    if (args.length < 2) {
        sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
        return false;
    }
    Player player = Bukkit.getPlayerExact(args[0]);
    if (player == null || sender instanceof Player && !((Player) sender).canSee(player)) {
        sender.sendMessage("There's no player by that name online.");
    } else {
        StringBuilder message = new StringBuilder();
        for (int i = 1; i < args.length; i++) {
            if (i > 1)
                message.append(" ");
            message.append(args[i]);
        }
        GlowPlayer glowPlayer = (GlowPlayer) player;
        Object obj = JSONValue.parse(message.toString());
        if (!(obj instanceof JSONObject)) {
            sender.sendMessage(ChatColor.RED + "Failed to parse JSON");
        } else {
            glowPlayer.getSession().send(new ChatMessage((JSONObject) obj));
        }
    }
    return true;
}
Also used : GlowPlayer(net.glowstone.entity.GlowPlayer) Player(org.bukkit.entity.Player) JSONObject(org.json.simple.JSONObject) ChatMessage(net.glowstone.net.message.play.game.ChatMessage) GlowPlayer(net.glowstone.entity.GlowPlayer) JSONObject(org.json.simple.JSONObject)

Example 2 with ChatMessage

use of net.glowstone.net.message.play.game.ChatMessage in project Glowstone by GlowstoneMC.

the class GlowServer method broadcast.

@Override
public void broadcast(BaseComponent... components) {
    try {
        Message packet = new ChatMessage((JSONObject) parser.parse(ComponentSerializer.toString(components)));
        broadcastPacket(packet);
    } catch (ParseException e) {
        //should never happen
        e.printStackTrace();
    }
}
Also used : Message(com.flowpowered.network.Message) ChatMessage(net.glowstone.net.message.play.game.ChatMessage) ChatMessage(net.glowstone.net.message.play.game.ChatMessage) ParseException(org.json.simple.parser.ParseException)

Example 3 with ChatMessage

use of net.glowstone.net.message.play.game.ChatMessage in project Glowstone by GlowstoneMC.

the class ChatCodec method decode.

@Override
public ChatMessage decode(ByteBuf buf) throws IOException {
    TextMessage message = GlowBufUtils.readChat(buf);
    int mode = buf.readByte();
    return new ChatMessage(message, mode);
}
Also used : ChatMessage(net.glowstone.net.message.play.game.ChatMessage) TextMessage(net.glowstone.util.TextMessage)

Aggregations

ChatMessage (net.glowstone.net.message.play.game.ChatMessage)3 Message (com.flowpowered.network.Message)1 GlowPlayer (net.glowstone.entity.GlowPlayer)1 TextMessage (net.glowstone.util.TextMessage)1 Player (org.bukkit.entity.Player)1 JSONObject (org.json.simple.JSONObject)1 ParseException (org.json.simple.parser.ParseException)1