Reimplement the MPS selection

This commit is contained in:
Sam 2018-07-31 16:20:08 +01:00 committed by Alexander Meech
parent 8982d4b47f
commit 6df90a66ff
6 changed files with 161 additions and 24 deletions

View File

@ -2,6 +2,7 @@ package mineplex.core.game.status;
import mineplex.core.account.permissions.PermissionGroup; import mineplex.core.account.permissions.PermissionGroup;
import mineplex.core.common.Constants; import mineplex.core.common.Constants;
import mineplex.core.game.GameDisplay;
public class GameInfo public class GameInfo
{ {
@ -11,7 +12,8 @@ public class GameInfo
return Constants.GSON.fromJson(json, GameInfo.class); return Constants.GSON.fromJson(json, GameInfo.class);
} }
private final String _game, _mode, _map; private final GameDisplay _game;
private final String _mode, _map;
private final int _timer; private final int _timer;
private final String[] _votingOn; private final String[] _votingOn;
private final PermissionGroup _hostRank; private final PermissionGroup _hostRank;
@ -23,7 +25,7 @@ public class GameInfo
this(null, null, null, -1, new String[0], null, GameDisplayStatus.CLOSING, GameJoinStatus.CLOSED); this(null, null, null, -1, new String[0], null, GameDisplayStatus.CLOSING, GameJoinStatus.CLOSED);
} }
public GameInfo(String game, String mode, String map, int timer, String[] votingOn, PermissionGroup hostRank, GameDisplayStatus status, GameJoinStatus joinable) public GameInfo(GameDisplay game, String mode, String map, int timer, String[] votingOn, PermissionGroup hostRank, GameDisplayStatus status, GameJoinStatus joinable)
{ {
_game = game; _game = game;
_mode = mode; _mode = mode;
@ -35,7 +37,7 @@ public class GameInfo
_joinable = joinable; _joinable = joinable;
} }
public String getGame() public GameDisplay getGame()
{ {
return _game; return _game;
} }

View File

@ -96,11 +96,6 @@ public class ServerManager extends MiniPlugin
private final PersonalServerManager _personalServerManager; private final PersonalServerManager _personalServerManager;
private final Titles _titles; private final Titles _titles;
// private NautHashMap<String, HashSet<ServerInfo>> _serverKeyInfoMap = new NautHashMap<String, HashSet<ServerInfo>>();
// private NautHashMap<String, Integer> _serverPlayerCounts = new NautHashMap<String, Integer>();
// private NautHashMap<String, ServerNpcShop> _serverNpcShopMap = new NautHashMap<String, ServerNpcShop>();
// private NautHashMap<String, ServerInfo> _serverInfoMap = new NautHashMap<String, ServerInfo>();
// private NautHashMap<String, Long> _serverUpdate = new NautHashMap<String, Long>();
// Maps ServerGroup name to ServerGroup // Maps ServerGroup name to ServerGroup
private final Map<String, ServerGroup> _serverGroupsByName; private final Map<String, ServerGroup> _serverGroupsByName;
// Maps ServerGroup NPC name to ServerGroup // Maps ServerGroup NPC name to ServerGroup
@ -431,7 +426,15 @@ public class ServerManager extends MiniPlugin
continue; continue;
} }
Map<String, GameServer> servers = _gameServers.computeIfAbsent(serverGroup.getPrefix(), k -> new HashMap<>()); String prefix = serverGroup.getPrefix();
// Special case for MPS. Normally they are all separate ServerGroups however here we want to group them together
if (serverGroup.getHost() != null && !serverGroup.getHost().isEmpty())
{
prefix = MPS_PREFIX;
}
Map<String, GameServer> servers = _gameServers.computeIfAbsent(prefix, k -> new HashMap<>());
GameServer gameServer = servers.computeIfAbsent(serverStatus.getName(), k -> new GameServer(serverStatus)); GameServer gameServer = servers.computeIfAbsent(serverStatus.getName(), k -> new GameServer(serverStatus));
GameInfo gameInfo; GameInfo gameInfo;
@ -447,14 +450,6 @@ public class ServerManager extends MiniPlugin
gameServer.updateStatus(serverStatus, gameInfo); gameServer.updateStatus(serverStatus, gameInfo);
String prefix = serverGroup.getPrefix();
// Special case for MPS. Normally they are all separate ServerGroups however here we want to group them together
if (serverGroup.getHost() != null && !serverGroup.getHost().isEmpty())
{
prefix = MPS_PREFIX;
}
_playersPlaying.put(prefix, _playersPlaying.getOrDefault(prefix, 0) + gameServer.getServer().getPlayerCount()); _playersPlaying.put(prefix, _playersPlaying.getOrDefault(prefix, 0) + gameServer.getServer().getPlayerCount());
} }
@ -511,7 +506,7 @@ public class ServerManager extends MiniPlugin
return false; return false;
case STARTING: case STARTING:
// If the game is about to start, ignore it. The player probably won't make it in time. // If the game is about to start, ignore it. The player probably won't make it in time.
return info.getTimer() < 6; return info.getTimer() < 5;
default: default:
return true; return true;
} }
@ -561,8 +556,7 @@ public class ServerManager extends MiniPlugin
_serverGroupsByNPCName.clear(); _serverGroupsByNPCName.clear();
_gameServers.clear(); _gameServers.clear();
addServerGroup(new ServerGroup("Event", "Event Servers", "EVENT")); addServerGroup(new ServerGroup(MPS_PREFIX, "Mineplex Player Servers", MPS_PREFIX));
addServerGroup(new ServerGroup("MPS", "Mineplex Player Servers", MPS_PREFIX));
} }
public int getGroupTagPlayerCount(String tag) public int getGroupTagPlayerCount(String tag)

View File

@ -0,0 +1,136 @@
package mineplex.hub.server.ui.server;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import mineplex.core.account.CoreClientManager;
import mineplex.core.account.permissions.PermissionGroup;
import mineplex.core.common.util.C;
import mineplex.core.donation.DonationManager;
import mineplex.core.game.GameDisplay;
import mineplex.core.game.status.GameInfo;
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;
import mineplex.serverdata.data.ServerGroup;
public class MPSServerSelectionPage extends ShopPageBase<ServerManager, ServerSelectionShop>
{
private final ServerGroup _serverGroup;
private final boolean _ownsUltra;
public MPSServerSelectionPage(ServerManager plugin, ServerSelectionShop shop, CoreClientManager clientManager, DonationManager donationManager, ServerGroup serverGroup, Player player)
{
super(plugin, shop, clientManager, donationManager, serverGroup.getServerNpcName(), player);
_serverGroup = serverGroup;
_ownsUltra = clientManager.Get(player).hasPermission(Perm.JOIN_FULL);
buildPage();
}
@Override
protected void buildPage()
{
List<GameServer> servers = new ArrayList<>(getPlugin().getServers(_serverGroup.getPrefix()));
servers.sort((o1, o2) -> o2.getServer().getPlayerCount() - o1.getServer().getPlayerCount());
int slot = 18, featuredSlot = 0;
for (GameServer server : servers)
{
MinecraftServer serverStatus = server.getServer();
GameInfo info = server.getInfo();
PermissionGroup hostRank = info.getHostRank();
if (hostRank == null)
{
continue;
}
int thisSlot = hostRank.hasPermission(Perm.FEATURE_SERVER) ? featuredSlot++ : slot++;
if (thisSlot >= getSize() - 1)
{
continue;
}
GameDisplay game = info.getGame();
ItemBuilder builder;
if (game == null)
{
builder = new ItemBuilder(Material.REDSTONE_BLOCK);
}
else
{
builder = new ItemBuilder(game.getMaterial(), game.getMaterialData())
.addLore(
"",
C.cYellow + "Game: " + C.Reset + game.getName()
);
}
if (info.getMap() != null)
{
builder.addLore(C.cYellow + "Map: " + C.Reset + info.getMap());
}
builder.setTitle(C.cGreenB + serverStatus.getName())
.addLore(
C.cYellow + "Host Rank: " + hostRank.getDisplay(true, true, true, true),
C.cYellow + "Players: " + C.Reset + serverStatus.getPlayerCount() + "/" + serverStatus.getMaxPlayerCount(),
""
);
String footer;
boolean canJoin;
switch (info.getJoinable())
{
case OPEN:
footer = "Click to Join!";
canJoin = true;
break;
case RANKS_ONLY:
if (_ownsUltra)
{
footer = "You have ULTRA! Click to Join!";
canJoin = true;
}
else
{
footer = "ULTRA+ can join. Visit mineplex.com/shop";
canJoin = false;
}
break;
default:
footer = "Game is full!";
canJoin = false;
break;
}
builder.addLore(C.cWhite + C.Line + footer);
addButton(thisSlot, builder.build(), (player, clickType) ->
{
if (canJoin)
{
getPlugin().selectServer(player, server);
}
else
{
playDenySound(player);
}
});
}
}
}

View File

@ -271,7 +271,7 @@ public class ServerSelectionPage extends ShopPageBase<ServerManager, ServerSelec
// If there's a game and the ServerGroup could run more than 1 game // If there's a game and the ServerGroup could run more than 1 game
if (info.getGame() != null && _serverGroup.getGames().contains(",")) if (info.getGame() != null && _serverGroup.getGames().contains(","))
{ {
builder.addLore(C.cYellow + "Game: " + C.cWhite + info.getGame()); builder.addLore(C.cYellow + "Game: " + C.cWhite + info.getGame().getName());
} }
if (info.getMode() != null) if (info.getMode() != null)

View File

@ -40,6 +40,9 @@ public class ServerSelectionShop extends ShopBase<ServerManager>
case "CW4": case "CW4":
page = new CakeWarsServerSelectionPage(getPlugin(), this, getClientManager(), getDonationManager(), serverGroup, player); page = new CakeWarsServerSelectionPage(getPlugin(), this, getClientManager(), getDonationManager(), serverGroup, player);
break; break;
case "MPS":
page = new MPSServerSelectionPage(getPlugin(), this, getClientManager(), getDonationManager(), serverGroup, player);
break;
default: default:
page = getDirectServerPage(player, serverGroup.getServerNpcName(), serverGroup); page = getDirectServerPage(player, serverGroup.getServerNpcName(), serverGroup);
break; break;

View File

@ -80,6 +80,7 @@ import mineplex.core.gadget.event.GadgetEnableEvent;
import mineplex.core.gadget.event.ToggleMobsEvent; import mineplex.core.gadget.event.ToggleMobsEvent;
import mineplex.core.gadget.types.Gadget; import mineplex.core.gadget.types.Gadget;
import mineplex.core.gadget.types.GadgetType; import mineplex.core.gadget.types.GadgetType;
import mineplex.core.game.GameDisplay;
import mineplex.core.game.MineplexGameManager; import mineplex.core.game.MineplexGameManager;
import mineplex.core.game.status.GameInfo; import mineplex.core.game.status.GameInfo;
import mineplex.core.game.status.GameInfo.GameDisplayStatus; import mineplex.core.game.status.GameInfo.GameDisplayStatus;
@ -1043,7 +1044,8 @@ public class ArcadeManager extends MiniPlugin implements IRelation
} }
boolean nullGame = _game == null; boolean nullGame = _game == null;
String game = null, mode = null, map = null; GameDisplay game = null;
String mode = null, map = null;
int timer = -1; int timer = -1;
String[] votingOn = null; String[] votingOn = null;
PermissionGroup hostRank = null; PermissionGroup hostRank = null;
@ -1063,7 +1065,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation
// MapVote // MapVote
else else
{ {
game = _game.GetName(); game = _game.GetType().getDisplay();
mode = _game.GetMode(); mode = _game.GetMode();
map = null; map = null;
} }
@ -1086,7 +1088,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation
// Game not null // Game not null
else else
{ {
game = _game.GetName(); game = _game.GetType().getDisplay();
mode = _game.GetMode(); mode = _game.GetMode();
// Has WorldData // Has WorldData