Allow dev servers
This commit is contained in:
parent
ba322f0df1
commit
a8adf23c15
@ -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-");
|
||||||
|
}
|
||||||
}
|
}
|
@ -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();
|
||||||
@ -564,6 +565,9 @@ 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)
|
||||||
|
@ -72,11 +72,19 @@ 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]))
|
boolean isDevServerA = a.isDevServer();
|
||||||
return -1;
|
boolean isDevServerB = b.isDevServer();
|
||||||
else if (Integer.parseInt(a.Name.split("-")[1]) > Integer.parseInt(b.Name.split("-")[1]))
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
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.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";
|
||||||
@ -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;
|
||||||
|
|
||||||
@ -155,22 +159,39 @@ 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");
|
||||||
|
|
||||||
@ -203,45 +224,119 @@ public class ServerNpcPage extends ShopPageInventory<ServerManager, ServerNpcSho
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int gamesInProgress = 0;
|
||||||
|
|
||||||
|
if (!hasDevServers)
|
||||||
|
{
|
||||||
|
int normalSlotStart = 19;
|
||||||
|
int normalSlotEnd = 25;
|
||||||
|
int currentNormalSlot = normalSlotStart;
|
||||||
int fullCount = 0;
|
int fullCount = 0;
|
||||||
|
|
||||||
for (ServerInfo serverInfo : serverList)
|
for (ServerInfo serverInfo : serverList)
|
||||||
{
|
{
|
||||||
int slot = greenCount + greenStartSlot;
|
if (isStarting(serverInfo) && hasEnoughSlots(serverInfo, slotsNeeded))
|
||||||
|
|
||||||
if (isStarting(serverInfo) && hasEnoughSlots(serverInfo, slotsNeeded) && greenCount < serversToShow)
|
|
||||||
{
|
|
||||||
if (showGreen)
|
|
||||||
{
|
{
|
||||||
boolean full = serverInfo.MaxPlayers - serverInfo.CurrentPlayers <= 0;
|
boolean full = serverInfo.MaxPlayers - serverInfo.CurrentPlayers <= 0;
|
||||||
|
|
||||||
if (full && fullCount >= maxFull)
|
if (full && fullCount >= MAX_FULL_SERVERS)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
ShopItem shopItem = buildShopItem(serverInfo, slotsNeeded);
|
ShopItem shopItem = buildShopItem(serverInfo, slotsNeeded, false);
|
||||||
|
|
||||||
greenCount++;
|
|
||||||
|
|
||||||
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))
|
else if (isInProgress(serverInfo))
|
||||||
{
|
{
|
||||||
yellowCount++;
|
gamesInProgress++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (showGreen)
|
if (currentNormalSlot <= normalSlotEnd)
|
||||||
|
for (int i = currentNormalSlot; i <= normalSlotEnd; i++)
|
||||||
{
|
{
|
||||||
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()
|
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
|
@Override
|
||||||
public void onClick(Player player, ClickType clickType)
|
public void onClick(Player player, ClickType clickType)
|
||||||
@ -250,25 +345,16 @@ public class ServerNpcPage extends ShopPageInventory<ServerManager, ServerNpcSho
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
addButton(4, ItemStackFactory.Instance.CreateStack(Material.DIAMOND_BLOCK, (byte) 0, 1, C.cGreen + "Click to join instantly!"), new IButton() {
|
addButton(4, ItemStackFactory.Instance.CreateStack(Material.DIAMOND_BLOCK, (byte) 0, 1, C.cGreen + "Click to join instantly!"), new IButton()
|
||||||
|
{
|
||||||
@Override
|
@Override
|
||||||
public void onClick(Player player, ClickType clickType) {
|
public void onClick(Player player, ClickType clickType)
|
||||||
|
{
|
||||||
getPlugin().selectServer(player, _serverGroupName);
|
getPlugin().selectServer(player, _serverGroupName);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clear empty slots
|
|
||||||
if (showGreen)
|
|
||||||
{
|
|
||||||
for (int i = greenCount + greenStartSlot; i < greenStartSlot + serversToShow; i++)
|
|
||||||
{
|
|
||||||
addItemStack(i, null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addItemStack(int slot, ItemStack item)
|
public void addItemStack(int slot, ItemStack item)
|
||||||
{
|
{
|
||||||
if (_items.length <= slot)
|
if (_items.length <= slot)
|
||||||
@ -367,7 +453,7 @@ public class ServerNpcPage extends ShopPageInventory<ServerManager, ServerNpcSho
|
|||||||
{
|
{
|
||||||
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,7 +468,7 @@ 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()));
|
||||||
|
|
||||||
|
@ -48,6 +48,12 @@ public class MinecraftServer
|
|||||||
|
|
||||||
private long _startUpDate;
|
private long _startUpDate;
|
||||||
|
|
||||||
|
private long _currentTime;
|
||||||
|
public long getCurrentTime()
|
||||||
|
{
|
||||||
|
return this._currentTime;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class constructor
|
* Class constructor
|
||||||
* @param name
|
* @param name
|
||||||
@ -76,6 +82,7 @@ public class MinecraftServer
|
|||||||
_port = port;
|
_port = port;
|
||||||
_donorsOnline = donorsOnline;
|
_donorsOnline = donorsOnline;
|
||||||
_startUpDate = startUpDate;
|
_startUpDate = startUpDate;
|
||||||
|
_currentTime = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user