Check for Hardcore mode in Clans Server Selector

This commit is contained in:
AlexTheCoder 2017-06-13 23:13:18 -04:00
parent 9da5b367fd
commit d168e03f80
3 changed files with 86 additions and 40 deletions

View File

@ -1,20 +1,23 @@
package mineplex.clanshub;
import java.util.Collection;
import java.util.Comparator;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import mineplex.core.Managers;
import mineplex.core.account.CoreClientManager;
import mineplex.core.common.Rank;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilTime;
import mineplex.core.common.util.UtilTime.TimeUnit;
import mineplex.core.donation.DonationManager;
import mineplex.core.shop.item.ShopItem;
import mineplex.core.shop.page.ShopPageBase;
import mineplex.core.stats.StatsManager;
import mineplex.game.clans.core.repository.tokens.SimpleClanToken;
import org.bukkit.Material;
import org.bukkit.entity.Player;
/**
* GUI page for clans servers
*/
@ -31,37 +34,54 @@ public class ClansServerPage extends ShopPageBase<ClansTransferManager, ClansSer
@Override
protected void buildPage()
{
if (!getPlugin().Get(_player).getClanName().isEmpty())
if (getClientManager().hasRank(_player, Rank.HELPER))
{
buildClanPage(getPlugin().Get(_player));
buildStaffJoinServers(getPlugin().Get(_player));
}
else
{
buildNoClanPage();
if (!getPlugin().Get(_player).getClanName().isEmpty())
{
buildJoinHomeServer(getPlugin().Get(_player));
}
else
{
buildNoClanPage();
}
}
}
private void buildClanPage(SimpleClanToken clan)
private boolean canPlayHardcore()
{
if (getClientManager().hasRank(_player, Rank.HELPER))
{
buildStaffJoinServers(clan);
return true;
}
long secondsPlayed = Managers.get(StatsManager.class).Get(_player).getStat("Clans.TimePlaying");
return secondsPlayed >= UtilTime.convert(20, TimeUnit.HOURS, TimeUnit.SECONDS);
}
private String timeTillUnlockHardcore()
{
if (canPlayHardcore())
{
return "0 Seconds";
}
else
{
buildJoinHomeServer(clan);
long secondsPlayed = Managers.get(StatsManager.class).Get(_player).getStat("Clans.TimePlaying");
long needed = UtilTime.convert(20, TimeUnit.HOURS, TimeUnit.SECONDS);
return UtilTime.MakeStr(UtilTime.convert(needed - secondsPlayed, TimeUnit.SECONDS, TimeUnit.MILLISECONDS));
}
}
private void buildNoClanPage()
{
Collection<ServerInfo> servers = UtilAlg.sortSet(getPlugin().getServers(), new Comparator<ServerInfo>()
Collection<ServerInfo> servers = UtilAlg.sortSet(getPlugin().getServers(true), (o1, o2) ->
{
@Override
public int compare(ServerInfo o1, ServerInfo o2)
{
return o1.Name.compareTo(o2.Name);
}
return o1.Name.compareTo(o2.Name);
});
int currentSlot = 9;
@ -93,39 +113,57 @@ public class ClansServerPage extends ShopPageBase<ClansTransferManager, ClansSer
String title = C.cGreen + C.Bold + "Join Clans Server!";
String desc1 = C.cYellow + "Server Name " + C.cWhite + server.Name;
String desc2 = C.cYellow + "Players " + C.cWhite + server.CurrentPlayers + "/" + server.MaxPlayers;
String desc3 = C.cRed + "Note: " + C.cWhite + "Creating or Joining a clan on this";
String desc4 = C.cWhite + "server will set your Home Server!";
String desc3 = C.cYellow + "Mode " + C.cWhite + (server.Hardcore ? "Hardcore" : "Casual");
String desc4 = "";
String desc5 = "";
if (!server.Hardcore || canPlayHardcore())
{
desc4 = C.cRed + "Note: " + C.cWhite + "Creating or Joining a clan on this";
desc5 = C.cWhite + "server will set your Home Server!";
}
else
{
desc4 = C.cRed + "You have not unlocked Hardcore play yet!";
desc5 = C.cWhite + "You need to play Casual for " + timeTillUnlockHardcore() + " to unlock Hardcore play!";
}
ShopItem shopItem = new ShopItem(Material.GOLD_BLOCK, title, new String[] {" ", desc1, desc2, " ", desc3, desc4}, 0, true, true);
addButton(slot, shopItem, new JoinServerButton(this, getPlugin(), server));
ShopItem shopItem = new ShopItem(Material.GOLD_BLOCK, title, new String[] {" ", desc1, desc2, desc3, " ", desc4, desc5}, 0, true, true);
if (server.Hardcore && !canPlayHardcore())
{
addButtonNoAction(slot, shopItem);
}
else
{
addButton(slot, shopItem, new JoinServerButton(this, getPlugin(), server));
}
}
private void buildStaffJoinServers(SimpleClanToken clan)
{
ServerInfo serverInfo = getServerInfo(clan.getHomeServer());
boolean serverOnline = (serverInfo != null);
String serverStatus = serverOnline ? C.cGreen + "Online" : C.cRed + "Offline";
String title = (serverOnline ? C.cGreen : C.cRed) + C.Bold + "Join Home Server!";
String serverName = C.cYellow + "Server Name: " + C.cWhite + clan.getHomeServer();
String serverDesc = C.cYellow + "Server Status: " + C.cWhite + serverStatus;
String players = (serverOnline ? C.cYellow + "Players: " + C.cWhite + serverInfo.CurrentPlayers + "/" + serverInfo.MaxPlayers : "" );
ShopItem shopItem = new ShopItem(Material.EMERALD_BLOCK, title, new String[] {" ", serverName, serverDesc, players, " "}, 0, true, true);
addButton(13, shopItem, new JoinServerButton(this, getPlugin(), getServerInfo(clan.getHomeServer())));
Collection<ServerInfo> servers = UtilAlg.sortSet(getPlugin().getServers(), new Comparator<ServerInfo>()
if (!clan.getClanName().isEmpty())
{
@Override
public int compare(ServerInfo o1, ServerInfo o2)
{
return o1.Name.compareTo(o2.Name);
}
ServerInfo serverInfo = getServerInfo(clan.getHomeServer());
boolean serverOnline = (serverInfo != null);
String serverStatus = serverOnline ? C.cGreen + "Online" : C.cRed + "Offline";
String title = (serverOnline ? C.cGreen : C.cRed) + C.Bold + "Join Home Server!";
String serverName = C.cYellow + "Server Name: " + C.cWhite + clan.getHomeServer();
String serverDesc = C.cYellow + "Server Status: " + C.cWhite + serverStatus;
String players = C.cYellow + "Players: " + C.cWhite + (serverOnline ? serverInfo.CurrentPlayers + "/" + serverInfo.MaxPlayers : "0/0");
String mode = C.cYellow + "Mode " + C.cWhite + (serverInfo.Hardcore ? "Hardcore" : "Casual");
ShopItem shopItem = new ShopItem(Material.EMERALD_BLOCK, title, new String[] {" ", serverName, serverDesc, players, mode, " "}, 0, true, true);
addButton(13, shopItem, new JoinServerButton(this, getPlugin(), getServerInfo(clan.getHomeServer())));
}
Collection<ServerInfo> servers = UtilAlg.sortSet(getPlugin().getServers(true), (o1, o2) ->
{
return o1.Name.compareTo(o2.Name);
});
int currentSlot = 27;
for (ServerInfo server : servers)
{
if (server.Name.equalsIgnoreCase(clan.getHomeServer()))
if (!clan.getClanName().isEmpty() && server.Name.equalsIgnoreCase(clan.getHomeServer()))
{
continue;
}

View File

@ -74,10 +74,16 @@ public class ClansTransferManager extends MiniDbClientPlugin<SimpleClanToken>
* Gets a list of all loaded servers
* @return A list of all loaded servers
*/
public List<ServerInfo> getServers()
public List<ServerInfo> getServers(boolean onlineOnly)
{
List<ServerInfo> servers = Lists.newArrayList();
servers.addAll(_servers.values());
for (ServerInfo info : _servers.values())
{
if (!info.MOTD.equalsIgnoreCase("Restarting soon") || !onlineOnly)
{
servers.add(info);
}
}
return servers;
}
@ -112,6 +118,7 @@ public class ClansTransferManager extends MiniDbClientPlugin<SimpleClanToken>
info.MOTD = server.getMotd();
info.CurrentPlayers = server.getPlayerCount();
info.MaxPlayers = server.getMaxPlayerCount();
info.Hardcore = server.getMotd().contains("Hardcore");
_servers.put(server, info);
}
}

View File

@ -9,6 +9,7 @@ public class ServerInfo
public String MOTD;
public int CurrentPlayers = 0;
public int MaxPlayers = 0;
public boolean Hardcore = false;
/**
* Checks how many slots are left on this server