This commit is contained in:
Sam 2017-10-26 17:29:22 +01:00 committed by Alexander Meech
parent cd85f4434a
commit 567773f035

View File

@ -2,7 +2,9 @@ package nautilus.game.arcade.managers.chat;
import java.text.DecimalFormat;
import java.util.AbstractMap;
import java.util.AbstractMap.SimpleEntry;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map;
@ -87,9 +89,9 @@ public class GameChatManager implements Listener
Player sender = event.getPlayer();
String senderName = sender.getName();
String format = "";
String name = "";
String message = "";
String format;
String name;
String message;
//Dead Prefix
@ -318,16 +320,13 @@ public class GameChatManager implements Listener
public void setGameChatStats(ChatStatData... stats)
{
_chatStats = new LinkedList<ChatStatData>();
for (ChatStatData chatStat : stats)
{
_chatStats.add(chatStat);
}
_chatStats = new LinkedList<>();
Collections.addAll(_chatStats, stats);
}
private JsonMessage buildJSON(Player player, String prefix, String rankStr, PermissionGroup group, String name, LinkedList<ChatStatData> hoverText, String message)
{
if (_manager.GetGame() == null || (_manager.GetGame().GetState() != GameState.Prepare && _manager.GetGame().GetState() != GameState.Live && _manager.GetGame().GetState() != GameState.End))
if (_manager.GetGame() == null || _manager.GetGame().GetState() == GameState.Recruit)
{
if (group.getDisplay(false, false, false, false).isEmpty())
{
@ -340,91 +339,83 @@ public class GameChatManager implements Listener
.add(JSONObject.escape(name)).add(JSONObject.escape(message));
}
LinkedList<Map.Entry<String, String>> temp = new LinkedList<Map.Entry<String, String>>();
LinkedList<Map.Entry<String, String>> temp = new LinkedList<>();
ChatColor teamColor = _manager.GetColor(player);
temp.add(new AbstractMap.SimpleEntry<String, String>(teamColor + C.Bold + ChatColor.stripColor(name) + teamColor + "'s stats", ""));
temp.add(new AbstractMap.SimpleEntry<String, String>(" ", ""));
temp.add(new AbstractMap.SimpleEntry<>(teamColor + C.Bold + ChatColor.stripColor(name) + teamColor + "'s stats", ""));
temp.add(new AbstractMap.SimpleEntry<>(" ", ""));
Game game = _manager.GetGame();
String gameName = game.GetName();
for (int i = 0; i < hoverText.size(); i++)
for (ChatStatData statData : hoverText)
{
if (!_manager.GetGame().GetStats().containsKey(player))
{
temp.add(new AbstractMap.SimpleEntry<String, String>(C.cGray + "No in-game stats available", ""));
temp.add(new SimpleEntry<>(C.cGray + "No in-game stats available", ""));
break;
}
ChatStatData chatStatData = hoverText.get(i);
String display = (chatStatData.getDisplay() == null ? chatStatData.getStat() : chatStatData.getDisplay());
String display = (statData.getDisplay() == null ? statData.getStat() : statData.getDisplay());
if (!chatStatData.isValue())
if (!statData.isValue())
{
temp.add(new AbstractMap.SimpleEntry<String, String>(chatStatData.getDisplay(), ""));
temp.add(new SimpleEntry<>(statData.getDisplay(), ""));
continue;
}
if (chatStatData.getStat().equalsIgnoreCase("kit"))
if (statData.getStat().equalsIgnoreCase("kit"))
{
temp.add(new AbstractMap.SimpleEntry<String, String>(display + ": ", game.GetKit(player).GetName()));
temp.add(new SimpleEntry<>(display + ": ", game.GetKit(player).GetName()));
continue;
}
if (chatStatData.getStat().equalsIgnoreCase("kdratio"))
if (statData.getStat().equalsIgnoreCase("kdratio"))
{
int kills;
int deaths;
if (game.GetStats().get(player).containsKey(gameName + ".Kills"))
kills = game.GetStats().get(player).get(gameName + ".Kills");
else
kills = 0;
kills = game.GetStats().get(player).getOrDefault(gameName + ".Kills", 0);
if (game.GetStats().get(player).containsKey(gameName + ".Deaths"))
deaths = game.GetStats().get(player).get(gameName + ".Deaths");
else
deaths = 0;
deaths = game.GetStats().get(player).getOrDefault(gameName + ".Deaths", 0);
temp.add(new AbstractMap.SimpleEntry<String, String>(display + ": ", "" + getRatio(kills, deaths, "##.##")));
temp.add(new SimpleEntry<>(display + ": ", "" + getRatio(kills, deaths, "##.##")));
continue;
}
if (game.GetStats().get(player).containsKey(gameName + "." + chatStatData.getStat()))
if (game.GetStats().get(player).containsKey(gameName + "." + statData.getStat()))
{
temp.add(new AbstractMap.SimpleEntry<String, String>(display + ": ", (game.GetStats().get(player).get(gameName + "." + chatStatData.getStat()).toString())));
temp.add(new SimpleEntry<>(display + ": ", (game.GetStats().get(player).get(gameName + "." + statData.getStat()).toString())));
}
else
{
temp.add(new AbstractMap.SimpleEntry<String, String>(display + ": ", "0"));
temp.add(new SimpleEntry<>(display + ": ", "0"));
}
}
String stats = "";
StringBuilder stats = new StringBuilder();
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");
stats.append(C.cWhite).append(JSONObject.escape(temp.get(i).getKey())).append(C.cGray).append(JSONObject.escape(temp.get(i).getValue())).append(i >= temp.size() - 1 ? "" : "\\n");
}
if (group.getDisplay(false, false, false, false).isEmpty())
{
return new JsonMessage("").extra(JSONObject.escape(prefix))
.add(JSONObject.escape(rankStr)).add(JSONObject.escape(name)).hover("show_text", stats).add(JSONObject.escape(message));
.add(JSONObject.escape(rankStr)).add(JSONObject.escape(name)).hover("show_text", stats.toString()).add(JSONObject.escape(message));
}
return new JsonMessage("").extra(JSONObject.escape(prefix))
.add(JSONObject.escape(rankStr)).hover("show_text", group.getDisplay(true, true, true, false) + ChatColor.WHITE + "\n" + group.getDescription())
.add(JSONObject.escape(name)).hover("show_text", stats).add(JSONObject.escape(message));
.add(JSONObject.escape(name)).hover("show_text", stats.toString()).add(JSONObject.escape(message));
}
public double getRatio(int var1, int var2, String format)
private double getRatio(int var1, int var2, String format)
{
double ratio = 0.0;
double ratio;
if (var1 <= 0) ratio = 0d;
else if (var2 <= 1) ratio = (double) var1;
else if (var1 <= 0 && var2 <= 0) ratio = 0d;
else ratio = ((double) var1 / var2);
return Double.parseDouble(new DecimalFormat(format).format(ratio));