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;
}
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();
}
}
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);
}
Aggregations