From 263e1326cd0ea37bba178caf74756aa597c3b6be Mon Sep 17 00:00:00 2001 From: Teddy Date: Sat, 9 Jan 2016 20:22:29 +0000 Subject: [PATCH] JSON progress --- .../nautilus/game/arcade/ArcadeManager.java | 8 +- .../src/nautilus/game/arcade/game/Game.java | 3 + .../game/games/baconbrawl/BaconBrawl.java | 2 + .../game/games/evolution/Evolution.java | 2 + .../game/arcade/managers/GameChatManager.java | 201 ++++++++++++------ 5 files changed, 155 insertions(+), 61 deletions(-) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java index db787f98e..c1698e5db 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java @@ -170,6 +170,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation private GameTournamentManager _gameTournamentManager; private GameWorldManager _gameWorldManager; private GameHostManager _gameHostManager; + private GameChatManager _gameChatManager; private ServerStatusManager _serverStatusManager; private InventoryManager _inventoryManager; private CosmeticManager _cosmeticManager; @@ -273,7 +274,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation _arcadeShop = new ArcadeShop(this, clientManager, donationManager); // Managers - new GameChatManager(this); + _gameChatManager = new GameChatManager(this); _gameCreationManager = new GameCreationManager(this); _gameGemManager = new GameGemManager(this); _gameManager = new GameManager(this); @@ -345,6 +346,11 @@ public class ArcadeManager extends MiniPlugin implements IRelation addCommand(new RequiredRankCommand(this)); } + public GameChatManager getGameChatManager() + { + return _gameChatManager; + } + public GameServerConfig GetServerConfig() { return _serverConfig; diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java index 6eec52eb7..3659b0ef6 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java @@ -1,10 +1,12 @@ 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; @@ -73,6 +75,7 @@ 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.scoreboard.GameScoreboard; import nautilus.game.arcade.stats.AssistsStatTracker; diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/baconbrawl/BaconBrawl.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/baconbrawl/BaconBrawl.java index 0ee17ce94..1648437e9 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/baconbrawl/BaconBrawl.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/baconbrawl/BaconBrawl.java @@ -38,6 +38,8 @@ public class BaconBrawl extends SoloGame DamageTeamSelf = true; HungerSet = 20; PrepareFreeze = false; + + Manager.getGameChatManager().setGameChatStats("Kills", "Deaths"); } @EventHandler diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/evolution/Evolution.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/evolution/Evolution.java index bfcd5896f..3dab469b2 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/evolution/Evolution.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/evolution/Evolution.java @@ -162,6 +162,8 @@ public class Evolution extends SoloGame new NoMeleeTracker(this), new KillsWhileEvolvingTracker(this) ); + + Manager.getGameChatManager().setGameChatStats("Kills", "Deaths"); } public EvolveManager getEvolve() diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameChatManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameChatManager.java index 4b520c4d8..dd5bfcc13 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameChatManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameChatManager.java @@ -1,15 +1,12 @@ package nautilus.game.arcade.managers; +import java.util.AbstractMap; +import java.util.Arrays; +import java.util.HashMap; import java.util.Iterator; - -import mineplex.core.account.CoreClient; -import mineplex.core.common.Rank; -import mineplex.core.common.util.C; -import mineplex.core.common.util.F; -import mineplex.core.party.Party; -import nautilus.game.arcade.ArcadeManager; -import nautilus.game.arcade.game.Game.GameState; -import nautilus.game.arcade.game.GameTeam; +import java.util.LinkedHashMap; +import java.util.LinkedList; +import java.util.Map; import org.bukkit.ChatColor; import org.bukkit.entity.Player; @@ -17,96 +14,119 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent; +import net.minecraft.server.v1_8_R3.IChatBaseComponent; +import net.minecraft.server.v1_8_R3.PacketPlayOutChat; + +import mineplex.core.account.CoreClient; +import mineplex.core.common.Rank; +import mineplex.core.common.util.C; +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.GameState; +import nautilus.game.arcade.game.GameTeam; +import org.apache.commons.lang.StringUtils; +import org.json.simple.JSONObject; public class GameChatManager implements Listener { - ArcadeManager Manager; + + private ArcadeManager _manager; + + private LinkedList _chatStats = new LinkedList<>(); public GameChatManager(ArcadeManager manager) { - Manager = manager; + _manager = manager; - Manager.getPluginManager().registerEvents(this, Manager.getPlugin()); - } + _manager.getPluginManager().registerEvents(this, _manager.getPlugin()); + } @EventHandler public void MeCancel(PlayerCommandPreprocessEvent event) { if (event.getMessage().startsWith("/me ")) { - event.getPlayer().sendMessage(F.main("Mirror", "You can't see /me messages, are you a vampire?")); + UtilPlayer.message(event.getPlayer(), F.main("Mirror", "You can't see /me messages, are you a vampire?")); event.setCancelled(true); } } @EventHandler - public void HandleChat(AsyncPlayerChatEvent event) + public void HandleChat(AsyncPlayerChatEvent event) { if (event.isCancelled()) return; Player sender = event.getPlayer(); String senderName = sender.getName(); - - //Dead Prefix - String dead = ""; - if (Manager.GetGame() != null) - if (Manager.GetGame().GetTeam(sender) != null) - if (!Manager.GetGame().IsAlive(sender)) - dead = C.cGray + "Dead "; - Rank rank = Manager.GetClients().Get(sender).GetRank(); + PacketPlayOutChat packet = null; + String format = ""; + String name = ""; + String message = ""; + + + //Dead Prefix + String dead = ""; + if (_manager.GetGame() != null) + if (_manager.GetGame().GetTeam(sender) != null) + if (!_manager.GetGame().IsAlive(sender)) + dead = C.cGray + "Dead " + C.Reset; + + Rank rank = _manager.GetClients().Get(sender).GetRank(); String disguiseTag = ""; - if(Manager.GetClients().Get(sender).isDisguised()) + if(_manager.GetClients().Get(sender).isDisguised()) { - CoreClient cc = Manager.GetClients().Get(sender); - rank = cc.getDisguisedRank(); - - if(!cc.GetRank().has(Rank.JNR_DEV)) - { - disguiseTag = ChatColor.BLACK + " "; - } + CoreClient cc = _manager.GetClients().Get(sender); + rank = cc.getDisguisedRank(); + + if(!cc.GetRank().has(Rank.JNR_DEV)) + { + disguiseTag = ChatColor.BLACK + " "; + } } - + boolean ownsUltra = false; - if (Manager.GetGame() != null) - ownsUltra= Manager.GetDonation().Get(sender.getName()).OwnsUnknownPackage(Manager.GetServerConfig().ServerType + " ULTRA"); + if (_manager.GetGame() != null) + ownsUltra = _manager.GetDonation().Get(sender.getName()).OwnsUnknownPackage(_manager.GetServerConfig().ServerType + " ULTRA"); //Level String levelStr = ""; - if (!Manager.GetGameHostManager().isPrivateServer()) - levelStr = Manager.GetAchievement().getMineplexLevel(sender, rank); - + if (!_manager.GetGameHostManager().isPrivateServer()) + levelStr = _manager.GetAchievement().getMineplexLevel(sender, rank); + String rankStr = ""; //Rank Prefix & MPS Host Prefix - if (Manager.GetGameHostManager().isHost(event.getPlayer())) + if (_manager.GetGameHostManager().isHost(event.getPlayer())) { - if (Manager.GetGameHostManager().isEventServer()) - rankStr = C.cDGreen + C.Bold + "Event Host "; + if (_manager.GetGameHostManager().isEventServer()) + rankStr = C.cDGreen + C.Bold + "Event Host " + C.Reset; else - rankStr = C.cDGreen + C.Bold + "MPS Host "; + rankStr = C.cDGreen + C.Bold + "MPS Host " + C.Reset; } - else if (Manager.GetGameHostManager().isAdmin(event.getPlayer(), false)) + else if (_manager.GetGameHostManager().isAdmin(event.getPlayer(), false)) { - if (Manager.GetGameHostManager().isEventServer()) - rankStr = C.cDGreen + C.Bold + "Event Co-Host "; + if (_manager.GetGameHostManager().isEventServer()) + rankStr = C.cDGreen + C.Bold + "Event Co-Host " + C.Reset; else - rankStr = C.cDGreen + C.Bold + "MPS Co-Host "; + rankStr = C.cDGreen + C.Bold + "MPS Co-Host " + C.Reset; } else { if (rank != Rank.ALL) - rankStr = rank.getTag(true, true) + " "; + rankStr = rank.getTag(true, true) + " " + C.Reset; if (ownsUltra && !rank.has(Rank.ULTRA)) - rankStr = Rank.ULTRA.getTag(true, true) + " "; + rankStr = Rank.ULTRA.getTag(true, true) + " " + C.Reset; } - + if (event.getMessage().charAt(0) == '@') { //Party Chat - Party party = Manager.getPartyManager().GetParty(sender); + Party party = _manager.getPartyManager().GetParty(sender); if (party != null) { @@ -115,24 +135,39 @@ public class GameChatManager implements Listener event.setMessage(event.getMessage().substring(1, event.getMessage().length())); event.setFormat(levelStr + C.cDPurple + C.Bold + "Party " + C.cWhite + C.Bold + senderName + " " + C.cPurple + "%2$s"); - event.getRecipients().addAll(party.GetPlayersOnline()); + format = event.getFormat().split(sender.getName())[0]; + name = _manager.GetColor(sender) + sender.getName(); + message = event.getFormat().split(sender.getName())[1].replace("%2$s", "") + JSONObject.escape(event.getMessage()); + + if(!_manager.GetGame().IsLive()) + { + event.getRecipients().addAll(party.GetPlayersOnline()); + } + else + { + for(Player partyUser : party.GetPlayersOnline()) + { + + } + } + //TODO send to party players return; } } - + //Base Format - event.setFormat(disguiseTag + dead + levelStr + rankStr + Manager.GetColor(sender) + senderName + " " + ChatColor.WHITE + "%2$s"); + event.setFormat(disguiseTag + dead + levelStr + rankStr + _manager.GetColor(sender) + senderName + " " + ChatColor.WHITE + "%2$s"); //Public/Private (Not If Player Dead) - if (Manager.GetGame() != null && Manager.GetGame().GetState() == GameState.Live) + if (_manager.GetGame() != null && _manager.GetGame().GetState() == GameState.Live) { boolean globalMessage = false; //Team - GameTeam team = Manager.GetGame().GetTeam(sender); + GameTeam team = _manager.GetGame().GetTeam(sender); - if (team != null) + if (team != null) { //Team Chat if (event.getMessage().charAt(0) == '@') @@ -149,7 +184,10 @@ public class GameChatManager implements Listener } if (globalMessage) + { + //TODO send globally return; + } //Team Message Remove Recipient Iterator recipientIterator = event.getRecipients().iterator(); @@ -158,12 +196,12 @@ public class GameChatManager implements Listener { Player receiver = recipientIterator.next(); - if (!Manager.GetServerConfig().Tournament && Manager.GetClients().Get(receiver).GetRank().has(Rank.MODERATOR)) + if (!_manager.GetServerConfig().Tournament && _manager.GetClients().Get(receiver).GetRank().has(Rank.MODERATOR)) continue; - - GameTeam recTeam = Manager.GetGame().GetTeam(receiver); - GameTeam sendTeam = Manager.GetGame().GetTeam(sender); - + + GameTeam recTeam = _manager.GetGame().GetTeam(receiver); + GameTeam sendTeam = _manager.GetGame().GetTeam(sender); + if (recTeam == null || sendTeam == null) { continue; @@ -174,4 +212,47 @@ public class GameChatManager implements Listener } } } + + public void setGameChatStats(String... stats) + { + for(String str : stats) + { + System.out.println(_manager.GetGame().GetName() + "." + str); + _chatStats.add(_manager.GetGame().GetName() + "." + str); + } + } + + private String buildJSON(Player player, String format, String name, String[] hoverText, String message) + { + LinkedHashMap> temp = new LinkedHashMap>(); + + int x = 0; + for(String str : _manager.GetGame().GetStats().get(player).keySet()) + { + for(String str2 : hoverText) + { + if(str.equalsIgnoreCase(str2)) + { + Map.Entry entry = new AbstractMap.SimpleEntry(str, _manager.GetGame().GetStats().get(player).get(str)); + temp.put(x, entry); + x++; + } + + continue; + } + } + + String f = "{\"text\":\"\",\"extra\":[{\"text\":\"" + format + "\"}"; + String n = "{\"text\":\"NAME\","; + String stats = "\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\""; + String m = "{\"text\":\"MESSAGE\"}]}"; + + 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.length ? "\"}}}" : "\n"); + } + + return f + n + stats + m; + } }