Redo the Lobby Selector

This commit is contained in:
Sam 2018-07-30 20:03:57 +01:00 committed by Alexander Meech
parent f9504a9e4c
commit 4327c8468a
3 changed files with 84 additions and 11 deletions

View File

@ -107,7 +107,7 @@ public class ServerManager extends MiniPlugin
private final Map<String, ServerGroup> _serverGroupsByNPCName; private final Map<String, ServerGroup> _serverGroupsByNPCName;
// Maps ServerGroup prefix (CW4) to a Map that maps server name (CW4-5) to GameServer // Maps ServerGroup prefix (CW4) to a Map that maps server name (CW4-5) to GameServer
private final Map<String, Map<String, GameServer>> _gameServers; private final Map<String, Map<String, GameServer>> _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<String, Integer> _playersPlaying; private final Map<String, Integer> _playersPlaying;
// Maps (in both directions) ServerGroup NPC name to the game room location // Maps (in both directions) ServerGroup NPC name to the game room location
private final BiMap<String, Location> _serverNPCTeleport; private final BiMap<String, Location> _serverNPCTeleport;
@ -472,7 +472,7 @@ public class ServerManager extends MiniPlugin
public boolean selectServer(Player player, GameServer server) 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; return false;
} }
@ -486,6 +486,11 @@ public class ServerManager extends MiniPlugin
public boolean selectBest(Player player, ServerGroup serverGroup) public boolean selectBest(Player player, ServerGroup serverGroup)
{ {
if (!Recharge.Instance.use(player, "Select Best Server", SELECT_SERVER_COOLDOWN, false, false))
{
return false;
}
Collection<GameServer> servers = getServers(serverGroup.getPrefix()); Collection<GameServer> servers = getServers(serverGroup.getPrefix());
int required = getRequiredSlots(player); int required = getRequiredSlots(player);

View File

@ -1,28 +1,96 @@
package mineplex.hub.server.ui.lobby; 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 org.bukkit.entity.Player;
import mineplex.core.account.CoreClientManager; 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.donation.DonationManager;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.shop.page.ShopPageBase; import mineplex.core.shop.page.ShopPageBase;
import mineplex.hub.server.GameServer;
import mineplex.hub.server.ServerManager; import mineplex.hub.server.ServerManager;
import mineplex.hub.server.ServerManager.Perm;
import mineplex.serverdata.data.MinecraftServer;
public class LobbyMenu extends ShopPageBase<ServerManager, LobbyShop> public class LobbyMenu extends ShopPageBase<ServerManager, LobbyShop>
{ {
private final String _serverGroup; LobbyMenu(ServerManager plugin, LobbyShop lobbyShop, CoreClientManager clientManager, DonationManager donationManager, Player player)
LobbyMenu(ServerManager plugin, LobbyShop lobbyShop, CoreClientManager clientManager, DonationManager donationManager, String name, Player player, String serverGroup)
{ {
super(plugin, lobbyShop, clientManager, donationManager, name, player, 54); super(plugin, lobbyShop, clientManager, donationManager, "Lobby Selector", player);
_serverGroup = serverGroup;
buildPage(); buildPage();
} }
@Override @Override
protected void buildPage() protected void buildPage()
{ {
List<GameServer> 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);
}
});
});
} }
} }

View File

@ -19,7 +19,7 @@ public class LobbyShop extends ShopBase<ServerManager>
@Override @Override
protected ShopPageBase<ServerManager, ? extends ShopBase<ServerManager>> buildPagesFor(Player player) protected ShopPageBase<ServerManager, ? extends ShopBase<ServerManager>> 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() public void updatePages()