From a8adf23c155a268e5ebb486c55a812886e248c57 Mon Sep 17 00:00:00 2001 From: samczsun Date: Wed, 7 Sep 2016 11:44:49 -0400 Subject: [PATCH] Allow dev servers --- .../src/mineplex/hub/server/ServerInfo.java | 7 + .../mineplex/hub/server/ServerManager.java | 6 +- .../src/mineplex/hub/server/ServerSorter.java | 20 +- .../mineplex/hub/server/ui/ServerNpcPage.java | 214 ++++++++++++------ .../serverdata/data/MinecraftServer.java | 7 + 5 files changed, 183 insertions(+), 71 deletions(-) diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerInfo.java b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerInfo.java index f3ebc2e5d..eee657553 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerInfo.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerInfo.java @@ -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-"); + } } \ No newline at end of file diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerManager.java index f13a54a49..42bd4837a 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerManager.java @@ -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(); @@ -563,7 +564,10 @@ public class ServerManager extends MiniPlugin implements BrawlShopProvider { if (isInProgress(server)) continue; - + + if (server.isDevServer()) + continue; + if (results.size() >= count) break; if (server.getAvailableSlots() > requiredSlots) diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerSorter.java b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerSorter.java index 325ae80c6..95286de67 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerSorter.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerSorter.java @@ -71,12 +71,20 @@ public class ServerSorter implements Comparator 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; - 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); } } \ No newline at end of file diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/ServerNpcPage.java b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/ServerNpcPage.java index 4ef6c301e..f6f42dee1 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/ServerNpcPage.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/ServerNpcPage.java @@ -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 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,10 +47,10 @@ public class ServerNpcPage extends ShopPageInventory= 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 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 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"); - + if (privateServer) { int staffSlot = 0; @@ -202,71 +223,136 @@ public class ServerNpcPage extends ShopPageInventory= 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")) - 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++; + + 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 - 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); + _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) @@ -360,14 +446,14 @@ public class ServerNpcPage extends ShopPageInventory serverList, int slotsNeeded) { int slot = 9; - + ArrayList inProgress = new ArrayList(); for (ServerInfo serverInfo : serverList) { 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,20 +468,20 @@ public class ServerNpcPage extends ShopPageInventory