more stable, progress for making 'easier-to-use'

This commit is contained in:
Teddy 2016-01-11 12:06:30 +00:00
parent 5caeb8bee0
commit ec6e916c7b
6 changed files with 155 additions and 48 deletions

View File

@ -1,12 +1,10 @@
package nautilus.game.arcade.game;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map.Entry;
import java.util.Set;
@ -75,8 +73,8 @@ import nautilus.game.arcade.game.GameTeam.PlayerState;
import nautilus.game.arcade.kit.Kit;
import nautilus.game.arcade.kit.KitAvailability;
import nautilus.game.arcade.kit.Perk;
import nautilus.game.arcade.managers.GameChatManager;
import nautilus.game.arcade.managers.GameLobbyManager;
import nautilus.game.arcade.managers.chat.ChatStatData;
import nautilus.game.arcade.scoreboard.GameScoreboard;
import nautilus.game.arcade.stats.AssistsStatTracker;
import nautilus.game.arcade.stats.DamageDealtStatTracker;
@ -274,6 +272,11 @@ public abstract class Game implements Listener
public long PrepareTime = 9000;
public boolean PlaySoundGameStart = true;
// Chat Stats
public final ChatStatData Kills = new ChatStatData(new String[]{"Kills"}, "Kills", true);
public final ChatStatData Deaths = new ChatStatData(new String[]{"Deaths"}, "Kills", true);
public final ChatStatData KDRatio = new ChatStatData(new String[]{"KDRatio"}, "KD-Ratio", true);
// Gems
public double GemMultiplier = 1;
public boolean GemHunterEnabled = true;

View File

@ -39,7 +39,7 @@ public class BaconBrawl extends SoloGame
HungerSet = 20;
PrepareFreeze = false;
Manager.getGameChatManager().setGameChatStats("Kills", "Deaths");
Manager.getGameChatManager().setGameChatStats(Kills, Deaths);
}
@EventHandler

View File

@ -163,7 +163,7 @@ public class Evolution extends SoloGame
new KillsWhileEvolvingTracker(this)
);
Manager.getGameChatManager().setGameChatStats("Kills", "Deaths");
Manager.getGameChatManager().setGameChatStats(Kills, Deaths);
}
public EvolveManager getEvolve()

View File

@ -104,6 +104,7 @@ import nautilus.game.arcade.game.games.minestrike.items.guns.GunStats;
import nautilus.game.arcade.game.games.minestrike.items.guns.GunType;
import nautilus.game.arcade.game.games.minestrike.kits.KitPlayer;
import nautilus.game.arcade.kit.Kit;
import nautilus.game.arcade.managers.chat.ChatStatData;
import nautilus.game.arcade.stats.KaboomStatTracker;
import nautilus.game.arcade.stats.KillAllOpposingMineStrikeRoundStatTracker;
import nautilus.game.arcade.stats.KillFastStatTracker;
@ -309,7 +310,14 @@ public class MineStrike extends TeamGame
new TeamKillsStatTracker(this)
);
Manager.getGameChatManager().setGameChatStats("Kills", "Deaths", "KDRatio");
//"Kills", "Deaths", "KDRatio", "", "BoomHeadshot"
Manager.getGameChatManager().setGameChatStats(
Kills,
Deaths,
KDRatio,
new ChatStatData().blankLine(),
new ChatStatData(new String[]{null}, "Testing", false)
);
}
@Override

View File

@ -3,6 +3,7 @@ package nautilus.game.arcade.managers;
import java.text.DecimalFormat;
import java.util.AbstractMap;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
@ -20,6 +21,7 @@ import org.bukkit.event.player.PlayerItemConsumeEvent;
import net.minecraft.server.v1_8_R3.IChatBaseComponent;
import net.minecraft.server.v1_8_R3.PacketPlayOutChat;
import com.google.gson.stream.MalformedJsonException;
import mineplex.core.account.CoreClient;
import mineplex.core.common.Rank;
import mineplex.core.common.jsonchat.JsonMessage;
@ -28,8 +30,10 @@ import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.party.Party;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.game.Game;
import nautilus.game.arcade.game.Game.GameState;
import nautilus.game.arcade.game.GameTeam;
import nautilus.game.arcade.managers.chat.ChatStatData;
import org.apache.commons.lang.StringUtils;
import org.json.simple.JSONObject;
@ -38,7 +42,7 @@ public class GameChatManager implements Listener
private ArcadeManager _manager;
private LinkedList<String> _chatStats = new LinkedList<>();
private LinkedList<ChatStatData> _chatStats = new LinkedList<ChatStatData>();
public GameChatManager(ArcadeManager manager)
{
@ -149,11 +153,9 @@ public class GameChatManager implements Listener
}
else
{
event.setCancelled(true);
IChatBaseComponent baseComponent = IChatBaseComponent.ChatSerializer.a(buildJSON(sender, format, name, _chatStats, message));
for(Player partyUser : party.GetPlayersOnline())
if(safeSend(sender, format, name, message, party.GetPlayersOnline()))
{
UtilPlayer.sendPacket(partyUser, new PacketPlayOutChat(baseComponent));
event.setCancelled(true);
}
}
@ -200,11 +202,9 @@ public class GameChatManager implements Listener
{
if(_manager.GetGame().IsLive())
{
event.setCancelled(true);
IChatBaseComponent baseComponent = IChatBaseComponent.ChatSerializer.a(buildJSON(sender, format, name, _chatStats, message));
for(Player player : _manager.GetGame().GetPlayers(false))
if(safeSend(sender, format, name, message, _manager.GetGame().GetPlayers(false)))
{
UtilPlayer.sendPacket(player, new PacketPlayOutChat(baseComponent));
event.setCancelled(true);
}
}
return;
@ -232,66 +232,113 @@ public class GameChatManager implements Listener
recipientIterator.remove();
}
IChatBaseComponent baseComponent = IChatBaseComponent.ChatSerializer.a(buildJSON(sender, format, name, _chatStats, message));
for(Player player : event.getRecipients())
if(safeSend(sender, format, name, message, event.getRecipients()))
{
event.setCancelled(true);
}
}
}
public boolean safeSend(Player sender, String format, String name, String message, Collection<Player> sendto)
{
String json = buildJSON(sender, format, name, _chatStats, message);
try
{
IChatBaseComponent baseComponent = IChatBaseComponent.ChatSerializer.a(json);
for(Player player : sendto)
{
UtilPlayer.sendPacket(player, new PacketPlayOutChat(baseComponent));
}
return true;
}
catch (Exception e)
{
System.out.println("");
System.out.println("ChatStats Failed to send JSON message..");
System.out.println(json);
System.out.println("");
return false;
}
}
public void setGameChatStats(String... stats)
public void setGameChatStats(ChatStatData... stats)
{
for(String str : stats)
for(ChatStatData chatStat : stats)
{
System.out.println(str);
_chatStats.add(str);
System.out.println(chatStat.getStat());
_chatStats.add(chatStat);
}
}
private String buildJSON(Player player, String format, String name, LinkedList<String> hoverText, String message)
private String buildJSON(Player player, String format, String name, LinkedList<ChatStatData> hoverText, String message)
{
LinkedHashMap<Integer, Map.Entry<String, String>> temp = new LinkedHashMap<Integer, Map.Entry<String, String>>();
LinkedList<Map.Entry<String, String>> temp = new LinkedList<Map.Entry<String, String>>();
ChatColor teamColor = _manager.GetGame().GetTeam(player).GetColor();
temp.put(0, new AbstractMap.SimpleEntry<String, String>(C.Bold + teamColor + ChatColor.stripColor(name) + teamColor + "'s stats", ""));
temp.put(1, new AbstractMap.SimpleEntry<String, String>(" ", ""));
temp.add(new AbstractMap.SimpleEntry<String, String>(teamColor + C.Bold + ChatColor.stripColor(name) + teamColor + "'s stats", ""));
temp.add(new AbstractMap.SimpleEntry<String, String>(" ", ""));
int x = 2;
for(String str : hoverText)
Game game = _manager.GetGame();
String gameName = game.GetName();
for (int i = 0; i < hoverText.size(); i++)
{
if(!_manager.GetGame().GetStats().containsKey(player))
if (!_manager.GetGame().GetStats().containsKey(player))
{
temp.put(x, new AbstractMap.SimpleEntry<String, String>(C.cGray + "Retrieving stats..", ""));
x++;
temp.add(new AbstractMap.SimpleEntry<String, String>(C.cGray + "Retrieving stats..", ""));
break;
}
if(_manager.GetGame().GetStats().get(player).containsKey(_manager.GetGame().GetName() + "." + str))
ChatStatData chatStatData = hoverText.get(i);
String display = (chatStatData.getDisplay() == null ? chatStatData.getStat()[0] : chatStatData.getDisplay());
if(!chatStatData.isValue())
{
temp.put(x, new AbstractMap.SimpleEntry<String, String>(str, (_manager.GetGame().GetStats().get(player).get(_manager.GetGame().GetName() + "." + str).toString())));
}
else if(str.equalsIgnoreCase("kdratio"))
{
int kills = _manager.GetGame().GetStats().get(player).get(_manager.GetGame().GetName() + ".Kills");
int deaths = _manager.GetGame().GetStats().get(player).get(_manager.GetGame().GetName() + ".Deaths");
temp.put(x, new AbstractMap.SimpleEntry<String, String>(str, getRatio(kills, deaths, "##.##")));
temp.add(new AbstractMap.SimpleEntry<String, String>(chatStatData.getDisplay(), ""));
continue;
}
x++;
if (chatStatData.getStat()[0].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;
if (game.GetStats().get(player).containsKey(gameName + ".Deaths"))
deaths = game.GetStats().get(player).get(gameName + ".Deaths");
else
deaths = 0;
temp.add(new AbstractMap.SimpleEntry<String, String>(display + ": ", getRatio(kills, deaths, "##.##")));
continue;
}
String f = "{\"text\":\"\",\"extra\":[{\"text\":\"" + format + "\"},";
String n = "{\"text\":\"" + name + "\",";
if (game.GetStats().get(player).containsKey(gameName + "." + chatStatData.getStat()))
{
temp.add(new AbstractMap.SimpleEntry<String, String>(display + ": ", (game.GetStats().get(player).get(gameName + "." + chatStatData.getStat()).toString())));
}
else
{
temp.add(new AbstractMap.SimpleEntry<String, String>(display + ": ", "0"));
}
}
String f = "{\"text\":\"\",\"extra\":[{\"text\":\"" + JSONObject.escape(format) + "\"},";
String n = "{\"text\":\"" + JSONObject.escape(name) + "\",";
String stats = "\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"";
String m = ",{\"text\":\"" + message + "\"}]}";
String m = ",{\"text\":\"" + JSONObject.escape(message) + "\"}]}";
for(int i = 0; i < temp.size(); i++)
for (int i = 0; i < temp.size(); i++)
{
if(temp.containsKey(i))
stats += C.cWhite + temp.get(i).getKey() + ": " + C.cGray + temp.get(i).getValue() + (i == hoverText.size()-1 ? "\"}}}" : "\\n");
stats += 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);
return f + n + stats + m;
}

View File

@ -0,0 +1,49 @@
package nautilus.game.arcade.managers.chat;
import mineplex.core.chat.Chat;
/**
* Created by TeddyDev on 10/01/2016.
*/
public class ChatStatData
{
private String[] _stat;
private String _display;
private boolean _isValue;
public ChatStatData()
{
}
public ChatStatData(String[] stat, String display, boolean isValue)
{
_stat = stat;
_display = display;
_isValue = isValue;
}
public ChatStatData blankLine()
{
_stat = new String[]{null};
_display = " ";
_isValue = false;
return this;
}
public String[] getStat()
{
return _stat;
}
public String getDisplay()
{
return _display;
}
public boolean isValue()
{
return _isValue;
}
}