Close the server selector after 45 seconds

This commit is contained in:
Sam 2018-07-27 20:43:00 +01:00 committed by Alexander Meech
parent 304833dbae
commit 1583d41d1a
1 changed files with 31 additions and 6 deletions

View File

@ -1,7 +1,9 @@
package mineplex.hub.server.newui;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
@ -11,6 +13,7 @@ import mineplex.core.account.CoreClientManager;
import mineplex.core.common.util.C;
import mineplex.core.common.util.LineFormat;
import mineplex.core.common.util.UtilText;
import mineplex.core.common.util.UtilTime;
import mineplex.core.donation.DonationManager;
import mineplex.core.game.status.GameInfo;
import mineplex.core.game.status.GameInfo.GameDisplayStatus;
@ -26,9 +29,14 @@ public class ServerSelectionPage extends ShopPageBase<ServerManager, ServerSelec
private static final int STARTING_SLOT = 19;
private static final int MAX_SHOWN_SERVERS = 7;
private static final long MAX_VIEWING_TIME = TimeUnit.SECONDS.toMillis(45);
private static final Comparator<GameServer> GAME_SERVER_SORTER = (o1, o2) ->
{
return 0;
};
private final ServerGroup _serverGroup;
private final long _openedAt;
private boolean _showInProgress;
@ -37,24 +45,41 @@ public class ServerSelectionPage extends ShopPageBase<ServerManager, ServerSelec
super(plugin, shop, clientManager, donationManager, serverGroup.getServerNpcName(), player);
_serverGroup = serverGroup;
_openedAt = System.currentTimeMillis();
buildPage();
}
@Override
protected void buildPage()
{
if (UtilTime.elapsed(_openedAt, MAX_VIEWING_TIME))
{
getPlayer().closeInventory();
return;
}
List<GameServer> servers = new ArrayList<>(getPlugin().getServers(_serverGroup.getPrefix()));
servers.sort(GAME_SERVER_SORTER);
if (_showInProgress)
{
// TODO MAKE
}
else
{
buildMainPage();
buildMainPage(servers);
}
}
private void buildMainPage()
private void buildMainPage(List<GameServer> servers)
{
// Filter servers
servers.removeIf(server ->
{
GameDisplayStatus status = server.getInfo().getStatus();
return status == null || status == GameDisplayStatus.IN_PROGRESS || status == GameDisplayStatus.CLOSING;
});
// Instant join
addRow(0, (byte) 3, new ItemBuilder(Material.DIAMOND_BLOCK)
.setTitle(C.cGreenB + "Click To Join Instantly!")
@ -65,7 +90,6 @@ public class ServerSelectionPage extends ShopPageBase<ServerManager, ServerSelec
});
// Public Servers
List<GameServer> servers = new ArrayList<>(getPlugin().getServers(_serverGroup.getPrefix()));
int slot = STARTING_SLOT;
for (GameServer server : servers)
@ -96,7 +120,8 @@ public class ServerSelectionPage extends ShopPageBase<ServerManager, ServerSelec
}, LineFormat.LORE)),
(player, clickType) ->
{
// TODO show in progress servers
_showInProgress = !_showInProgress;
refresh();
});
}
@ -136,7 +161,7 @@ public class ServerSelectionPage extends ShopPageBase<ServerManager, ServerSelec
material = Material.STAINED_GLASS;
data = (byte) 5;
votingColour = C.cYellow;
votingStatus = "Voting is in Progress";
votingStatus = "Voting Is In Progress";
motd = "Voting Ends in " + timeString(info.getTimer());
break;
case STARTING: