Allow dev servers
This commit is contained in:
parent
ba322f0df1
commit
a8adf23c15
@ -1,6 +1,7 @@
|
||||
package mineplex.hub.server;
|
||||
|
||||
import mineplex.core.common.Rank;
|
||||
import mineplex.serverdata.data.MinecraftServer;
|
||||
|
||||
public class ServerInfo
|
||||
{
|
||||
@ -12,9 +13,15 @@ public class ServerInfo
|
||||
public String ServerType;
|
||||
public String Game;
|
||||
public Rank HostRank = Rank.ALL;
|
||||
public MinecraftServer Server;
|
||||
|
||||
public int getAvailableSlots()
|
||||
{
|
||||
return MaxPlayers - CurrentPlayers;
|
||||
}
|
||||
|
||||
public boolean isDevServer()
|
||||
{
|
||||
return Name.contains("-Dev-");
|
||||
}
|
||||
}
|
@ -357,6 +357,7 @@ public class ServerManager extends MiniPlugin implements BrawlShopProvider
|
||||
}
|
||||
|
||||
ServerInfo serverInfo = _serverInfoMap.get(serverStatus.getName());
|
||||
serverInfo.Server = serverStatus;
|
||||
serverInfo.MOTD = args.length > 0 ? args[0] : serverStatus.getMotd();
|
||||
serverInfo.CurrentPlayers = serverStatus.getPlayerCount();
|
||||
serverInfo.MaxPlayers = serverStatus.getMaxPlayerCount();
|
||||
@ -564,6 +565,9 @@ public class ServerManager extends MiniPlugin implements BrawlShopProvider
|
||||
if (isInProgress(server))
|
||||
continue;
|
||||
|
||||
if (server.isDevServer())
|
||||
continue;
|
||||
|
||||
if (results.size() >= count) break;
|
||||
|
||||
if (server.getAvailableSlots() > requiredSlots)
|
||||
|
@ -72,11 +72,19 @@ public class ServerSorter implements Comparator<ServerInfo>
|
||||
if (b.CurrentPlayers > a.CurrentPlayers)
|
||||
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;
|
||||
boolean isDevServerA = a.isDevServer();
|
||||
boolean isDevServerB = b.isDevServer();
|
||||
|
||||
return 0;
|
||||
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);
|
||||
}
|
||||
}
|
@ -3,7 +3,9 @@ package mineplex.hub.server.ui;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
@ -28,6 +30,8 @@ import mineplex.hub.server.ui.button.JoinServerButton;
|
||||
|
||||
public class ServerNpcPage extends ShopPageInventory<ServerManager, ServerNpcShop> implements IServerPage
|
||||
{
|
||||
private static final int MAX_FULL_SERVERS = 3;
|
||||
|
||||
// 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_JOIN = ChatColor.RESET + C.Line + "Click to Join";
|
||||
@ -43,7 +47,7 @@ public class ServerNpcPage extends ShopPageInventory<ServerManager, ServerNpcSho
|
||||
private IButton[] _buttons;
|
||||
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);
|
||||
|
||||
@ -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);
|
||||
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;
|
||||
|
||||
if (isStarting(serverInfo) && (serverInfo.MaxPlayers - serverInfo.CurrentPlayers) >= slotsNeeded)
|
||||
status = Material.EMERALD_BLOCK;
|
||||
status = isDev ? Material.COMMAND : Material.EMERALD_BLOCK;
|
||||
else if (isInProgress(serverInfo))
|
||||
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);
|
||||
|
||||
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 + "");
|
||||
@ -155,22 +159,39 @@ public class ServerNpcPage extends ShopPageInventory<ServerManager, ServerNpcSho
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
int serversToShow = 7;
|
||||
int greenCount = 0;
|
||||
int yellowCount = 0;
|
||||
int maxFull = 3;
|
||||
int greenStartSlot = 18 + ((9 - serversToShow) / 2);
|
||||
boolean showGreen = true;
|
||||
boolean hasDevServers = false;
|
||||
|
||||
for (Iterator<ServerInfo> iterator = serverList.iterator(); iterator.hasNext(); )
|
||||
{
|
||||
ServerInfo serverInfo = iterator.next();
|
||||
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");
|
||||
|
||||
@ -203,70 +224,135 @@ public class ServerNpcPage extends ShopPageInventory<ServerManager, ServerNpcSho
|
||||
return;
|
||||
}
|
||||
|
||||
int fullCount = 0;
|
||||
int gamesInProgress = 0;
|
||||
|
||||
for (ServerInfo serverInfo : serverList)
|
||||
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;
|
||||
|
||||
if (full && fullCount >= maxFull)
|
||||
if (full && fullCount >= MAX_FULL_SERVERS)
|
||||
continue;
|
||||
|
||||
ShopItem shopItem = buildShopItem(serverInfo, slotsNeeded);
|
||||
|
||||
greenCount++;
|
||||
ShopItem shopItem = buildShopItem(serverInfo, slotsNeeded, false);
|
||||
|
||||
if (serverInfo.MOTD.contains("Open in"))
|
||||
addItemStack(slot, shopItem);
|
||||
addItemStack(currentNormalSlot, shopItem);
|
||||
else
|
||||
{
|
||||
addButton(slot, shopItem, new JoinServerButton(this, getPlugin(), serverInfo, getPlayer()));
|
||||
}
|
||||
addButton(currentNormalSlot, shopItem, new JoinServerButton(this, getPlugin(), serverInfo, getPlayer()));
|
||||
|
||||
if (full)
|
||||
fullCount++;
|
||||
}
|
||||
}
|
||||
else if (isInProgress(serverInfo))
|
||||
{
|
||||
yellowCount++;
|
||||
}
|
||||
}
|
||||
|
||||
if (showGreen)
|
||||
{
|
||||
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)
|
||||
currentNormalSlot++;
|
||||
if (currentNormalSlot > normalSlotEnd)
|
||||
break;
|
||||
}
|
||||
else if (isInProgress(serverInfo))
|
||||
{
|
||||
_onMainPage = false;
|
||||
gamesInProgress++;
|
||||
}
|
||||
});
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
@Override
|
||||
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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void addItemStack(int slot, ItemStack item)
|
||||
@ -367,7 +453,7 @@ public class ServerNpcPage extends ShopPageInventory<ServerManager, ServerNpcSho
|
||||
{
|
||||
if (isInProgress(serverInfo))
|
||||
{
|
||||
ShopItem shopItem = buildShopItem(serverInfo, slotsNeeded);
|
||||
ShopItem shopItem = buildShopItem(serverInfo, slotsNeeded, false);
|
||||
|
||||
addButton(slot, shopItem, new JoinServerButton(this, getPlugin(), serverInfo, getPlayer()));
|
||||
inProgress.add(serverInfo);
|
||||
@ -382,7 +468,7 @@ public class ServerNpcPage extends ShopPageInventory<ServerManager, ServerNpcSho
|
||||
slot += 9;
|
||||
}
|
||||
|
||||
ShopItem shopItem = buildShopItem(serverInfo, slotsNeeded);
|
||||
ShopItem shopItem = buildShopItem(serverInfo, slotsNeeded, false);
|
||||
|
||||
addButton(slot, shopItem, new JoinServerButton(this, getPlugin(), serverInfo, getPlayer()));
|
||||
|
||||
@ -395,7 +481,7 @@ public class ServerNpcPage extends ShopPageInventory<ServerManager, ServerNpcSho
|
||||
private void addBackBed(int slot)
|
||||
{
|
||||
addButton(slot, new ShopItem(Material.BED, C.cGray + " \u21FD Go Back", new String[]
|
||||
{}, 1, false), new IButton()
|
||||
{}, 1, false), new IButton()
|
||||
{
|
||||
@Override
|
||||
public void onClick(Player player, ClickType clickType)
|
||||
|
@ -48,6 +48,12 @@ public class MinecraftServer
|
||||
|
||||
private long _startUpDate;
|
||||
|
||||
private long _currentTime;
|
||||
public long getCurrentTime()
|
||||
{
|
||||
return this._currentTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
* @param name
|
||||
@ -76,6 +82,7 @@ public class MinecraftServer
|
||||
_port = port;
|
||||
_donorsOnline = donorsOnline;
|
||||
_startUpDate = startUpDate;
|
||||
_currentTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user