From 4327c8468a7957486f0018c2c1e83367f456afc8 Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 30 Jul 2018 20:03:57 +0100 Subject: [PATCH] Redo the Lobby Selector --- .../mineplex/hub/server/ServerManager.java | 9 +- .../hub/server/ui/lobby/LobbyMenu.java | 84 +++++++++++++++++-- .../hub/server/ui/lobby/LobbyShop.java | 2 +- 3 files changed, 84 insertions(+), 11 deletions(-) diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerManager.java index ac1e9c8e0..828d5d42f 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerManager.java @@ -107,7 +107,7 @@ public class ServerManager extends MiniPlugin private final Map _serverGroupsByNPCName; // Maps ServerGroup prefix (CW4) to a Map that maps server name (CW4-5) to GameServer private final Map> _gameServers; - // Maps ServerGroup prefix (CW4) to the number of players on that server + // Maps ServerType (Not ServerGroup) prefix (CW4) to the number of players on that server private final Map _playersPlaying; // Maps (in both directions) ServerGroup NPC name to the game room location private final BiMap _serverNPCTeleport; @@ -472,7 +472,7 @@ public class ServerManager extends MiniPlugin public boolean selectServer(Player player, GameServer server) { - if (!Recharge.Instance.use(player, getName(), SELECT_SERVER_COOLDOWN, false, false)) + if (!Recharge.Instance.use(player, "Select Server", SELECT_SERVER_COOLDOWN, false, false)) { return false; } @@ -486,6 +486,11 @@ public class ServerManager extends MiniPlugin public boolean selectBest(Player player, ServerGroup serverGroup) { + if (!Recharge.Instance.use(player, "Select Best Server", SELECT_SERVER_COOLDOWN, false, false)) + { + return false; + } + Collection servers = getServers(serverGroup.getPrefix()); int required = getRequiredSlots(player); diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/lobby/LobbyMenu.java b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/lobby/LobbyMenu.java index a6c917c54..89be1ff96 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/lobby/LobbyMenu.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/lobby/LobbyMenu.java @@ -1,28 +1,96 @@ package mineplex.hub.server.ui.lobby; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; + +import org.bukkit.Material; import org.bukkit.entity.Player; import mineplex.core.account.CoreClientManager; +import mineplex.core.common.util.C; +import mineplex.core.common.util.UtilServer; import mineplex.core.donation.DonationManager; +import mineplex.core.itemstack.ItemBuilder; import mineplex.core.shop.page.ShopPageBase; +import mineplex.hub.server.GameServer; import mineplex.hub.server.ServerManager; +import mineplex.hub.server.ServerManager.Perm; +import mineplex.serverdata.data.MinecraftServer; public class LobbyMenu extends ShopPageBase { - private final String _serverGroup; - - LobbyMenu(ServerManager plugin, LobbyShop lobbyShop, CoreClientManager clientManager, DonationManager donationManager, String name, Player player, String serverGroup) + LobbyMenu(ServerManager plugin, LobbyShop lobbyShop, CoreClientManager clientManager, DonationManager donationManager, Player player) { - super(plugin, lobbyShop, clientManager, donationManager, name, player, 54); - - _serverGroup = serverGroup; - + super(plugin, lobbyShop, clientManager, donationManager, "Lobby Selector", player); buildPage(); } - @Override + @Override protected void buildPage() { + List servers = new ArrayList<>(getPlugin().getServers("Lobby")); + boolean ownsUltra = getClientManager().Get(getPlayer()).hasPermission(Perm.JOIN_FULL); + String serverName = UtilServer.getServerName(); + + servers.sort(Comparator.comparingInt(GameServer::getNumber)); + + servers.forEach(server -> + { + if (server.getNumber() >= getSize()) + { + return; + } + + MinecraftServer serverStatus = server.getServer(); + + ItemBuilder builder = new ItemBuilder(Material.IRON_BLOCK); + String colour = C.cYellow, bottomLine = "Click to Join!"; + boolean sameServer = serverName.equals(serverStatus.getName()); + boolean full = serverStatus.getPlayerCount() >= serverStatus.getMaxPlayerCount(); + boolean canJoin = ownsUltra || !full; + + if (sameServer) + { + builder.setType(Material.EMERALD_BLOCK); + colour = C.cGreenB; + bottomLine = "You are here!"; + } + else if (full) + { + if (ownsUltra) + { + builder.setType(Material.DIAMOND_BLOCK); + colour = C.cAquaB; + } + else + { + builder.setType(Material.REDSTONE_BLOCK); + colour = C.cRedB; + bottomLine = "Ultra+ can join. Visit mineplex.com/shop!"; + } + } + + builder.setTitle(colour + serverStatus.getName()); + builder.addLore( + "", + C.cYellow + "Players: " + C.Reset + serverStatus.getPlayerCount() + "/" + serverStatus.getMaxPlayerCount(), + "", + bottomLine + ); + + addButton(server.getNumber() - 1, builder.build(), (player, clickType) -> + { + if (sameServer) + { + playDenySound(player); + } + else if (canJoin) + { + getPlugin().selectServer(player, server); + } + }); + }); } } \ No newline at end of file diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/lobby/LobbyShop.java b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/lobby/LobbyShop.java index 3011fae4c..6e7776901 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/lobby/LobbyShop.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/lobby/LobbyShop.java @@ -19,7 +19,7 @@ public class LobbyShop extends ShopBase @Override protected ShopPageBase> buildPagesFor(Player player) { - return new LobbyMenu(getPlugin(), this, getClientManager(), getDonationManager(), "Lobby Selector", player, "Lobby"); + return new LobbyMenu(getPlugin(), this, getClientManager(), getDonationManager(), player); } public void updatePages()