Add new chat features to JsonMessage

This commit is contained in:
Shaun Bennett 2014-10-15 11:11:32 -05:00
parent 62d4804aa6
commit 58f69b49d7
2 changed files with 57 additions and 2 deletions

View File

@ -1,7 +1,11 @@
package mineplex.core.common.jsonchat;
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer;
import org.bukkit.entity.Player;
import net.minecraft.server.v1_7_R4.ChatSerializer;
import net.minecraft.server.v1_7_R4.PacketPlayOutChat;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
public class JsonMessage
@ -63,4 +67,53 @@ public class JsonMessage
{
UtilServer.getServer().dispatchCommand(UtilServer.getServer().getConsoleSender(), "tellraw " + player.getName() + " " + toString());
}
/**
* Send a message to players using the new 1.8 message types
*
* @param messageType Message type to send
* @param players Players to send to
*/
public void send(MessageType messageType, Player... players)
{
send(messageType, false, players);
}
/**
* Send a message to players using the new 1.8 message types
*
* @param messageType Message type to send
* @param defaultToChat Only applies to MessageType.ABOVE_HOTBAR. If true, it will send this to chat for 1.7 clients
* @param players Players to send to
*/
public void send(MessageType messageType, boolean defaultToChat, Player... players)
{
PacketPlayOutChat chatPacket = new PacketPlayOutChat(ChatSerializer.a(toString()));
chatPacket.setChatType(messageType.getId());
for (Player player : players)
{
if (defaultToChat || messageType != MessageType.ABOVE_HOTBAR || UtilPlayer.is1_8(player))
((CraftPlayer) player).getHandle().playerConnection.sendPacket(chatPacket);
}
}
public static enum MessageType
{
CHAT_BOX((byte) 0), // Inside Chat Box
SYSTEM_MESSAGE((byte) 1), // Inside Chat Box - This is used for the client to identify difference between chat message and server messages
ABOVE_HOTBAR((byte) 2); // Shows above hotbar
private byte _id;
MessageType(byte id)
{
_id = id;
}
public byte getId()
{
return _id;
}
}
}

View File

@ -8,7 +8,6 @@ import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.server.ServerListPingEvent;
import mineplex.core.MiniPlugin;
import mineplex.core.common.Rank;
@ -240,6 +239,9 @@ public class NewsManager extends MiniPlugin
{
_newsIndex = (_newsIndex + 1)%_news.length;
_newsTime = System.currentTimeMillis();
// JsonMessage jsonMessage = new JsonMessage(_news[_newsIndex]);
// jsonMessage.send(JsonMessage.MessageType.ABOVE_HOTBAR, UtilServer.getPlayers());
}
if (_newsIndex >= _news.length)
{