diff --git a/Plugins/Mineplex.Core/src/mineplex/core/portal/Commands/ServerCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/portal/Commands/ServerCommand.java index f74bb2b99..176506241 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/portal/Commands/ServerCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/portal/Commands/ServerCommand.java @@ -2,7 +2,7 @@ package mineplex.core.portal.Commands; import org.bukkit.entity.Player; -import mineplex.core.command.*; +import mineplex.core.command.CommandBase; import mineplex.core.common.Rank; import mineplex.core.common.util.C; import mineplex.core.common.util.Callback; @@ -84,6 +84,13 @@ public class ServerCommand extends CommandBase else deniedAccess = true; } + else if (!servUp.contains("FREE")) + { + if (playerRank.Has(Rank.ULTRA)) + Plugin.SendPlayerToServerWithMessage(player, args[0]); + else + deniedAccess = true; + } else { Plugin.SendPlayerToServerWithMessage(player, args[0]); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/shop/item/SingleButton.java b/Plugins/Mineplex.Core/src/mineplex/core/shop/item/SingleButton.java new file mode 100644 index 000000000..9ac844a6c --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/shop/item/SingleButton.java @@ -0,0 +1,19 @@ +package mineplex.core.shop.item; + +import org.bukkit.entity.Player; + +public abstract class SingleButton implements IButton +{ + public abstract void Clicked(Player player); + + public void ClickedLeft(Player player) + { + Clicked(player); + } + + public void ClickedRight(Player player) + { + Clicked(player); + } + +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerInfo.java b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerInfo.java index 688cc034a..07f1f4fd6 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerInfo.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerInfo.java @@ -9,4 +9,9 @@ public class ServerInfo public String Map; public String ServerType; public String Game; + + public boolean isFree() + { + return Name.contains("FREE"); + } } \ 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 a28b4daa6..40e537be1 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerManager.java @@ -5,6 +5,7 @@ import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; +import java.time.Duration; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -12,7 +13,6 @@ import java.util.HashSet; import java.util.List; import java.util.Set; -import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.Sound; @@ -25,6 +25,7 @@ import org.bukkit.event.entity.EntityPortalEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerPortalEvent; +import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.util.Vector; @@ -62,6 +63,8 @@ import mineplex.hub.server.ui.ServerNpcShop; public class ServerManager extends MiniPlugin { + private static final Long FREE_PORTAL_TIMER = Duration.ofSeconds(60).toMillis(); + private CoreClientManager _clientManager; private DonationManager _donationManager; private Portal _portal; @@ -78,6 +81,9 @@ public class ServerManager extends MiniPlugin private NautHashMap _serverUpdate = new NautHashMap(); private NautHashMap _serverPortalLocations = new NautHashMap(); + // Join Time for Free Players Timer + private NautHashMap _freeJoinTime = new NautHashMap(); + private QueueShop _domShop; private QuickShop _quickShop; private LobbyShop _lobbyShop; @@ -131,16 +137,39 @@ public class ServerManager extends MiniPlugin return; } - Player player = (Player)event.getEntity(); - - if (!_hubManager.CanPortal(player)) - { - UtilAction.velocity(player, UtilAlg.getTrajectory(player.getLocation(), _hubManager.GetSpawn()), 1, true, 0.8, 0, 1, true); - return; - } - + final Player player = (Player)event.getEntity(); + if (!Recharge.Instance.use(player, "Portal Server", 1000, false, false)) return; + + long timeUntilPortal = getMillisecondsUntilPortal(player); + if (!_hubManager.CanPortal(player) || timeUntilPortal > 0) + { + if (timeUntilPortal > 0) + { + player.playSound(player.getEyeLocation(), Sound.CHICKEN_EGG_POP, 2, 2); + UtilPlayer.message(player, F.main("Server Portal", "You cannot join a server for " + C.cGreen + UtilTime.convertString(timeUntilPortal, 0, TimeUnit.SECONDS))); + } + + UtilAction.velocity(player, UtilAlg.getTrajectory(player.getLocation(), _hubManager.GetSpawn()), 1.5, true, 0.8, 0, 1.0, true); + + // Need to set their velocity again a tick later + // Setting Y-Velocity while in a portal doesn't seem to do anything... Science! + _plugin.getServer().getScheduler().runTask(_plugin, new Runnable() + { + + @Override + public void run() + { + if (player != null && player.isOnline()) + { + UtilAction.velocity(player, UtilAlg.getTrajectory(player.getLocation(), _hubManager.GetSpawn()), 1, true, 0.5, 0, 1.0, true); + } + } + }); + + return; + } String serverName = _serverPortalLocations.get(player.getLocation().getBlock().getLocation().toVector()); @@ -158,11 +187,16 @@ public class ServerManager extends MiniPlugin try { Collections.sort(serverList, new ServerSorter(slots)); + boolean hasUltra = _clientManager.Get(player).GetRank().Has(Rank.ULTRA); for (ServerInfo serverInfo : serverList) { if ((serverInfo.MOTD.contains("Starting") || serverInfo.MOTD.contains("Recruiting") || serverInfo.MOTD.contains("Waiting") || serverInfo.MOTD.contains("Cup")) && (serverInfo.MaxPlayers - serverInfo.CurrentPlayers) >= slots) { + // Make sure ultra players get put on premium servers, non premium gets placed on free servers + if (hasUltra == serverInfo.isFree()) + continue; + SelectServer(player, serverInfo); return; } @@ -174,7 +208,7 @@ public class ServerManager extends MiniPlugin exception.printStackTrace(); } - player.sendMessage(F.main("Server Portal", "There are currently no joinable servers!")); + UtilPlayer.message(player, F.main("Server Portal", "There are currently no joinable servers!")); } } @@ -208,6 +242,17 @@ public class ServerManager extends MiniPlugin { event.getPlayer().getInventory().addItem(ItemStackFactory.Instance.CreateStack(Material.COMPASS.getId(), (byte)0, 1, ChatColor.GREEN + "Game Menu")); event.getPlayer().getInventory().addItem(ItemStackFactory.Instance.CreateStack(Material.WATCH.getId(), (byte)0, 1, ChatColor.GREEN + "Lobby Menu")); + + if (_clientManager.Get(event.getPlayer()).GetRank() == Rank.ALL) + { + _freeJoinTime.put(event.getPlayer().getName(), System.currentTimeMillis()); + } + } + + @EventHandler + public void playerQuit(PlayerQuitEvent event) + { + _freeJoinTime.remove(event.getPlayer().getName()); } @EventHandler(priority = EventPriority.LOWEST) @@ -222,6 +267,36 @@ public class ServerManager extends MiniPlugin _lobbyShop.attemptShopOpen(event.getPlayer()); } } + + public Long getMillisecondsUntilPortal(Player player) + { +// Party party = _partyManager.GetParty(player); + long timeLeft = 0; + + if (_freeJoinTime.containsKey(player.getName())) + { + timeLeft = (_freeJoinTime.get(player.getName()) - System.currentTimeMillis()) + FREE_PORTAL_TIMER; + if (timeLeft <= 0) + { + _freeJoinTime.remove(player.getName()); + timeLeft = 0; + } + } + +// if (party != null) +// { +// if (player.getName().equals(party.GetLeader())) +// { +// for (Player partyPlayer : party.GetPlayersOnline()) +// { +// if (!partyPlayer.equals(player)) +// timeLeft = Math.max(timeLeft, getMillisecondsUntilPortal(partyPlayer)); +// } +// } +// } + + return timeLeft; + } public void RemoveServer(String serverName) { 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 045587ab8..66fed0f7f 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/ServerNpcPage.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/ServerNpcPage.java @@ -4,189 +4,340 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.entity.Player; + import mineplex.core.account.CoreClientManager; import mineplex.core.common.Rank; import mineplex.core.common.util.C; -import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilTime; import mineplex.core.donation.DonationManager; import mineplex.core.logger.Logger; import mineplex.core.shop.item.ShopItem; +import mineplex.core.shop.item.SingleButton; import mineplex.core.shop.page.ShopPageBase; import mineplex.hub.server.ServerInfo; import mineplex.hub.server.ServerManager; import mineplex.hub.server.ServerSorter; import mineplex.hub.server.ui.button.JoinServerButton; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.entity.Player; - public class ServerNpcPage extends ShopPageBase implements IServerPage { + // Shop Item Messages + private static final String MESSAGE_SHOP_URL = ChatColor.RESET + "www.mineplex.com/shop"; + private static final String MESSAGE_REQUIRES_PREMIUM = ChatColor.RESET + C.cRed + "Premium requires " + Rank.ULTRA.GetTag(false, false) + C.cRed + " or " + Rank.HERO.GetTag(false, false); + private static final String MESSAGE_BETA_GET_ULTRA = ChatColor.RESET + C.Line + "Get Ultra to join Beta servers!"; + private static final String MESSAGE_JOIN = ChatColor.RESET + C.Line + "Click to Join"; + private static final String MESSAGE_IN_PROGRESS = ChatColor.RESET + C.Line + "Game in Progress."; + private static final String MESSAGE_SPECTATE = ChatColor.RESET + C.Line + "Click to Spectate"; + private static final String MESSAGE_WAIT = ChatColor.RESET + C.Line + "and wait for next game!"; + private static final String MESSAGE_FULL_GET_ULTRA = ChatColor.RESET + C.Line + "Get Ultra to join full servers!"; + private static final String MESSAGE_RESTARTING = ChatColor.RESET + C.Line + "This server will be open shortly!"; + private String _serverNpcKey; + private boolean _onMainPage = true; + private boolean _freeOnly; public ServerNpcPage(ServerManager plugin, ServerNpcShop shop, CoreClientManager clientManager, DonationManager donationManager, String name, Player player, String serverNpcKey) { super(plugin, shop, clientManager, donationManager, name, player, 54); _serverNpcKey = serverNpcKey; - + BuildPage(); } @Override protected void BuildPage() - { + { List serverList = new ArrayList(Plugin.GetServerList(_serverNpcKey)); - - int slots = 1; - + int slotsNeeded = 1; + if (serverList.size() > 0) { - slots = Plugin.GetRequiredSlots(Player, serverList.get(0).ServerType); + slotsNeeded = Plugin.GetRequiredSlots(Player, serverList.get(0).ServerType); } try { - Collections.sort(serverList, new ServerSorter(slots)); + Collections.sort(serverList, new ServerSorter(slotsNeeded)); } catch (Exception exception) { Logger.Instance.log(exception); exception.printStackTrace(); } - - int slot = 10; - int greenCount = 0; - int yellowCount = 0; - String openFull = ChatColor.RESET + C.Line + "Get Ultra to join full servers!"; - String beta = ChatColor.RESET + C.Line + "Get Ultra to join Beta servers!"; - String openFullUltra = ChatColor.RESET + C.Line + "Click to join!"; - - for (ServerInfo serverInfo : serverList) + + + if (_onMainPage) { - boolean ownsUltraPackage = DonationManager.Get(Player.getName()).OwnsUnknownPackage(serverInfo.ServerType + " ULTRA") || Client.GetRank().Has(Rank.ULTRA); - - String inProgress = (serverInfo.Game == null || serverInfo.ServerType.equalsIgnoreCase("Competitive")) ? (ChatColor.RESET + C.Line + "Game in progress.") : (ChatColor.RESET + C.Line + "Click to spectate"); - String inProgressLine2 = (serverInfo.Game == null || serverInfo.ServerType.equalsIgnoreCase("Competitive")) ? null : (ChatColor.RESET + C.Line + "and wait for next game!"); - - Material status = Material.REDSTONE_BLOCK; - List lore = new ArrayList(); - - if (slot >= 53) - break; - - if ((serverInfo.MOTD.contains("Starting") || serverInfo.MOTD.contains("Recruiting") || serverInfo.MOTD.contains("Waiting") || serverInfo.MOTD.contains("Cup")) && slot < 15 && (serverInfo.MaxPlayers - serverInfo.CurrentPlayers) >= slots) + buildAvailableServerPage(serverList, slotsNeeded); + } + else + { + buildInProgressServerPage(serverList, _freeOnly, slotsNeeded); + } + } + + private void showClock(long milliseconds) + { + int seconds = (int) (milliseconds / 1000); + String timeLeft = UtilTime.convertString(milliseconds, 0, UtilTime.TimeUnit.SECONDS); + + byte data = (byte) (milliseconds - (seconds * 1000) > 500 ? 15 : 14); + + ShopItem item = new ShopItem(Material.WOOL, data, ChatColor.RESET + C.Bold + "Free Server Timer", null, new String[] { + ChatColor.RESET + C.cGreen + timeLeft + " Remaining...", + ChatColor.RESET + "", + ChatColor.RESET + C.cYellow + "Free players must wait a short time", + ChatColor.RESET + C.cYellow + "to help lighten the load on our servers.", + ChatColor.RESET + "", + ChatColor.RESET + C.cAqua + "Ultra and Hero players have instant", + ChatColor.RESET + C.cAqua + "access to free and premium servers!", + ChatColor.RESET + "", + ChatColor.RESET + "Visit " + C.cGreen + "www.mineplex.com/shop" + C.cWhite + " for Premium!" + }, seconds, false, false); + + AddItem(20, item); + } + + private void clearPage() + { + for (int i = 0; i < getSize(); i++) + { + setItem(i, null); + } + } + + private ShopItem buildShopItem(ServerInfo serverInfo, int slotsNeeded) + { + boolean ownsUltraPackage = DonationManager.Get(Player.getName()).OwnsUnknownPackage(serverInfo.ServerType + " ULTRA") || Client.GetRank().Has(Rank.ULTRA); + Material status = Material.REDSTONE_BLOCK; + boolean free = serverInfo.isFree(); + List lore = new ArrayList(); + + String inProgress = (serverInfo.Game == null || serverInfo.ServerType.equalsIgnoreCase("Competitive")) ? MESSAGE_IN_PROGRESS : MESSAGE_SPECTATE; + String wait = (serverInfo.Game == null || serverInfo.ServerType.equalsIgnoreCase("Competitive")) ? null : MESSAGE_WAIT; + + if (isStarting(serverInfo) && (serverInfo.MaxPlayers - serverInfo.CurrentPlayers) >= slotsNeeded) + status = free ? Material.EMERALD_BLOCK : Material.DIAMOND_BLOCK; + else if (isInProgress(serverInfo)) + status = Material.GOLD_BLOCK; + + lore.add(ChatColor.RESET + ""); + + if (serverInfo.Game != null) + 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 + "Players: " + C.cWhite + serverInfo.CurrentPlayers + "/" + serverInfo.MaxPlayers); + lore.add(ChatColor.RESET + ""); + + // Only show motd if the player has access + if (free || ownsUltraPackage) + lore.add(ChatColor.RESET + serverInfo.MOTD); + + if (serverInfo.Name.contains("BETA") && !ownsUltraPackage) + { + lore.add(MESSAGE_BETA_GET_ULTRA); + } + else + { + if (isInProgress(serverInfo)) { - if (greenCount > 0 && serverInfo.MaxPlayers == serverInfo.CurrentPlayers) - continue; - - slot += 1; - status = Material.EMERALD_BLOCK; - lore.add(ChatColor.RESET + ""); - - if (serverInfo.Game != null) - lore.add(ChatColor.RESET + "" + ChatColor.YELLOW + "Game: " + ChatColor.WHITE + serverInfo.Game); - - if (serverInfo.Map != null && !serverInfo.ServerType.equalsIgnoreCase("Competitive")) - lore.add(ChatColor.RESET + "" + ChatColor.YELLOW + "Map: " + ChatColor.WHITE + serverInfo.Map); - - lore.add(ChatColor.RESET + "" + ChatColor.YELLOW + "Players: " + ChatColor.WHITE + serverInfo.CurrentPlayers + "/" + serverInfo.MaxPlayers); - lore.add(ChatColor.RESET + ""); - lore.add(ChatColor.RESET + serverInfo.MOTD); - - if (serverInfo.Name.contains("BETA") && !ownsUltraPackage) + if (serverInfo.MOTD.contains("Restarting")) { - lore.add(beta); + status = Material.IRON_BLOCK; + lore.add(MESSAGE_RESTARTING); } else { - if (serverInfo.CurrentPlayers >= serverInfo.MaxPlayers) + if (serverInfo.Game.equalsIgnoreCase("Survival Games")) { - if (serverInfo.Game.equalsIgnoreCase("Survival Games")) + lore.add(ChatColor.RESET + C.Line + "Full Survival Games servers"); + lore.add(ChatColor.RESET + C.Line + "cannot be joined."); + } + else + { + if (!ownsUltraPackage) { - lore.add(ChatColor.RESET + C.Line + "Full Survival Games servers"); - lore.add(ChatColor.RESET + C.Line + "cannot be joined."); + if (free) + lore.add(MESSAGE_FULL_GET_ULTRA); + else + { + lore.add(MESSAGE_REQUIRES_PREMIUM); + lore.add(MESSAGE_SHOP_URL); + } } else { - if (!ownsUltraPackage) - lore.add(openFull); - else - lore.add(openFullUltra); + lore.add(inProgress); + if (wait != null) + lore.add(wait); } } - else - { - lore.add(ChatColor.RESET + C.Line + "Click to join!"); - } } - - greenCount++; - } - else if (serverInfo.MOTD.contains("In") || serverInfo.MOTD.contains("Restarting")) - { - if (slot <= 15) - slot = 27; - else - slot++; - - status = Material.GOLD_BLOCK; - lore.add(ChatColor.RESET + ""); - - if (serverInfo.Game != null) - lore.add(ChatColor.RESET + "" + ChatColor.YELLOW + "Game: " + ChatColor.WHITE + serverInfo.Game); - - if (serverInfo.Map != null && !serverInfo.ServerType.equalsIgnoreCase("Competitive")) - lore.add(ChatColor.RESET + "" + ChatColor.YELLOW + "Map: " + ChatColor.WHITE + serverInfo.Map); - - lore.add(ChatColor.RESET + "" + ChatColor.YELLOW + "Players: " + ChatColor.WHITE + serverInfo.CurrentPlayers + "/" + serverInfo.MaxPlayers); - lore.add(ChatColor.RESET + ""); - lore.add(ChatColor.RESET + serverInfo.MOTD); - - if (serverInfo.MOTD.contains("Restarting")) - { - lore.add(ChatColor.RESET + C.Line + "This server will be open shortly!"); - status = Material.IRON_BLOCK; - } - else if (serverInfo.CurrentPlayers >= serverInfo.MaxPlayers) - { - if (!Client.GetRank().Has(Rank.ULTRA) || ownsUltraPackage) - lore.add(openFull); - else - { - lore.add(inProgress); - - if (inProgressLine2 != null) - lore.add(inProgressLine2); - } - } - else - { - lore.add(inProgress); - - if (inProgressLine2 != null) - lore.add(inProgressLine2); - } - - yellowCount++; } else - continue; - - AddButton(slot, new ShopItem(status, ChatColor.UNDERLINE + "" + ChatColor.BOLD + "" + ChatColor.WHITE + "Server " + serverInfo.Name.substring(serverInfo.Name.indexOf('-') + 1), lore.toArray(new String[lore.size()]), Math.max(1, serverInfo.CurrentPlayers), false), new JoinServerButton(this, serverInfo)); + { + if (free || ownsUltraPackage) + { + if (serverInfo.CurrentPlayers >= serverInfo.MaxPlayers && !ownsUltraPackage) + { + lore.add(MESSAGE_FULL_GET_ULTRA); + } + else + { + lore.add(MESSAGE_JOIN); + } + } + else + { + lore.add(MESSAGE_REQUIRES_PREMIUM); + lore.add(MESSAGE_SHOP_URL); + } + } } - - while (greenCount < 3) + + return new ShopItem(status, ChatColor.RESET + C.Line + C.Bold + (free ? C.cGreen + "Free Server " : C.cAqua + "Premium Server ") + serverInfo.Name.split("-")[1], lore.toArray(new String[lore.size()]), serverInfo.CurrentPlayers, false); + } + + private void buildAvailableServerPage(List serverList, int slotsNeeded) + { + int greenCount = 0; + int blueCount = 0; + int yellowFreeCount = 0; + int yellowUltraCount = 0; + int greenStartSlot = 19; + int blueStartSlot = 23; + boolean showGreen = true; + + long portalTime = Plugin.getMillisecondsUntilPortal(Player); + if (portalTime > 0) { - setItem(9 + ((greenCount + 1) * 2), null); - greenCount++; + showClock(portalTime); + showGreen = false; } - - while (yellowCount < 18) + + for (ServerInfo serverInfo : serverList) { - setItem(yellowCount + 27, null); - yellowCount++; + boolean free = serverInfo.isFree(); + int slot = (free ? greenCount + greenStartSlot : blueCount + blueStartSlot); + + if (isStarting(serverInfo) && hasEnoughSlots(serverInfo, slotsNeeded) && (free ? greenCount : blueCount) < 3) + { + if ((free && showGreen) || !free) + { + ShopItem shopItem = buildShopItem(serverInfo, slotsNeeded); + + if (free) + greenCount++; + else + blueCount++; + + AddButton(slot, shopItem, new JoinServerButton(this, serverInfo)); + } + } + else + { + if (free) + yellowFreeCount++; + else + yellowUltraCount++; + } + } +// AddItem(11, new ShopItem(Material.IRON_BLOCK, C.cGreen + "Free Servers", new String[] {C.cGray + "Anyone can play!" }, 1, false)); +// AddItem(15, new ShopItem(Material.IRON_BLOCK, C.cBlue + "Premium Servers", new String[] {C.cGray + "Available to " + Rank.ULTRA.GetTag(true, true) + ChatColor.RESET + C.cGray + " and " + Rank.HERO.GetTag(true, true) + ChatColor.RESET + C.cGray + "!" }, 1, false)); + + AddButton(38, new ShopItem(Material.GOLD_BLOCK, C.cGreen + yellowFreeCount + " Games In Progress", new String[]{MESSAGE_SPECTATE}, yellowFreeCount > 64 ? 1 : yellowFreeCount, false), new SingleButton() + { + @Override + public void Clicked(Player player) + { + long portalTime = Plugin.getMillisecondsUntilPortal(Player); + if (portalTime <= 0) + { + _onMainPage = false; + _freeOnly = true; + } + else + { + PlayDenySound(Player); + } + } + }); + AddButton(42, new ShopItem(Material.GOLD_BLOCK, C.cAqua + yellowUltraCount + " Games In Progress", new String[]{MESSAGE_SPECTATE}, yellowUltraCount > 64 ? 1 : yellowUltraCount, false), new SingleButton() + { + @Override + public void Clicked(Player player) + { + _onMainPage = false; + _freeOnly = false; + } + }); + + // Clear empty slots + if (showGreen) + { + for (int i = greenCount + greenStartSlot; i < greenStartSlot + 3; i++) + { + setItem(i, null); + } + } + for (int i = blueCount + blueStartSlot; i < blueStartSlot + 3; i++) + { + setItem(i, null); + } + } + + private boolean isStarting(ServerInfo serverInfo) + { + return (serverInfo.MOTD.contains("Starting") || serverInfo.MOTD.contains("Recruiting") || serverInfo.MOTD.contains("Waiting") || serverInfo.MOTD.contains("Cup")); + } + + private boolean isInProgress(ServerInfo serverInfo) + { + return serverInfo.MOTD.contains("In") || serverInfo.MOTD.contains("Restarting"); + } + + private boolean hasEnoughSlots(ServerInfo serverInfo, int slotsNeeded) + { + return (serverInfo.MaxPlayers - serverInfo.CurrentPlayers) >= slotsNeeded; + } + + private void buildInProgressServerPage(List serverList, boolean freeOnly, int slotsNeeded) + { + int slot = 9; + + for (ServerInfo serverInfo : serverList) + { + if (isInProgress(serverInfo) && serverInfo.isFree() == freeOnly && slot < getSize()) + { + ShopItem shopItem = buildShopItem(serverInfo, slotsNeeded); + + AddButton(slot, shopItem, new JoinServerButton(this, serverInfo)); + + slot++; + } + } + + AddButton(4, new ShopItem(Material.BED, C.cGray + " \u21FD Go Back", new String[] { }, 1, false), new SingleButton() + { + @Override + public void Clicked(Player player) + { + clearPage(); + _onMainPage = true; + } + }); + + while (slot < getSize()) + { + setItem(slot, null); + slot++; } } @@ -200,7 +351,7 @@ public class ServerNpcPage extends ShopPageBase im { int slots = Plugin.GetRequiredSlots(player, serverInfo.ServerType); - if ((serverInfo.Name.contains("BETA") && !Client.GetRank().Has(Rank.ULTRA)) || (serverInfo.MaxPlayers - serverInfo.CurrentPlayers < slots && !(DonationManager.Get(Player.getName()).OwnsUnknownPackage(serverInfo.ServerType + " ULTRA") || Client.GetRank().Has(Rank.ULTRA)))) + if ((serverInfo.Name.contains("BETA") && !Client.GetRank().Has(Rank.ULTRA)) || (!serverInfo.isFree() && !(DonationManager.Get(Player.getName()).OwnsUnknownPackage(serverInfo.ServerType + " ULTRA") || Client.GetRank().Has(Rank.ULTRA))) || (serverInfo.MaxPlayers - serverInfo.CurrentPlayers < slots && !(DonationManager.Get(Player.getName()).OwnsUnknownPackage(serverInfo.ServerType + " ULTRA") || Client.GetRank().Has(Rank.ULTRA)))) { PlayDenySound(player); return; diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/button/JoinServerButton.java b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/button/JoinServerButton.java index 5234c692f..71b96a761 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/button/JoinServerButton.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/button/JoinServerButton.java @@ -2,12 +2,11 @@ package mineplex.hub.server.ui.button; import org.bukkit.entity.Player; -import mineplex.core.shop.item.IButton; +import mineplex.core.shop.item.SingleButton; import mineplex.hub.server.ServerInfo; import mineplex.hub.server.ui.IServerPage; -import mineplex.hub.server.ui.ServerNpcPage; -public class JoinServerButton implements IButton +public class JoinServerButton extends SingleButton { private IServerPage _page; private ServerInfo _serverInfo; @@ -17,15 +16,9 @@ public class JoinServerButton implements IButton _page = page; _serverInfo = serverInfo; } - - @Override - public void ClickedLeft(Player player) - { - _page.SelectServer(player, _serverInfo); - } @Override - public void ClickedRight(Player player) + public void Clicked(Player player) { _page.SelectServer(player, _serverInfo); }