diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/jsonchat/JsonMessage.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/jsonchat/JsonMessage.java index 428d3344e..a42d080fb 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/jsonchat/JsonMessage.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/jsonchat/JsonMessage.java @@ -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; + } + } } diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/modules/NewsManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/modules/NewsManager.java index 38793e994..fa1789a09 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/modules/NewsManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/modules/NewsManager.java @@ -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,7 +239,10 @@ 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) { // Resets newsIndex if outside of bounds of news array after RefreshNews but before UtilTime.elapsed above