Merge remote-tracking branch 'origin/master'

This commit is contained in:
Shaun Bennett 2015-01-16 15:30:16 -05:00
commit c8be08e5b9
8 changed files with 382 additions and 342 deletions

View File

@ -66,70 +66,41 @@ public class Portal extends MiniPlugin
if (_connectingPlayers.contains(player.getName()))
return;
final boolean override = serverName.equalsIgnoreCase("Lobby");
final Rank playerRank = _clientManager.Get(player).GetRank();
runAsync(new Runnable()
if (override)
{
public void run()
sendPlayer(player, serverName);
}
else
{
runAsync(new Runnable()
{
final MinecraftServer server = _repository.getServerStatus(serverName);
if (server == null)
return;
Bukkit.getServer().getScheduler().runTask(_plugin, new Runnable()
public void run()
{
public void run()
final MinecraftServer server = _repository.getServerStatus(serverName);
if (server == null)
return;
Bukkit.getServer().getScheduler().runTask(_plugin, new Runnable()
{
if (server.getPlayerCount() < server.getMaxPlayerCount() || playerRank.Has(Rank.ULTRA))
public void run()
{
ByteArrayOutputStream b = new ByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(b);
try
if (server.getPlayerCount() < server.getMaxPlayerCount() || playerRank.Has(Rank.ULTRA))
{
out.writeUTF("Connect");
out.writeUTF(serverName);
sendPlayer(player, serverName);
}
catch (IOException e)
{
// Can never happen
}
finally
{
try
{
out.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
player.sendPluginMessage(GetPlugin(), "BungeeCord", b.toByteArray());
_connectingPlayers.add(player.getName());
GetScheduler().scheduleSyncDelayedTask(GetPlugin(), new Runnable()
{
public void run()
{
_connectingPlayers.remove(player.getName());
}
}, 20L);
else
UtilPlayer.message(
player,
F.main(getName(), "You have been sent to " + C.cGold + serverName));
F.main(getName(), C.cGold + serverName + C.cRed + " is full!"));
}
else
UtilPlayer.message(
player,
F.main(getName(), C.cGold + serverName + C.cRed + " is full!"));
}
});
}
});
});
}
});
}
}
public static void transferPlayer(String playerName, String serverName)
@ -166,4 +137,46 @@ public class Portal extends MiniPlugin
addCommand(new ServerCommand(this));
addCommand(new SendCommand(this));
}
private void sendPlayer(final Player player, String serverName)
{
ByteArrayOutputStream b = new ByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(b);
try
{
out.writeUTF("Connect");
out.writeUTF(serverName);
}
catch (IOException e)
{
// Can never happen
}
finally
{
try
{
out.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
player.sendPluginMessage(GetPlugin(), "BungeeCord", b.toByteArray());
_connectingPlayers.add(player.getName());
GetScheduler().scheduleSyncDelayedTask(GetPlugin(), new Runnable()
{
public void run()
{
_connectingPlayers.remove(player.getName());
}
}, 20L);
UtilPlayer.message(
player,
F.main(getName(), "You have been sent to " + C.cGold + serverName));
}
}

View File

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

View File

@ -42,7 +42,7 @@ public class StatsManager extends MiniDbClientPlugin<PlayerStats>
}
};
plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, _saveRunnable, 1L, 1L);
plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, _saveRunnable, 20L, 20L);
}
for (Stat stat : _repository.retrieveStats())
@ -144,9 +144,6 @@ public class StatsManager extends MiniDbClientPlugin<PlayerStats>
}
statIterator.remove();
// Only process one player per tick/call.
break;
}
}

View File

@ -108,7 +108,7 @@ import mineplex.minecraft.game.core.damage.CustomDamageEvent;
public class HubManager extends MiniClientPlugin<HubClient>
{
// Snowman!
public HubType Type = HubType.Christmas;
public HubType Type = HubType.Normal;
private BlockRestore _blockRestore;
private CoreClientManager _clientManager;
@ -138,6 +138,7 @@ public class HubManager extends MiniClientPlugin<HubClient>
private HashMap<Player, Scoreboard> _scoreboards = new HashMap<Player, Scoreboard>();
private String _pigStacker = "0 - Nobody";
private String _serverName = "";
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[] { });
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<HubClient>
//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--);

View File

@ -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<Map<String, String>> response : serverDatas)
{
Map<String, String> 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)
@ -508,6 +503,35 @@ public class RedisServerRepository implements ServerRepository
}
}
@Override
public ServerGroup getServerGroup(String serverGroup)
{
ServerGroup server = null;
Jedis jedis = _jedisPool.getResource();
try
{
String key = concatenate("servergroups", serverGroup);
Map<String, String> data = jedis.hgetAll(key);
server = new ServerGroup(data, null);
}
catch (JedisConnectionException exception)
{
exception.printStackTrace();
_jedisPool.returnBrokenResource(jedis);
jedis = null;
}
finally
{
if (jedis != null)
{
_jedisPool.returnResource(jedis);
}
}
return server;
}
/*
* <region> = "US" or "EU"
* serverstatus.minecraft.<region>.<name> stores the JSON encoded information of an active MinecraftServer instance.

View File

@ -63,6 +63,8 @@ public interface ServerRepository
*/
public Collection<ServerGroup> getServerGroups(Collection<MinecraftServer> servers);
public ServerGroup getServerGroup(String serverGroup);
public Collection<MinecraftServer> getDeadServers();
void updateServerGroup(ServerGroup serverGroup);

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 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)

View File

@ -1,8 +1,13 @@
package nautilus.game.arcade.scoreboard;
import java.util.ArrayList;
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;
@ -11,298 +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<ScoreboardElement> _elements = new ArrayList<ScoreboardElement>();
private char[] _chars = "1234567890abcdefghijklmnopqrstuvwxyz".toCharArray();
private ArrayList<ScoreboardElement> _elements = new ArrayList<ScoreboardElement>();
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<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)
{
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<Integer> toAdd = new HashSet<Integer>();
HashSet<Integer> toDelete = new HashSet<Integer>();
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<String> newLines = new ArrayList<String>();
for (ScoreboardElement elem : _elements)
{
for (String line : elem.GetLines())
{
newLines.add(line);
}
}
int i = 0;
while (true)
{
if (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);
team.setPrefix(line.substring(0, Math.min(line.length(), 16)));
team.setSuffix(ChatColor.getLastColors(line) + line.substring(team.getPrefix().length()));
if (!score.isScoreSet())
{
if (i == 15)
{
score.setScore(1);
}
score.setScore(15 - i);
}
}
i++;
}
}
public void Reset()
{
_elements.clear();
}
public void Reset()
{
_elements.clear();
}
}