Fixed scoreboards reading from file.

Fixed scoreboard server name length
Changed how we pull server group on startup.
This commit is contained in:
Jonathan Williams 2015-01-13 12:22:47 -08:00
parent b32259d7f1
commit c83643564b
5 changed files with 283 additions and 300 deletions

View File

@ -23,30 +23,8 @@ public class ServerConfiguration extends MiniPlugin
Region region = plugin.getConfig().getBoolean("serverstatus.us") ? Region.US : Region.EU; Region region = plugin.getConfig().getBoolean("serverstatus.us") ? Region.US : Region.EU;
String groupName = plugin.getConfig().getString("serverstatus.group"); 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 _serverGroup = ServerManager.getServerRepository(region).getServerGroup(groupName);
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;
}
}
if (_serverGroup == null) if (_serverGroup == null)
return; return;

View File

@ -138,6 +138,7 @@ public class HubManager extends MiniClientPlugin<HubClient>
private HashMap<Player, Scoreboard> _scoreboards = new HashMap<Player, Scoreboard>(); private HashMap<Player, Scoreboard> _scoreboards = new HashMap<Player, Scoreboard>();
private String _pigStacker = "0 - Nobody"; private String _pigStacker = "0 - Nobody";
private String _serverName = "";
private ItemStack _ruleBook = null; private ItemStack _ruleBook = null;
@ -204,6 +205,8 @@ public class HubManager extends MiniClientPlugin<HubClient>
_ruleBook = ItemStackFactory.Instance.CreateStack(Material.WRITTEN_BOOK, (byte)0, 1, ChatColor.GREEN + "Rule Book", new String[] { }); _ruleBook = ItemStackFactory.Instance.CreateStack(Material.WRITTEN_BOOK, (byte)0, 1, ChatColor.GREEN + "Rule Book", new String[] { });
BookMeta meta = (BookMeta)_ruleBook.getItemMeta(); 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" meta.addPage("§m-------------------§r\n"
+ "Welcome to §6§lMineplex§r\n" + "Welcome to §6§lMineplex§r\n"
@ -790,7 +793,7 @@ public class HubManager extends MiniClientPlugin<HubClient>
//Stacker //Stacker
obj.getScore(C.cAqua + C.Bold + "Server").setScore(line--); obj.getScore(C.cAqua + C.Bold + "Server").setScore(line--);
obj.getScore(GetPlugin().getConfig().getString("serverstatus.name")).setScore(line--); obj.getScore(_serverName).setScore(line--);
//Space //Space
obj.getScore(" ").setScore(line--); obj.getScore(" ").setScore(line--);

View File

@ -73,19 +73,6 @@ public class RedisServerRepository implements ServerRepository
if (server != null) 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); servers.add(server);
} }
} }
@ -298,10 +285,18 @@ public class RedisServerRepository implements ServerRepository
for (Response<Map<String, String>> response : serverDatas) for (Response<Map<String, String>> response : serverDatas)
{ {
Map<String, String> data = response.get(); Map<String, String> data = response.get();
ServerGroup serverGroup = new ServerGroup(data, serverStatuses);
if (serverGroup.getRegion() == Region.ALL || serverGroup.getRegion() == _region) try
servers.add(serverGroup); {
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) catch (JedisConnectionException exception)

View File

@ -111,6 +111,7 @@ public class GameLobbyManager implements Listener, IPacketHandler
private int _oldMaxPlayerCount = 0; // Used for scoreboard when max player count changes private int _oldMaxPlayerCount = 0; // Used for scoreboard when max player count changes
private boolean _handlingPacket = false; private boolean _handlingPacket = false;
private String _serverName;
public GameLobbyManager(ArcadeManager manager, PacketHandler packetHandler) public GameLobbyManager(ArcadeManager manager, PacketHandler packetHandler)
{ {
@ -131,6 +132,9 @@ public class GameLobbyManager implements Listener, IPacketHandler
_teamDisplay = new Location(world, 18, 101, 0); _teamDisplay = new Location(world, 18, 101, 0);
Manager.GetPluginManager().registerEvents(this, Manager.GetPlugin()); 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) private boolean HasScoreboard(Player player)
@ -1017,7 +1021,7 @@ public class GameLobbyManager implements Listener, IPacketHandler
//Server //Server
objective.getScore(" ").setScore(line--); objective.getScore(" ").setScore(line--);
objective.getScore(C.cAqua + C.Bold + "Server").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 //ELO
if (Manager.GetGame() != null && Manager.GetGame().EloRanking) if (Manager.GetGame() != null && Manager.GetGame().EloRanking)

View File

@ -1,10 +1,13 @@
package nautilus.game.arcade.scoreboard; package nautilus.game.arcade.scoreboard;
import java.util.ArrayList; 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.C;
import mineplex.core.common.util.UtilMath; 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.Game;
import nautilus.game.arcade.game.GameTeam; import nautilus.game.arcade.game.GameTeam;
@ -13,312 +16,312 @@ import org.bukkit.ChatColor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.scoreboard.DisplaySlot; import org.bukkit.scoreboard.DisplaySlot;
import org.bukkit.scoreboard.Objective; import org.bukkit.scoreboard.Objective;
import org.bukkit.scoreboard.Score;
import org.bukkit.scoreboard.Scoreboard; import org.bukkit.scoreboard.Scoreboard;
import org.bukkit.scoreboard.Team; import org.bukkit.scoreboard.Team;
public class GameScoreboard public class GameScoreboard
{ {
private Game Game; private Game Game;
private Scoreboard _scoreboard; private Scoreboard _scoreboard;
private Objective _sideObjective; private Objective _sideObjective;
private ArrayList<ScoreboardElement> _elements = new ArrayList<ScoreboardElement>(); private ArrayList<ScoreboardElement> _elements = new ArrayList<ScoreboardElement>();
private char[] _chars = "1234567890abcdefghijklmnopqrstuvwxyz".toCharArray(); private String[] _current = new String[15];
private String _title; private String _title;
private int _shineIndex; private int _shineIndex;
private boolean _shineDirection = true; private boolean _shineDirection = true;
private boolean _debug = false; private boolean _debug = false;
public GameScoreboard(Game game) public GameScoreboard(Game game)
{ {
Game = game; Game = game;
_title = " MINEPLEX "; _title = " MINEPLEX ";
// Scoreboard //Scoreboard
_scoreboard = Bukkit.getScoreboardManager().getNewScoreboard(); _scoreboard = Bukkit.getScoreboardManager().getNewScoreboard();
_sideObjective = _scoreboard.registerNewObjective("Obj" + UtilMath.r(999999999), "dummy"); _sideObjective = _scoreboard.registerNewObjective("Obj"+UtilMath.r(999999999), "dummy");
_sideObjective.setDisplaySlot(DisplaySlot.SIDEBAR); _sideObjective.setDisplaySlot(DisplaySlot.SIDEBAR);
_sideObjective.setDisplayName(C.Bold + _title); _sideObjective.setDisplayName(C.Bold + _title);
} }
public Scoreboard GetScoreboard() public Scoreboard GetScoreboard()
{ {
return _scoreboard; return _scoreboard;
} }
public Objective GetObjectiveSide() public Objective GetObjectiveSide()
{ {
return _sideObjective; return _sideObjective;
} }
public void UpdateTitle() public void UpdateTitle()
{ {
String out; String out;
if (_shineDirection) if (_shineDirection)
{ {
out = C.cGold + C.Bold; out = C.cGold + C.Bold;
} }
else else
{ {
out = C.cWhite + C.Bold; out = C.cWhite + C.Bold;
} }
for (int i = 0; i < _title.length(); i++) for (int i=0 ; i < _title.length() ; i++)
{ {
char c = _title.charAt(i); char c = _title.charAt(i);
if (_shineDirection) if (_shineDirection)
{ {
if (i == _shineIndex) if (i == _shineIndex)
out += C.cYellow + C.Bold; out += C.cYellow + C.Bold;
if (i == _shineIndex + 1) if (i == _shineIndex + 1)
out += C.cWhite + C.Bold; out += C.cWhite + C.Bold;
} }
else else
{ {
if (i == _shineIndex) if (i == _shineIndex)
out += C.cYellow + C.Bold; out += C.cYellow + C.Bold;
if (i == _shineIndex + 1) if (i == _shineIndex + 1)
out += C.cGold + C.Bold; out += C.cGold + C.Bold;
} }
out += c;
}
_sideObjective.setDisplayName(out); out += c;
}
_shineIndex++; _sideObjective.setDisplayName(out);
if (_shineIndex == _title.length() * 2) _shineIndex++;
{
_shineIndex = 0;
_shineDirection = !_shineDirection;
}
}
public String ParseTeamName(String name) if (_shineIndex == _title.length()*2)
{ {
return name.substring(0, Math.min(16, name.length())); _shineIndex = 0;
} _shineDirection = !_shineDirection;
}
}
public void CreateTeams() public String ParseTeamName(String name)
{ {
System.out.println("Creating Scoreboard Teams."); return name.substring(0, Math.min(16, name.length()));
}
_scoreboard.registerNewTeam(ParseTeamName("SPEC")).setPrefix(ChatColor.GRAY + ""); public void CreateTeams()
{
System.out.println("Creating Scoreboard Teams.");
// Team Groups
for (GameTeam team : Game.GetTeamList())
{
System.out.println("Scoreboard Team: " + team.GetName().toUpperCase());
_scoreboard.registerNewTeam(ParseTeamName(team.GetName().toUpperCase())).setPrefix(team.GetColor() + "");
}
/* _scoreboard.registerNewTeam(ParseTeamName("SPEC")).setPrefix(ChatColor.GRAY + "");
//Base Groups
for (Rank rank : Rank.values())
{
//_scoreboard.registerNewTeam(ParseTeamName(rank.Name + "SPEC")).setPrefix(ChatColor.GRAY + "");
}
//Team Groups //Team Groups
for (GameTeam team : Game.GetTeamList()) for (GameTeam team : Game.GetTeamList())
{ {
System.out.println("Scoreboard Team: " + team.GetName().toUpperCase()); System.out.println("Scoreboard Team: " + team.GetName().toUpperCase());
_scoreboard.registerNewTeam(ParseTeamName(team.GetName().toUpperCase())).setPrefix(team.GetColor() + "");
}
for (Rank rank : Rank.values()) /*
{ //Base Groups
_scoreboard.registerNewTeam(ParseTeamName(rank.Name + team.GetName().toUpperCase())).setPrefix(team.GetColor() + ""); for (Rank rank : Rank.values())
} {
} //_scoreboard.registerNewTeam(ParseTeamName(rank.Name + "SPEC")).setPrefix(ChatColor.GRAY + "");
*/ }
}
public void SetPlayerTeam(Player player, String teamName) //Team Groups
{ for (GameTeam team : Game.GetTeamList())
for (Team team : _scoreboard.getTeams()) {
team.removePlayer(player); System.out.println("Scoreboard Team: " + team.GetName().toUpperCase());
if (teamName == null) for (Rank rank : Rank.values())
teamName = ""; {
_scoreboard.registerNewTeam(ParseTeamName(rank.Name + team.GetName().toUpperCase())).setPrefix(team.GetColor() + "");
}
}
*/
}
String team = ParseTeamName(teamName); public void SetPlayerTeam(Player player, String teamName)
{
for (Team team : _scoreboard.getTeams())
team.removePlayer(player);
try if (teamName == null)
{ teamName = "";
_scoreboard.getTeam(team).addPlayer(player);
}
catch (Exception e)
{
e.printStackTrace();
System.out.println("ERROR ADDING PLAYER TO TEAM: " + team);
}
}
public void ResetScore(String line) String team = ParseTeamName(teamName);
{
_scoreboard.resetScores(line);
}
/* try
public void Reset() {
{ _scoreboard.getTeam(team).addPlayer(player);
for (ScoreboardElement elem : _elements) }
{ catch (Exception e)
for (String line : elem.GetLines()) {
{ e.printStackTrace();
ResetScore(line); System.out.println("ERROR ADDING PLAYER TO TEAM: " + team);
} }
} }
_elements.clear(); public void ResetScore(String line)
{
_scoreboard.resetScores(line);
}
_space = " "; /*
} public void Reset()
*/ {
for (ScoreboardElement elem : _elements)
{
for (String line : elem.GetLines())
{
ResetScore(line);
}
}
public String Clean(String line) _elements.clear();
{
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);
}
}
return line; _space = " ";
} }
*/
public void Write(String line) public String Clean(String line)
{ {
line = Clean(line); if (line.length() >= 16)
line = line.substring(0, 15);
_elements.add(new ScoreboardElementText(line)); return line;
} }
public void WriteOrdered(String key, String line, int value, boolean prependScore) public void Write(String line)
{ {
if (prependScore) line = Clean(line);
line = value + " " + line;
line = Clean(line); _elements.add(new ScoreboardElementText(line));
}
for (ScoreboardElement elem : _elements) public void WriteOrdered(String key, String line, int value, boolean prependScore)
{ {
if (elem instanceof ScoreboardElementScores) if (prependScore)
{ line = value + " " + line;
ScoreboardElementScores scores = (ScoreboardElementScores) elem;
if (scores.IsKey(key)) line = Clean(line);
{
scores.AddScore(line, value);
return;
}
}
}
_elements.add(new ScoreboardElementScores(key, line, value, true)); for (ScoreboardElement elem : _elements)
} {
if (elem instanceof ScoreboardElementScores)
{
ScoreboardElementScores scores = (ScoreboardElementScores)elem;
public void WriteBlank() if (scores.IsKey(key))
{ {
_elements.add(new ScoreboardElementText(" ")); scores.AddScore(line, value);
} return;
}
}
}
public void Draw() _elements.add(new ScoreboardElementScores(key, line, value, true));
{ }
if (_debug)
System.out.println();
if (_debug)
System.out.println("/////////////////////////");
// Generate Lines public void WriteBlank()
ArrayList<String> newLines = new ArrayList<String>(); {
_elements.add(new ScoreboardElementText(" "));
}
for (ScoreboardElement elem : _elements) public void Draw()
{ {
for (String line : elem.GetLines()) if (_debug) System.out.println();
{ if (_debug) System.out.println("/////////////////////////");
newLines.add(line);
}
}
for (int i = 0; i < 15; i++) //Generate Lines
{ ArrayList<String> newLines = new ArrayList<String>();
if (i >= 15 || i >= _chars.length)
break;
String str = ChatColor.COLOR_CHAR + "" + _chars[i] + ChatColor.RESET; for (ScoreboardElement elem : _elements)
{
for (String line : elem.GetLines())
{
//Ensure no duplicate lines
while (true)
{
boolean matched = false;
Score score = GetObjectiveSide().getScore(str); for (String otherLine : newLines)
{
if (line.equals(otherLine))
{
line += ChatColor.RESET;
matched = true;
}
}
if (newLines.size() <= i) if (!matched)
{ break;
if (score.isScoreSet()) }
{
ResetScore(str);
}
else
{
break;
}
}
else
{
Team team = GetScoreboard().getTeam(str);
if (team == null) newLines.add(line);
{ }
team = GetScoreboard().registerNewTeam(str); }
team.addEntry(str); //Find Changes
} HashSet<Integer> toAdd = new HashSet<Integer>();
HashSet<Integer> toDelete = new HashSet<Integer>();
String line = newLines.get(i); 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);
}
String prefix = line.substring(0, Math.min(line.length(), 16)); continue;
String suffix = ChatColor.getLastColors(line) + line.substring(Math.min(team.getPrefix().length(), 16)); }
if (!(team.getPrefix() == null ? "" : team.getPrefix()).equals(prefix)) //Update or Add Row
team.setPrefix(prefix); 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 (!(team.getSuffix() == null ? "" : team.getSuffix()).equals(suffix)) //Delete Elements - Must happen before Add
team.setSuffix(suffix); for (int i : toDelete)
{
//Remove Old Line at Index
if (_current[i] != null)
{
if (_debug) System.out.println("Deleting: " + i + " [" + _current[i] + "]");
if (!score.isScoreSet()) ResetScore(_current[i]);
{ _current[i] = null;
if (i == 15) }
{ }
score.setScore(1);
}
score.setScore(15 - i); //Add Elements
for (int i : toAdd)
{
//Insert New Line
String newLine = newLines.get(i);
GetObjectiveSide().getScore(newLine).setScore(15-i);
_current[i] = newLine;
} if (_debug) System.out.println("Setting: " + (15-i) + " [" + newLine + "]");
} }
} }
}
public void Reset() public void Reset()
{ {
_elements.clear(); _elements.clear();
} }
} }