JSON progress

This commit is contained in:
Teddy 2016-01-09 20:22:29 +00:00
parent 8d197c9ece
commit 263e1326cd
5 changed files with 155 additions and 61 deletions

View File

@ -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;

View File

@ -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;

View File

@ -38,6 +38,8 @@ public class BaconBrawl extends SoloGame
DamageTeamSelf = true;
HungerSet = 20;
PrepareFreeze = false;
Manager.getGameChatManager().setGameChatStats("Kills", "Deaths");
}
@EventHandler

View File

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

View File

@ -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,16 +14,33 @@ 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<String> _chatStats = new LinkedList<>();
public GameChatManager(ArcadeManager manager)
{
Manager = manager;
_manager = manager;
Manager.getPluginManager().registerEvents(this, Manager.getPlugin());
_manager.getPluginManager().registerEvents(this, _manager.getPlugin());
}
@EventHandler
@ -34,7 +48,7 @@ public class GameChatManager implements Listener
{
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);
}
}
@ -48,18 +62,24 @@ public class GameChatManager implements Listener
Player sender = event.getPlayer();
String senderName = sender.getName();
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 ";
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();
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);
CoreClient cc = _manager.GetClients().Get(sender);
rank = cc.getDisguisedRank();
if(!cc.GetRank().has(Rank.JNR_DEV))
@ -70,43 +90,43 @@ public class GameChatManager implements Listener
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,22 +135,37 @@ 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");
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)
{
@ -149,7 +184,10 @@ public class GameChatManager implements Listener
}
if (globalMessage)
{
//TODO send globally
return;
}
//Team Message Remove Recipient
Iterator<Player> recipientIterator = event.getRecipients().iterator();
@ -158,11 +196,11 @@ 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)
{
@ -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<Integer, Map.Entry<String, Integer>> temp = new LinkedHashMap<Integer, Map.Entry<String, Integer>>();
int x = 0;
for(String str : _manager.GetGame().GetStats().get(player).keySet())
{
for(String str2 : hoverText)
{
if(str.equalsIgnoreCase(str2))
{
Map.Entry<String, Integer> entry = new AbstractMap.SimpleEntry<String, Integer>(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;
}
}