Allow dev servers

This commit is contained in:
samczsun 2016-09-07 11:44:49 -04:00
parent ba322f0df1
commit a8adf23c15
5 changed files with 183 additions and 71 deletions

View File

@ -1,6 +1,7 @@
package mineplex.hub.server; package mineplex.hub.server;
import mineplex.core.common.Rank; import mineplex.core.common.Rank;
import mineplex.serverdata.data.MinecraftServer;
public class ServerInfo public class ServerInfo
{ {
@ -12,9 +13,15 @@ public class ServerInfo
public String ServerType; public String ServerType;
public String Game; public String Game;
public Rank HostRank = Rank.ALL; public Rank HostRank = Rank.ALL;
public MinecraftServer Server;
public int getAvailableSlots() public int getAvailableSlots()
{ {
return MaxPlayers - CurrentPlayers; return MaxPlayers - CurrentPlayers;
} }
public boolean isDevServer()
{
return Name.contains("-Dev-");
}
} }

View File

@ -357,6 +357,7 @@ public class ServerManager extends MiniPlugin implements BrawlShopProvider
} }
ServerInfo serverInfo = _serverInfoMap.get(serverStatus.getName()); ServerInfo serverInfo = _serverInfoMap.get(serverStatus.getName());
serverInfo.Server = serverStatus;
serverInfo.MOTD = args.length > 0 ? args[0] : serverStatus.getMotd(); serverInfo.MOTD = args.length > 0 ? args[0] : serverStatus.getMotd();
serverInfo.CurrentPlayers = serverStatus.getPlayerCount(); serverInfo.CurrentPlayers = serverStatus.getPlayerCount();
serverInfo.MaxPlayers = serverStatus.getMaxPlayerCount(); serverInfo.MaxPlayers = serverStatus.getMaxPlayerCount();
@ -563,7 +564,10 @@ public class ServerManager extends MiniPlugin implements BrawlShopProvider
{ {
if (isInProgress(server)) if (isInProgress(server))
continue; continue;
if (server.isDevServer())
continue;
if (results.size() >= count) break; if (results.size() >= count) break;
if (server.getAvailableSlots() > requiredSlots) if (server.getAvailableSlots() > requiredSlots)

View File

@ -71,12 +71,20 @@ public class ServerSorter implements Comparator<ServerInfo>
if (b.CurrentPlayers > a.CurrentPlayers) if (b.CurrentPlayers > a.CurrentPlayers)
return 1; return 1;
if (Integer.parseInt(a.Name.split("-")[1]) < Integer.parseInt(b.Name.split("-")[1]))
return -1;
else if (Integer.parseInt(a.Name.split("-")[1]) > Integer.parseInt(b.Name.split("-")[1]))
return 1;
return 0; boolean isDevServerA = a.isDevServer();
boolean isDevServerB = b.isDevServer();
int serverIdA = Integer.parseInt(a.Name.substring(a.Name.lastIndexOf('-') + 1));
int serverIdB = Integer.parseInt(b.Name.substring(b.Name.lastIndexOf('-') + 1));
if (isDevServerA && isDevServerB)
return Integer.compare(serverIdA, serverIdB);
else if (isDevServerA)
return -1;
else if (isDevServerB)
return 1;
else
return Integer.compare(serverIdA, serverIdB);
} }
} }

View File

@ -3,7 +3,9 @@ package mineplex.hub.server.ui;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeUnit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
@ -28,6 +30,8 @@ import mineplex.hub.server.ui.button.JoinServerButton;
public class ServerNpcPage extends ShopPageInventory<ServerManager, ServerNpcShop> implements IServerPage public class ServerNpcPage extends ShopPageInventory<ServerManager, ServerNpcShop> implements IServerPage
{ {
private static final int MAX_FULL_SERVERS = 3;
// Shop Item Messages // Shop Item Messages
private static final String MESSAGE_BETA_GET_ULTRA = ChatColor.RESET + C.Line + "Get Ultra to join Tournament servers!"; private static final String MESSAGE_BETA_GET_ULTRA = ChatColor.RESET + C.Line + "Get Ultra to join Tournament servers!";
private static final String MESSAGE_JOIN = ChatColor.RESET + C.Line + "Click to Join"; private static final String MESSAGE_JOIN = ChatColor.RESET + C.Line + "Click to Join";
@ -43,10 +47,10 @@ public class ServerNpcPage extends ShopPageInventory<ServerManager, ServerNpcSho
private IButton[] _buttons; private IButton[] _buttons;
private ItemStack[] _items; private ItemStack[] _items;
public ServerNpcPage(ServerManager plugin, ServerNpcShop shop, CoreClientManager clientManager, DonationManager donationManager, String name, Player player, String serverGroupName) public ServerNpcPage(ServerManager plugin, ServerNpcShop shop, CoreClientManager clientManager, DonationManager donationManager, String name, Player player, String serverGroupName)
{ {
super(plugin, shop, clientManager, donationManager, name, player, 54); super(plugin, shop, clientManager, donationManager, name, player, 54);
_serverGroupName = serverGroupName; _serverGroupName = serverGroupName;
buildPage(); buildPage();
@ -86,7 +90,7 @@ public class ServerNpcPage extends ShopPageInventory<ServerManager, ServerNpcSho
} }
} }
private ShopItem buildShopItem(ServerInfo serverInfo, int slotsNeeded) private ShopItem buildShopItem(ServerInfo serverInfo, int slotsNeeded, boolean isDev)
{ {
boolean ownsUltraPackage = getDonationManager().Get(getPlayer()).OwnsUnknownPackage(serverInfo.ServerType + " ULTRA") || getClient().GetRank().has(Rank.ULTRA); boolean ownsUltraPackage = getDonationManager().Get(getPlayer()).OwnsUnknownPackage(serverInfo.ServerType + " ULTRA") || getClient().GetRank().has(Rank.ULTRA);
Material status = Material.REDSTONE_BLOCK; Material status = Material.REDSTONE_BLOCK;
@ -96,7 +100,7 @@ public class ServerNpcPage extends ShopPageInventory<ServerManager, ServerNpcSho
String wait = (serverInfo.Game == null || serverInfo.ServerType.equalsIgnoreCase("Competitive")) ? null : MESSAGE_WAIT; String wait = (serverInfo.Game == null || serverInfo.ServerType.equalsIgnoreCase("Competitive")) ? null : MESSAGE_WAIT;
if (isStarting(serverInfo) && (serverInfo.MaxPlayers - serverInfo.CurrentPlayers) >= slotsNeeded) if (isStarting(serverInfo) && (serverInfo.MaxPlayers - serverInfo.CurrentPlayers) >= slotsNeeded)
status = Material.EMERALD_BLOCK; status = isDev ? Material.COMMAND : Material.EMERALD_BLOCK;
else if (isInProgress(serverInfo)) else if (isInProgress(serverInfo))
status = Material.GOLD_BLOCK; status = Material.GOLD_BLOCK;
@ -106,7 +110,7 @@ public class ServerNpcPage extends ShopPageInventory<ServerManager, ServerNpcSho
lore.add(ChatColor.RESET + C.cYellow + "Game: " + C.cWhite + serverInfo.Game); lore.add(ChatColor.RESET + C.cYellow + "Game: " + C.cWhite + serverInfo.Game);
if (serverInfo.Map != null && !serverInfo.ServerType.equalsIgnoreCase("Competitive")) if (serverInfo.Map != null && !serverInfo.ServerType.equalsIgnoreCase("Competitive"))
lore.add(ChatColor.RESET + C.cYellow + "Map: " + C.cWhite + serverInfo.Map); lore.add(ChatColor.RESET + C.cYellow + "Map: " + C.cWhite + serverInfo.Map);
lore.add(ChatColor.RESET + C.cYellow + "Players: " + C.cWhite + serverInfo.CurrentPlayers + "/" + serverInfo.MaxPlayers); lore.add(ChatColor.RESET + C.cYellow + "Players: " + C.cWhite + serverInfo.CurrentPlayers + "/" + serverInfo.MaxPlayers);
lore.add(ChatColor.RESET + ""); lore.add(ChatColor.RESET + "");
@ -155,25 +159,42 @@ public class ServerNpcPage extends ShopPageInventory<ServerManager, ServerNpcSho
} }
else if (!serverInfo.MOTD.contains("Open in")) else if (!serverInfo.MOTD.contains("Open in"))
{ {
if (isDev)
{
lore.add(ChatColor.RESET + C.cRed + "Warning: This is a test server run by a developer");
lore.add(ChatColor.RESET + C.cRed + "It may contain unreleased updates");
}
lore.add(MESSAGE_JOIN); lore.add(MESSAGE_JOIN);
} }
} }
} }
return new ShopItem(status, ChatColor.RESET + C.cGreen + C.Line + C.Bold + "Server " + serverInfo.Name.split("-")[1], lore.toArray(new String[lore.size()]), serverInfo.CurrentPlayers, false); return new ShopItem(status, ChatColor.RESET + C.cGreen + C.Line + C.Bold + "Server " + serverInfo.Name.substring(serverInfo.Name.indexOf('-') + 1), lore.toArray(new String[lore.size()]), serverInfo.CurrentPlayers, false);
} }
private void buildAvailableServerPage(List<ServerInfo> serverList, int slotsNeeded) private void buildAvailableServerPage(List<ServerInfo> serverList, int slotsNeeded)
{ {
int serversToShow = 7; boolean hasDevServers = false;
int greenCount = 0;
int yellowCount = 0; for (Iterator<ServerInfo> iterator = serverList.iterator(); iterator.hasNext(); )
int maxFull = 3; {
int greenStartSlot = 18 + ((9 - serversToShow) / 2); ServerInfo serverInfo = iterator.next();
boolean showGreen = true; if (serverInfo.isDevServer())
{
if (TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - serverInfo.Server.getCurrentTime()) < 5)
{
hasDevServers = true;
break;
}
else
{
iterator.remove();
}
}
}
boolean privateServer = serverList.size() > 0 && serverList.get(0).ServerType.equals("Player"); boolean privateServer = serverList.size() > 0 && serverList.get(0).ServerType.equals("Player");
if (privateServer) if (privateServer)
{ {
int staffSlot = 0; int staffSlot = 0;
@ -202,71 +223,136 @@ public class ServerNpcPage extends ShopPageInventory<ServerManager, ServerNpcSho
} }
return; return;
} }
int fullCount = 0;
for (ServerInfo serverInfo : serverList) int gamesInProgress = 0;
if (!hasDevServers)
{ {
int slot = greenCount + greenStartSlot; int normalSlotStart = 19;
int normalSlotEnd = 25;
int currentNormalSlot = normalSlotStart;
int fullCount = 0;
if (isStarting(serverInfo) && hasEnoughSlots(serverInfo, slotsNeeded) && greenCount < serversToShow) for (ServerInfo serverInfo : serverList)
{ {
if (showGreen) if (isStarting(serverInfo) && hasEnoughSlots(serverInfo, slotsNeeded))
{ {
boolean full = serverInfo.MaxPlayers - serverInfo.CurrentPlayers <= 0; boolean full = serverInfo.MaxPlayers - serverInfo.CurrentPlayers <= 0;
if (full && fullCount >= maxFull)
continue;
ShopItem shopItem = buildShopItem(serverInfo, slotsNeeded);
greenCount++; if (full && fullCount >= MAX_FULL_SERVERS)
continue;
ShopItem shopItem = buildShopItem(serverInfo, slotsNeeded, false);
if (serverInfo.MOTD.contains("Open in")) if (serverInfo.MOTD.contains("Open in"))
addItemStack(slot, shopItem); addItemStack(currentNormalSlot, shopItem);
else else
{ addButton(currentNormalSlot, shopItem, new JoinServerButton(this, getPlugin(), serverInfo, getPlayer()));
addButton(slot, shopItem, new JoinServerButton(this, getPlugin(), serverInfo, getPlayer()));
}
if (full) if (full)
fullCount++; fullCount++;
currentNormalSlot++;
if (currentNormalSlot > normalSlotEnd)
break;
}
else if (isInProgress(serverInfo))
{
gamesInProgress++;
} }
} }
else if (isInProgress(serverInfo))
if (currentNormalSlot <= normalSlotEnd)
for (int i = currentNormalSlot; i <= normalSlotEnd; i++)
{
addItemStack(i, null);
}
}
else
{
int normalSlotStart = 10;
int normalSlotEnd = 16;
int currentNormalSlot = normalSlotStart;
int normalFullCount = 0;
int devSlotStart = 28;
int devSlotEnd = 34;
int currentDevSlot = devSlotStart;
int devFullCount = 0;
for (ServerInfo serverInfo : serverList)
{ {
yellowCount++; boolean isDevServer = serverInfo.isDevServer();
if (isStarting(serverInfo) && hasEnoughSlots(serverInfo, slotsNeeded))
{
if (isDevServer && currentDevSlot > devSlotEnd)
continue;
else if (!isDevServer && currentNormalSlot > normalSlotEnd)
continue;
boolean full = serverInfo.MaxPlayers - serverInfo.CurrentPlayers <= 0;
if (full)
{
if (isDevServer && devFullCount >= MAX_FULL_SERVERS)
continue;
else if (!isDevServer && normalFullCount >= MAX_FULL_SERVERS)
continue;
}
ShopItem shopItem = buildShopItem(serverInfo, slotsNeeded, isDevServer);
if (serverInfo.MOTD.contains("Open in"))
addItemStack(isDevServer ? currentDevSlot : currentNormalSlot, shopItem);
else
addButton(isDevServer ? currentDevSlot : currentNormalSlot, shopItem, new JoinServerButton(this, getPlugin(), serverInfo, getPlayer()));
if (full)
{
if (isDevServer)
devFullCount++;
else
normalFullCount++;
}
if (isDevServer)
currentDevSlot++;
else
currentNormalSlot++;
}
else if (isInProgress(serverInfo))
{
gamesInProgress++;
}
} }
if (currentNormalSlot <= normalSlotEnd)
for (int i = currentNormalSlot; i <= normalSlotEnd; i++)
{
addItemStack(i, null);
}
if (currentDevSlot <= devSlotEnd)
for (int i = currentDevSlot; i <= devSlotEnd; i++)
{
addItemStack(i, null);
}
} }
if (showGreen) addButton(40, new ShopItem(Material.GOLD_BLOCK, C.cAqua + gamesInProgress + " Game" + (gamesInProgress == 1 ? "" : "s") + " In Progress", new String[]{MESSAGE_SPECTATE}, gamesInProgress > 64 ? 64 : gamesInProgress, false), new IButton()
{ {
addButton(40, new ShopItem(Material.GOLD_BLOCK, C.cAqua + yellowCount + " Game" + (yellowCount == 1 ? "" : "s") + " In Progress", new String[]{MESSAGE_SPECTATE}, yellowCount > 64 ? 64 : yellowCount, false), new IButton() @Override
public void onClick(Player player, ClickType clickType)
{ {
@Override _onMainPage = false;
public void onClick(Player player, ClickType clickType)
{
_onMainPage = false;
}
});
addButton(4, ItemStackFactory.Instance.CreateStack(Material.DIAMOND_BLOCK, (byte) 0, 1, C.cGreen + "Click to join instantly!"), new IButton() {
@Override
public void onClick(Player player, ClickType clickType) {
getPlugin().selectServer(player, _serverGroupName);
}
});
}
// Clear empty slots
if (showGreen)
{
for (int i = greenCount + greenStartSlot; i < greenStartSlot + serversToShow; i++)
{
addItemStack(i, null);
} }
} });
addButton(4, ItemStackFactory.Instance.CreateStack(Material.DIAMOND_BLOCK, (byte) 0, 1, C.cGreen + "Click to join instantly!"), new IButton()
{
@Override
public void onClick(Player player, ClickType clickType)
{
getPlugin().selectServer(player, _serverGroupName);
}
});
} }
public void addItemStack(int slot, ItemStack item) public void addItemStack(int slot, ItemStack item)
@ -360,14 +446,14 @@ public class ServerNpcPage extends ShopPageInventory<ServerManager, ServerNpcSho
private void buildInProgressServerPage(List<ServerInfo> serverList, int slotsNeeded) private void buildInProgressServerPage(List<ServerInfo> serverList, int slotsNeeded)
{ {
int slot = 9; int slot = 9;
ArrayList<ServerInfo> inProgress = new ArrayList<ServerInfo>(); ArrayList<ServerInfo> inProgress = new ArrayList<ServerInfo>();
for (ServerInfo serverInfo : serverList) for (ServerInfo serverInfo : serverList)
{ {
if (isInProgress(serverInfo)) if (isInProgress(serverInfo))
{ {
ShopItem shopItem = buildShopItem(serverInfo, slotsNeeded); ShopItem shopItem = buildShopItem(serverInfo, slotsNeeded, false);
addButton(slot, shopItem, new JoinServerButton(this, getPlugin(), serverInfo, getPlayer())); addButton(slot, shopItem, new JoinServerButton(this, getPlugin(), serverInfo, getPlayer()));
inProgress.add(serverInfo); inProgress.add(serverInfo);
@ -382,20 +468,20 @@ public class ServerNpcPage extends ShopPageInventory<ServerManager, ServerNpcSho
slot += 9; slot += 9;
} }
ShopItem shopItem = buildShopItem(serverInfo, slotsNeeded); ShopItem shopItem = buildShopItem(serverInfo, slotsNeeded, false);
addButton(slot, shopItem, new JoinServerButton(this, getPlugin(), serverInfo, getPlayer())); addButton(slot, shopItem, new JoinServerButton(this, getPlugin(), serverInfo, getPlayer()));
slot++; slot++;
} }
addBackBed(4); addBackBed(4);
} }
private void addBackBed(int slot) private void addBackBed(int slot)
{ {
addButton(slot, new ShopItem(Material.BED, C.cGray + " \u21FD Go Back", new String[] addButton(slot, new ShopItem(Material.BED, C.cGray + " \u21FD Go Back", new String[]
{}, 1, false), new IButton() {}, 1, false), new IButton()
{ {
@Override @Override
public void onClick(Player player, ClickType clickType) public void onClick(Player player, ClickType clickType)
@ -416,13 +502,13 @@ public class ServerNpcPage extends ShopPageInventory<ServerManager, ServerNpcSho
{ {
System.out.println("Selecting server :" + serverInfo.Name); System.out.println("Selecting server :" + serverInfo.Name);
int slots = getPlugin().getRequiredSlots(player, serverInfo.ServerType); int slots = getPlugin().getRequiredSlots(player, serverInfo.ServerType);
if (serverInfo.getAvailableSlots() < slots && !(getDonationManager().Get(getPlayer()).OwnsUnknownPackage(serverInfo.ServerType + " ULTRA") || getClient().GetRank().has(Rank.ULTRA))) if (serverInfo.getAvailableSlots() < slots && !(getDonationManager().Get(getPlayer()).OwnsUnknownPackage(serverInfo.ServerType + " ULTRA") || getClient().GetRank().has(Rank.ULTRA)))
{ {
playDenySound(player); playDenySound(player);
return; return;
} }
getPlugin().selectServer(player, serverInfo); getPlugin().selectServer(player, serverInfo);
} }

View File

@ -47,6 +47,12 @@ public class MinecraftServer
public int getDonorsOnline() { return _donorsOnline; } public int getDonorsOnline() { return _donorsOnline; }
private long _startUpDate; private long _startUpDate;
private long _currentTime;
public long getCurrentTime()
{
return this._currentTime;
}
/** /**
* Class constructor * Class constructor
@ -76,6 +82,7 @@ public class MinecraftServer
_port = port; _port = port;
_donorsOnline = donorsOnline; _donorsOnline = donorsOnline;
_startUpDate = startUpDate; _startUpDate = startUpDate;
_currentTime = System.currentTimeMillis();
} }
/** /**