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");
_serverGroup = ServerManager.getServerRepository(region).getServerGroup(groupName);
// 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;
}
}
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;
public GameScoreboard(Game game)
{
Game = game;
private boolean _debug = false; _title = " MINEPLEX ";
public GameScoreboard(Game game) //Scoreboard
{ _scoreboard = Bukkit.getScoreboardManager().getNewScoreboard();
Game = game;
_title = " MINEPLEX "; _sideObjective = _scoreboard.registerNewObjective("Obj"+UtilMath.r(999999999), "dummy");
_sideObjective.setDisplaySlot(DisplaySlot.SIDEBAR);
_sideObjective.setDisplayName(C.Bold + _title);
}
// Scoreboard public Scoreboard GetScoreboard()
_scoreboard = Bukkit.getScoreboardManager().getNewScoreboard(); {
return _scoreboard;
}
_sideObjective = _scoreboard.registerNewObjective("Obj" + UtilMath.r(999999999), "dummy"); public Objective GetObjectiveSide()
_sideObjective.setDisplaySlot(DisplaySlot.SIDEBAR); {
_sideObjective.setDisplayName(C.Bold + _title); return _sideObjective;
} }
public Scoreboard GetScoreboard() public void UpdateTitle()
{ {
return _scoreboard; 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() public String ParseTeamName(String name)
{ {
return _sideObjective; return name.substring(0, Math.min(16, name.length()));
} }
public void UpdateTitle() public void CreateTeams()
{ {
String out; System.out.println("Creating Scoreboard Teams.");
if (_shineDirection)
{ _scoreboard.registerNewTeam(ParseTeamName("SPEC")).setPrefix(ChatColor.GRAY + "");
out = C.cGold + C.Bold;
} //Team Groups
else for (GameTeam team : Game.GetTeamList())
{ {
out = C.cWhite + C.Bold; 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++) //Team Groups
{ for (GameTeam team : Game.GetTeamList())
char c = _title.charAt(i); {
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) public void SetPlayerTeam(Player player, String teamName)
{ {
if (i == _shineIndex) for (Team team : _scoreboard.getTeams())
out += C.cYellow + C.Bold; team.removePlayer(player);
if (i == _shineIndex + 1) if (teamName == null)
out += C.cWhite + C.Bold; teamName = "";
}
else
{
if (i == _shineIndex)
out += C.cYellow + C.Bold;
if (i == _shineIndex + 1) String team = ParseTeamName(teamName);
out += C.cGold + C.Bold;
}
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) _elements.clear();
{
_shineIndex = 0;
_shineDirection = !_shineDirection;
}
}
public String ParseTeamName(String name) _space = " ";
{ }
return name.substring(0, Math.min(16, name.length())); */
}
public void CreateTeams() public String Clean(String line)
{ {
System.out.println("Creating Scoreboard Teams."); if (line.length() >= 16)
line = line.substring(0, 15);
_scoreboard.registerNewTeam(ParseTeamName("SPEC")).setPrefix(ChatColor.GRAY + ""); return line;
}
// Team Groups public void Write(String line)
for (GameTeam team : Game.GetTeamList()) {
{ line = Clean(line);
System.out.println("Scoreboard Team: " + team.GetName().toUpperCase());
_scoreboard.registerNewTeam(ParseTeamName(team.GetName().toUpperCase())).setPrefix(team.GetColor() + "");
}
/* _elements.add(new ScoreboardElementText(line));
//Base Groups }
for (Rank rank : Rank.values())
{
//_scoreboard.registerNewTeam(ParseTeamName(rank.Name + "SPEC")).setPrefix(ChatColor.GRAY + "");
}
//Team Groups public void WriteOrdered(String key, String line, int value, boolean prependScore)
for (GameTeam team : Game.GetTeamList()) {
{ if (prependScore)
System.out.println("Scoreboard Team: " + team.GetName().toUpperCase()); line = value + " " + line;
for (Rank rank : Rank.values())
{
_scoreboard.registerNewTeam(ParseTeamName(rank.Name + team.GetName().toUpperCase())).setPrefix(team.GetColor() + "");
}
}
*/
}
public void SetPlayerTeam(Player player, String teamName) line = Clean(line);
{
for (Team team : _scoreboard.getTeams())
team.removePlayer(player);
if (teamName == null) for (ScoreboardElement elem : _elements)
teamName = ""; {
if (elem instanceof ScoreboardElementScores)
{
ScoreboardElementScores scores = (ScoreboardElementScores)elem;
String team = ParseTeamName(teamName); if (scores.IsKey(key))
{
scores.AddScore(line, value);
return;
}
}
}
try _elements.add(new ScoreboardElementScores(key, line, value, true));
{ }
_scoreboard.getTeam(team).addPlayer(player);
}
catch (Exception e)
{
e.printStackTrace();
System.out.println("ERROR ADDING PLAYER TO TEAM: " + team);
}
}
public void ResetScore(String line) public void WriteBlank()
{ {
_scoreboard.resetScores(line); _elements.add(new ScoreboardElementText(" "));
} }
/* public void Draw()
public void Reset() {
{ if (_debug) System.out.println();
for (ScoreboardElement elem : _elements) if (_debug) System.out.println("/////////////////////////");
{
for (String line : elem.GetLines())
{
ResetScore(line);
}
}
_elements.clear(); //Generate Lines
ArrayList<String> newLines = new ArrayList<String>();
_space = " "; for (ScoreboardElement elem : _elements)
} {
*/ for (String line : elem.GetLines())
{
//Ensure no duplicate lines
while (true)
{
boolean matched = false;
public String Clean(String line) for (String otherLine : newLines)
{ {
if (line.length() > 28) if (line.equals(otherLine))
{ {
// Due to the scoreboard using teams, You can use prefix and suffix for a total length of 32. line += ChatColor.RESET;
// this means that the total length of the string can't extend 32. matched = true;
// 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; if (!matched)
} break;
}
public void Write(String line) newLines.add(line);
{ }
line = Clean(line); }
_elements.add(new ScoreboardElementText(line)); //Find Changes
} HashSet<Integer> toAdd = new HashSet<Integer>();
HashSet<Integer> toDelete = new HashSet<Integer>();
public void WriteOrdered(String key, String line, int value, boolean prependScore) for (int i=0 ; i<15 ; i++)
{ {
if (prependScore) //Delete Old Excess Row
line = value + " " + line; 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) //Update or Add Row
{ if (_current[i] == null || !_current[i].equals(newLines.get(i)))
if (elem instanceof ScoreboardElementScores) {
{ if (_debug) System.out.println("Update: " + i + " [" + newLines.get(i) + "]");
ScoreboardElementScores scores = (ScoreboardElementScores) elem; toDelete.add(i);
toAdd.add(i);
}
}
if (scores.IsKey(key)) //Delete Elements - Must happen before Add
{ for (int i : toDelete)
scores.AddScore(line, value); {
return; //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() //Add Elements
{ for (int i : toAdd)
_elements.add(new ScoreboardElementText(" ")); {
} //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("Setting: " + (15-i) + " [" + newLine + "]");
{ }
if (_debug) }
System.out.println();
if (_debug)
System.out.println("/////////////////////////");
// Generate Lines public void Reset()
ArrayList<String> newLines = new ArrayList<String>(); {
_elements.clear();
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();
}
} }