JSON now handled by JsonMessage Builder

This commit is contained in:
Teddy 2016-01-12 13:25:47 +00:00
parent 88c53bf464
commit f1314d5c26

View File

@ -24,6 +24,7 @@ import net.minecraft.server.v1_8_R3.PacketPlayOutChat;
import com.google.gson.stream.MalformedJsonException; import com.google.gson.stream.MalformedJsonException;
import mineplex.core.account.CoreClient; import mineplex.core.account.CoreClient;
import mineplex.core.common.Rank; import mineplex.core.common.Rank;
import mineplex.core.common.jsonchat.ChildJsonMessage;
import mineplex.core.common.jsonchat.JsonMessage; import mineplex.core.common.jsonchat.JsonMessage;
import mineplex.core.common.util.C; import mineplex.core.common.util.C;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
@ -34,6 +35,7 @@ import nautilus.game.arcade.game.Game;
import nautilus.game.arcade.game.Game.GameState; import nautilus.game.arcade.game.Game.GameState;
import nautilus.game.arcade.game.GameTeam; import nautilus.game.arcade.game.GameTeam;
import nautilus.game.arcade.managers.chat.ChatStatData; import nautilus.game.arcade.managers.chat.ChatStatData;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.jooq.tools.json.JSONObject; import org.jooq.tools.json.JSONObject;
@ -243,23 +245,17 @@ public class GameChatManager implements Listener
public boolean safeSend(Player sender, String format, String name, String message, Collection<Player> sendto) public boolean safeSend(Player sender, String format, String name, String message, Collection<Player> sendto)
{ {
String json = buildJSON(sender, format, name, _chatStats, message); final JsonMessage json = buildJSON(sender, format, name, _chatStats, message);
try try
{ {
IChatBaseComponent baseComponent = IChatBaseComponent.ChatSerializer.a(json); json.send(JsonMessage.MessageType.CHAT_BOX, sendto.toArray(new Player[sendto.size()]));
for(Player player : sendto)
{
UtilPlayer.sendPacket(player, new PacketPlayOutChat(baseComponent));
}
return true; return true;
} }
catch (Exception e) catch (Exception e)
{ {
System.out.println("");
System.out.println("ChatStats Failed to send JSON message.."); System.out.println("ChatStats Failed to send JSON message..");
System.out.println(json); System.out.println(json);
System.out.println("");
return false; return false;
} }
} }
@ -273,7 +269,7 @@ public class GameChatManager implements Listener
} }
} }
private String buildJSON(Player player, String format, String name, LinkedList<ChatStatData> hoverText, String message) private JsonMessage buildJSON(Player player, String format, String name, LinkedList<ChatStatData> hoverText, String message)
{ {
LinkedList<Map.Entry<String, String>> temp = new LinkedList<Map.Entry<String, String>>(); LinkedList<Map.Entry<String, String>> temp = new LinkedList<Map.Entry<String, String>>();
@ -330,18 +326,17 @@ public class GameChatManager implements Listener
} }
} }
String f = "{\"text\":\"\",\"extra\":[{\"text\":\"" + JSONObject.escape(format) + "\"},"; String stats2 = "";
String n = "{\"text\":\"" + JSONObject.escape(name) + "\",";
String stats = "\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"";
String m = ",{\"text\":\"" + JSONObject.escape(message) + "\"}]}";
for (int i = 0; i < temp.size(); i++) for (int i = 0; i < temp.size(); i++)
{ {
stats += C.cWhite + JSONObject.escape(temp.get(i).getKey()) + C.cGray + JSONObject.escape(temp.get(i).getValue()) + (i >= temp.size()-1 ? "\"}}}" : "\\n"); stats2 += C.cWhite + JSONObject.escape(temp.get(i).getKey()) + C.cGray + JSONObject.escape(temp.get(i).getValue()) + (i >= temp.size()-1 ? "" : "\\n");
} }
System.out.println(f + n + stats + m); JsonMessage jsonMessage = new JsonMessage("")
return f + n + stats + m; .extra(JSONObject.escape(format))
.add(JSONObject.escape(name)).hover("show_text", stats2)
.add(JSONObject.escape(message));
return jsonMessage;
} }
public String getRatio(int var1, int var2, String format) public String getRatio(int var1, int var2, String format)