From c83643564b8ad00f9dfe257e5dcc62ae3643f68c Mon Sep 17 00:00:00 2001 From: Jonathan Williams Date: Tue, 13 Jan 2015 12:22:47 -0800 Subject: [PATCH] Fixed scoreboards reading from file. Fixed scoreboard server name length Changed how we pull server group on startup. --- .../serverConfig/ServerConfiguration.java | 26 +- .../src/mineplex/hub/HubManager.java | 5 +- .../serverdata/RedisServerRepository.java | 27 +- .../arcade/managers/GameLobbyManager.java | 6 +- .../arcade/scoreboard/GameScoreboard.java | 519 +++++++++--------- 5 files changed, 283 insertions(+), 300 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/serverConfig/ServerConfiguration.java b/Plugins/Mineplex.Core/src/mineplex/core/serverConfig/ServerConfiguration.java index 5ba0d1397..c8541bd38 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/serverConfig/ServerConfiguration.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/serverConfig/ServerConfiguration.java @@ -23,30 +23,8 @@ public class ServerConfiguration extends MiniPlugin Region region = plugin.getConfig().getBoolean("serverstatus.us") ? Region.US : Region.EU; String groupName = plugin.getConfig().getString("serverstatus.group"); - String serverName = plugin.getConfig().getString("serverstatus.name"); - - // Ugh serializing json to redis converts a players name that is only numbers to name.0 so we have to parse this off so things don't go boom. hackfix ftw - try - { - String name = serverName.split("-")[0]; - Integer.parseInt(name); - - groupName = name; - System.out.println("Changed to server group name : " + serverName); - } - catch (NumberFormatException ex) - { - // Nothing stupid.. - } - - for (ServerGroup serverGroup : ServerManager.getServerRepository(region).getServerGroups(null)) - { - if (serverGroup.getName().equalsIgnoreCase(groupName)) - { - _serverGroup = serverGroup; - break; - } - } + + _serverGroup = ServerManager.getServerRepository(region).getServerGroup(groupName); if (_serverGroup == null) return; diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java index 955c564cd..df6f2ef5d 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java @@ -138,6 +138,7 @@ public class HubManager extends MiniClientPlugin private HashMap _scoreboards = new HashMap(); private String _pigStacker = "0 - Nobody"; + private String _serverName = ""; private ItemStack _ruleBook = null; @@ -204,6 +205,8 @@ public class HubManager extends MiniClientPlugin _ruleBook = ItemStackFactory.Instance.CreateStack(Material.WRITTEN_BOOK, (byte)0, 1, ChatColor.GREEN + "Rule Book", new String[] { }); BookMeta meta = (BookMeta)_ruleBook.getItemMeta(); + _serverName = GetPlugin().getConfig().getString("serverstatus.name"); + _serverName = _serverName.substring(0, Math.min(16, _serverName.length())); meta.addPage("§m-------------------§r\n" + "Welcome to §6§lMineplex§r\n" @@ -790,7 +793,7 @@ public class HubManager extends MiniClientPlugin //Stacker obj.getScore(C.cAqua + C.Bold + "Server").setScore(line--); - obj.getScore(GetPlugin().getConfig().getString("serverstatus.name")).setScore(line--); + obj.getScore(_serverName).setScore(line--); //Space obj.getScore(" ").setScore(line--); diff --git a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/RedisServerRepository.java b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/RedisServerRepository.java index 168b78ff0..e0380cb43 100644 --- a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/RedisServerRepository.java +++ b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/RedisServerRepository.java @@ -73,19 +73,6 @@ public class RedisServerRepository implements ServerRepository if (server != null) { - // Ugh serializing json to redis converts a players name that is only numbers to name.0 so we have to parse this off so things don't go boom. hackfix ftw - try - { - String name = server.getName().split("-")[0]; - Integer.parseInt(name); - - server.setGroup(name); - } - catch (NumberFormatException ex) - { - // Nothing stupid.. - } - servers.add(server); } } @@ -298,10 +285,18 @@ public class RedisServerRepository implements ServerRepository for (Response> response : serverDatas) { Map data = response.get(); - ServerGroup serverGroup = new ServerGroup(data, serverStatuses); - if (serverGroup.getRegion() == Region.ALL || serverGroup.getRegion() == _region) - servers.add(serverGroup); + try + { + ServerGroup serverGroup = new ServerGroup(data, serverStatuses); + + if (serverGroup.getRegion() == Region.ALL || serverGroup.getRegion() == _region) + servers.add(serverGroup); + } + catch (Exception exception) + { + exception.printStackTrace(); + } } } catch (JedisConnectionException exception) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameLobbyManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameLobbyManager.java index 5ada44ded..04f82d8c7 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameLobbyManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameLobbyManager.java @@ -111,6 +111,7 @@ public class GameLobbyManager implements Listener, IPacketHandler private int _oldMaxPlayerCount = 0; // Used for scoreboard when max player count changes private boolean _handlingPacket = false; + private String _serverName; public GameLobbyManager(ArcadeManager manager, PacketHandler packetHandler) { @@ -131,6 +132,9 @@ public class GameLobbyManager implements Listener, IPacketHandler _teamDisplay = new Location(world, 18, 101, 0); Manager.GetPluginManager().registerEvents(this, Manager.GetPlugin()); + + _serverName = Manager.GetPlugin().getConfig().getString("serverstatus.name"); + _serverName = _serverName.substring(0, Math.min(16, _serverName.length())); } private boolean HasScoreboard(Player player) @@ -1017,7 +1021,7 @@ public class GameLobbyManager implements Listener, IPacketHandler //Server objective.getScore(" ").setScore(line--); objective.getScore(C.cAqua + C.Bold + "Server").setScore(line--); - objective.getScore(Manager.GetPlugin().getConfig().getString("serverstatus.name")).setScore(line--); + objective.getScore(_serverName).setScore(line--); //ELO if (Manager.GetGame() != null && Manager.GetGame().EloRanking) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/scoreboard/GameScoreboard.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/scoreboard/GameScoreboard.java index ba185561d..924d655eb 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/scoreboard/GameScoreboard.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/scoreboard/GameScoreboard.java @@ -1,10 +1,13 @@ package nautilus.game.arcade.scoreboard; import java.util.ArrayList; -import java.util.Objects; +import java.util.HashSet; +import mineplex.core.common.Rank; import mineplex.core.common.util.C; import mineplex.core.common.util.UtilMath; +import mineplex.core.common.util.UtilTime; +import mineplex.core.common.util.UtilTime.TimeUnit; import nautilus.game.arcade.game.Game; import nautilus.game.arcade.game.GameTeam; @@ -13,312 +16,312 @@ import org.bukkit.ChatColor; import org.bukkit.entity.Player; import org.bukkit.scoreboard.DisplaySlot; import org.bukkit.scoreboard.Objective; -import org.bukkit.scoreboard.Score; import org.bukkit.scoreboard.Scoreboard; import org.bukkit.scoreboard.Team; public class GameScoreboard { - private Game Game; + private Game Game; - private Scoreboard _scoreboard; - private Objective _sideObjective; + private Scoreboard _scoreboard; + private Objective _sideObjective; - private ArrayList _elements = new ArrayList(); - private char[] _chars = "1234567890abcdefghijklmnopqrstuvwxyz".toCharArray(); + private ArrayList _elements = new ArrayList(); + private String[] _current = new String[15]; - private String _title; - private int _shineIndex; - private boolean _shineDirection = true; + private String _title; + private int _shineIndex; + private boolean _shineDirection = true; + + private boolean _debug = false; + + public GameScoreboard(Game game) + { + Game = game; - private boolean _debug = false; + _title = " MINEPLEX "; - public GameScoreboard(Game game) - { - Game = game; + //Scoreboard + _scoreboard = Bukkit.getScoreboardManager().getNewScoreboard(); - _title = " MINEPLEX "; + _sideObjective = _scoreboard.registerNewObjective("Obj"+UtilMath.r(999999999), "dummy"); + _sideObjective.setDisplaySlot(DisplaySlot.SIDEBAR); + _sideObjective.setDisplayName(C.Bold + _title); + } - // Scoreboard - _scoreboard = Bukkit.getScoreboardManager().getNewScoreboard(); + public Scoreboard GetScoreboard() + { + return _scoreboard; + } - _sideObjective = _scoreboard.registerNewObjective("Obj" + UtilMath.r(999999999), "dummy"); - _sideObjective.setDisplaySlot(DisplaySlot.SIDEBAR); - _sideObjective.setDisplayName(C.Bold + _title); - } + public Objective GetObjectiveSide() + { + return _sideObjective; + } - public Scoreboard GetScoreboard() - { - return _scoreboard; - } + public void UpdateTitle() + { + String out; + + if (_shineDirection) + { + out = C.cGold + C.Bold; + } + else + { + out = C.cWhite + C.Bold; + } + + for (int i=0 ; i < _title.length() ; i++) + { + char c = _title.charAt(i); + + if (_shineDirection) + { + if (i == _shineIndex) + out += C.cYellow + C.Bold; + + if (i == _shineIndex + 1) + out += C.cWhite + C.Bold; + } + else + { + if (i == _shineIndex) + out += C.cYellow + C.Bold; + + if (i == _shineIndex + 1) + out += C.cGold + C.Bold; + } + + + out += c; + } + + _sideObjective.setDisplayName(out); + + _shineIndex++; + + if (_shineIndex == _title.length()*2) + { + _shineIndex = 0; + _shineDirection = !_shineDirection; + } + } - public Objective GetObjectiveSide() - { - return _sideObjective; - } + public String ParseTeamName(String name) + { + return name.substring(0, Math.min(16, name.length())); + } - public void UpdateTitle() - { - String out; + public void CreateTeams() + { + System.out.println("Creating Scoreboard Teams."); - if (_shineDirection) - { - out = C.cGold + C.Bold; - } - else - { - out = C.cWhite + C.Bold; - } + + _scoreboard.registerNewTeam(ParseTeamName("SPEC")).setPrefix(ChatColor.GRAY + ""); + + //Team Groups + for (GameTeam team : Game.GetTeamList()) + { + System.out.println("Scoreboard Team: " + team.GetName().toUpperCase()); + _scoreboard.registerNewTeam(ParseTeamName(team.GetName().toUpperCase())).setPrefix(team.GetColor() + ""); + } + + /* + //Base Groups + for (Rank rank : Rank.values()) + { + //_scoreboard.registerNewTeam(ParseTeamName(rank.Name + "SPEC")).setPrefix(ChatColor.GRAY + ""); + } - for (int i = 0; i < _title.length(); i++) - { - char c = _title.charAt(i); + //Team Groups + for (GameTeam team : Game.GetTeamList()) + { + System.out.println("Scoreboard Team: " + team.GetName().toUpperCase()); + + for (Rank rank : Rank.values()) + { + _scoreboard.registerNewTeam(ParseTeamName(rank.Name + team.GetName().toUpperCase())).setPrefix(team.GetColor() + ""); + } + } + */ + } - if (_shineDirection) - { - if (i == _shineIndex) - out += C.cYellow + C.Bold; + public void SetPlayerTeam(Player player, String teamName) + { + for (Team team : _scoreboard.getTeams()) + team.removePlayer(player); - if (i == _shineIndex + 1) - out += C.cWhite + C.Bold; - } - else - { - if (i == _shineIndex) - out += C.cYellow + C.Bold; + if (teamName == null) + teamName = ""; - if (i == _shineIndex + 1) - out += C.cGold + C.Bold; - } + String team = ParseTeamName(teamName); - out += c; - } + try + { + _scoreboard.getTeam(team).addPlayer(player); + } + catch (Exception e) + { + e.printStackTrace(); + System.out.println("ERROR ADDING PLAYER TO TEAM: " + team); + } + } - _sideObjective.setDisplayName(out); + public void ResetScore(String line) + { + _scoreboard.resetScores(line); + } - _shineIndex++; + /* + public void Reset() + { + for (ScoreboardElement elem : _elements) + { + for (String line : elem.GetLines()) + { + ResetScore(line); + } + } - if (_shineIndex == _title.length() * 2) - { - _shineIndex = 0; - _shineDirection = !_shineDirection; - } - } + _elements.clear(); - public String ParseTeamName(String name) - { - return name.substring(0, Math.min(16, name.length())); - } + _space = " "; + } + */ - public void CreateTeams() - { - System.out.println("Creating Scoreboard Teams."); + public String Clean(String line) + { + if (line.length() >= 16) + line = line.substring(0, 15); - _scoreboard.registerNewTeam(ParseTeamName("SPEC")).setPrefix(ChatColor.GRAY + ""); + return line; + } - // Team Groups - for (GameTeam team : Game.GetTeamList()) - { - System.out.println("Scoreboard Team: " + team.GetName().toUpperCase()); - _scoreboard.registerNewTeam(ParseTeamName(team.GetName().toUpperCase())).setPrefix(team.GetColor() + ""); - } + public void Write(String line) + { + line = Clean(line); - /* - //Base Groups - for (Rank rank : Rank.values()) - { - //_scoreboard.registerNewTeam(ParseTeamName(rank.Name + "SPEC")).setPrefix(ChatColor.GRAY + ""); - } + _elements.add(new ScoreboardElementText(line)); + } - //Team Groups - for (GameTeam team : Game.GetTeamList()) - { - System.out.println("Scoreboard Team: " + team.GetName().toUpperCase()); - - for (Rank rank : Rank.values()) - { - _scoreboard.registerNewTeam(ParseTeamName(rank.Name + team.GetName().toUpperCase())).setPrefix(team.GetColor() + ""); - } - } - */ - } + public void WriteOrdered(String key, String line, int value, boolean prependScore) + { + if (prependScore) + line = value + " " + line; - public void SetPlayerTeam(Player player, String teamName) - { - for (Team team : _scoreboard.getTeams()) - team.removePlayer(player); + line = Clean(line); - if (teamName == null) - teamName = ""; + for (ScoreboardElement elem : _elements) + { + if (elem instanceof ScoreboardElementScores) + { + ScoreboardElementScores scores = (ScoreboardElementScores)elem; - String team = ParseTeamName(teamName); + if (scores.IsKey(key)) + { + scores.AddScore(line, value); + return; + } + } + } - try - { - _scoreboard.getTeam(team).addPlayer(player); - } - catch (Exception e) - { - e.printStackTrace(); - System.out.println("ERROR ADDING PLAYER TO TEAM: " + team); - } - } + _elements.add(new ScoreboardElementScores(key, line, value, true)); + } - public void ResetScore(String line) - { - _scoreboard.resetScores(line); - } + public void WriteBlank() + { + _elements.add(new ScoreboardElementText(" ")); + } - /* - public void Reset() - { - for (ScoreboardElement elem : _elements) - { - for (String line : elem.GetLines()) - { - ResetScore(line); - } - } + public void Draw() + { + if (_debug) System.out.println(); + if (_debug) System.out.println("/////////////////////////"); - _elements.clear(); + //Generate Lines + ArrayList newLines = new ArrayList(); - _space = " "; - } - */ + for (ScoreboardElement elem : _elements) + { + for (String line : elem.GetLines()) + { + //Ensure no duplicate lines + while (true) + { + boolean matched = false; - public String Clean(String line) - { - if (line.length() > 28) - { - // Due to the scoreboard using teams, You can use prefix and suffix for a total length of 32. - // this means that the total length of the string can't extend 32. - // Reason for the fancy logic is that the beginning of the suffix needs to use colors from line1 else the line is pure - // white. And line2 can't have its length extend 16.. - String line1 = line.substring(0, 16); - String color = ChatColor.getLastColors(line1); - String line2 = line.substring(16); - int length = 16 - (color + line2).length(); - if (length > 0) - { - return line1 + line2.substring(0, line2.length() - length); - } - } + for (String otherLine : newLines) + { + if (line.equals(otherLine)) + { + line += ChatColor.RESET; + matched = true; + } + } - return line; - } + if (!matched) + break; + } - public void Write(String line) - { - line = Clean(line); + newLines.add(line); + } + } - _elements.add(new ScoreboardElementText(line)); - } + //Find Changes + HashSet toAdd = new HashSet(); + HashSet toDelete = new HashSet(); - public void WriteOrdered(String key, String line, int value, boolean prependScore) - { - if (prependScore) - line = value + " " + line; + for (int i=0 ; i<15 ; i++) + { + //Delete Old Excess Row + if (i >= newLines.size()) + { + if (_current[i] != null) + { + if (_debug) System.out.println("Delete: " + i + " [" + _current[i] + "]"); + toDelete.add(i); + } - line = Clean(line); + continue; + } - for (ScoreboardElement elem : _elements) - { - if (elem instanceof ScoreboardElementScores) - { - ScoreboardElementScores scores = (ScoreboardElementScores) elem; + //Update or Add Row + if (_current[i] == null || !_current[i].equals(newLines.get(i))) + { + if (_debug) System.out.println("Update: " + i + " [" + newLines.get(i) + "]"); + toDelete.add(i); + toAdd.add(i); + } + } - if (scores.IsKey(key)) - { - scores.AddScore(line, value); - return; - } - } - } + //Delete Elements - Must happen before Add + for (int i : toDelete) + { + //Remove Old Line at Index + if (_current[i] != null) + { + if (_debug) System.out.println("Deleting: " + i + " [" + _current[i] + "]"); - _elements.add(new ScoreboardElementScores(key, line, value, true)); - } + ResetScore(_current[i]); + _current[i] = null; + } + } - public void WriteBlank() - { - _elements.add(new ScoreboardElementText(" ")); - } + //Add Elements + for (int i : toAdd) + { + //Insert New Line + String newLine = newLines.get(i); + GetObjectiveSide().getScore(newLine).setScore(15-i); + _current[i] = newLine; - public void Draw() - { - if (_debug) - System.out.println(); - if (_debug) - System.out.println("/////////////////////////"); + if (_debug) System.out.println("Setting: " + (15-i) + " [" + newLine + "]"); + } + } - // Generate Lines - ArrayList newLines = new ArrayList(); - - for (ScoreboardElement elem : _elements) - { - for (String line : elem.GetLines()) - { - newLines.add(line); - } - } - - for (int i = 0; i < 15; i++) - { - if (i >= 15 || i >= _chars.length) - break; - - String str = ChatColor.COLOR_CHAR + "" + _chars[i] + ChatColor.RESET; - - Score score = GetObjectiveSide().getScore(str); - - if (newLines.size() <= i) - { - if (score.isScoreSet()) - { - ResetScore(str); - } - else - { - break; - } - } - else - { - Team team = GetScoreboard().getTeam(str); - - if (team == null) - { - team = GetScoreboard().registerNewTeam(str); - - team.addEntry(str); - } - - String line = newLines.get(i); - - String prefix = line.substring(0, Math.min(line.length(), 16)); - String suffix = ChatColor.getLastColors(line) + line.substring(Math.min(team.getPrefix().length(), 16)); - - if (!(team.getPrefix() == null ? "" : team.getPrefix()).equals(prefix)) - team.setPrefix(prefix); - - if (!(team.getSuffix() == null ? "" : team.getSuffix()).equals(suffix)) - team.setSuffix(suffix); - - if (!score.isScoreSet()) - { - if (i == 15) - { - score.setScore(1); - } - - score.setScore(15 - i); - - } - } - } - } - - public void Reset() - { - _elements.clear(); - } + public void Reset() + { + _elements.clear(); + } }