Fixed scoreboards reading from file.
Fixed scoreboard server name length Changed how we pull server group on startup.
This commit is contained in:
parent
b32259d7f1
commit
c83643564b
@ -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;
|
||||||
|
@ -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--);
|
||||||
|
@ -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,11 +285,19 @@ 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();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
ServerGroup serverGroup = new ServerGroup(data, serverStatuses);
|
ServerGroup serverGroup = new ServerGroup(data, serverStatuses);
|
||||||
|
|
||||||
if (serverGroup.getRegion() == Region.ALL || serverGroup.getRegion() == _region)
|
if (serverGroup.getRegion() == Region.ALL || serverGroup.getRegion() == _region)
|
||||||
servers.add(serverGroup);
|
servers.add(serverGroup);
|
||||||
}
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
exception.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (JedisConnectionException exception)
|
catch (JedisConnectionException exception)
|
||||||
{
|
{
|
||||||
|
@ -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)
|
||||||
|
@ -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,7 +16,6 @@ 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;
|
||||||
|
|
||||||
@ -25,7 +27,7 @@ public class GameScoreboard
|
|||||||
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;
|
||||||
@ -91,6 +93,7 @@ public class GameScoreboard
|
|||||||
out += C.cGold + C.Bold;
|
out += C.cGold + C.Bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
out += c;
|
out += c;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,6 +117,7 @@ public class GameScoreboard
|
|||||||
{
|
{
|
||||||
System.out.println("Creating Scoreboard Teams.");
|
System.out.println("Creating Scoreboard Teams.");
|
||||||
|
|
||||||
|
|
||||||
_scoreboard.registerNewTeam(ParseTeamName("SPEC")).setPrefix(ChatColor.GRAY + "");
|
_scoreboard.registerNewTeam(ParseTeamName("SPEC")).setPrefix(ChatColor.GRAY + "");
|
||||||
|
|
||||||
//Team Groups
|
//Team Groups
|
||||||
@ -188,21 +192,8 @@ public class GameScoreboard
|
|||||||
|
|
||||||
public String Clean(String line)
|
public String Clean(String line)
|
||||||
{
|
{
|
||||||
if (line.length() > 28)
|
if (line.length() >= 16)
|
||||||
{
|
line = line.substring(0, 15);
|
||||||
// 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;
|
return line;
|
||||||
}
|
}
|
||||||
@ -245,10 +236,8 @@ public class GameScoreboard
|
|||||||
|
|
||||||
public void Draw()
|
public void Draw()
|
||||||
{
|
{
|
||||||
if (_debug)
|
if (_debug) System.out.println();
|
||||||
System.out.println();
|
if (_debug) System.out.println("/////////////////////////");
|
||||||
if (_debug)
|
|
||||||
System.out.println("/////////////////////////");
|
|
||||||
|
|
||||||
//Generate Lines
|
//Generate Lines
|
||||||
ArrayList<String> newLines = new ArrayList<String>();
|
ArrayList<String> newLines = new ArrayList<String>();
|
||||||
@ -257,63 +246,77 @@ public class GameScoreboard
|
|||||||
{
|
{
|
||||||
for (String line : elem.GetLines())
|
for (String line : elem.GetLines())
|
||||||
{
|
{
|
||||||
|
//Ensure no duplicate lines
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
boolean matched = false;
|
||||||
|
|
||||||
|
for (String otherLine : newLines)
|
||||||
|
{
|
||||||
|
if (line.equals(otherLine))
|
||||||
|
{
|
||||||
|
line += ChatColor.RESET;
|
||||||
|
matched = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!matched)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
newLines.add(line);
|
newLines.add(line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Find Changes
|
||||||
|
HashSet<Integer> toAdd = new HashSet<Integer>();
|
||||||
|
HashSet<Integer> toDelete = new HashSet<Integer>();
|
||||||
|
|
||||||
for (int i=0 ; i<15 ; i++)
|
for (int i=0 ; i<15 ; i++)
|
||||||
{
|
{
|
||||||
if (i >= 15 || i >= _chars.length)
|
//Delete Old Excess Row
|
||||||
break;
|
if (i >= newLines.size())
|
||||||
|
|
||||||
String str = ChatColor.COLOR_CHAR + "" + _chars[i] + ChatColor.RESET;
|
|
||||||
|
|
||||||
Score score = GetObjectiveSide().getScore(str);
|
|
||||||
|
|
||||||
if (newLines.size() <= i)
|
|
||||||
{
|
{
|
||||||
if (score.isScoreSet())
|
if (_current[i] != null)
|
||||||
{
|
{
|
||||||
ResetScore(str);
|
if (_debug) System.out.println("Delete: " + i + " [" + _current[i] + "]");
|
||||||
}
|
toDelete.add(i);
|
||||||
else
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Team team = GetScoreboard().getTeam(str);
|
|
||||||
|
|
||||||
if (team == null)
|
|
||||||
{
|
|
||||||
team = GetScoreboard().registerNewTeam(str);
|
|
||||||
|
|
||||||
team.addEntry(str);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String line = newLines.get(i);
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
String prefix = line.substring(0, Math.min(line.length(), 16));
|
//Update or Add Row
|
||||||
String suffix = ChatColor.getLastColors(line) + line.substring(Math.min(team.getPrefix().length(), 16));
|
if (_current[i] == null || !_current[i].equals(newLines.get(i)))
|
||||||
|
|
||||||
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)
|
if (_debug) System.out.println("Update: " + i + " [" + newLines.get(i) + "]");
|
||||||
|
toDelete.add(i);
|
||||||
|
toAdd.add(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Delete Elements - Must happen before Add
|
||||||
|
for (int i : toDelete)
|
||||||
{
|
{
|
||||||
score.setScore(1);
|
//Remove Old Line at Index
|
||||||
|
if (_current[i] != null)
|
||||||
|
{
|
||||||
|
if (_debug) System.out.println("Deleting: " + i + " [" + _current[i] + "]");
|
||||||
|
|
||||||
|
ResetScore(_current[i]);
|
||||||
|
_current[i] = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 + "]");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user