2016-07-25 16:55:18 +02:00
|
|
|
package mineplex.clanshub;
|
|
|
|
|
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.Comparator;
|
|
|
|
|
|
|
|
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.donation.DonationManager;
|
|
|
|
import mineplex.core.shop.item.ShopItem;
|
|
|
|
import mineplex.core.shop.page.ShopPageBase;
|
|
|
|
import mineplex.game.clans.core.repository.tokens.SimpleClanToken;
|
|
|
|
|
|
|
|
import org.bukkit.Material;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
2016-07-27 04:32:46 +02:00
|
|
|
/**
|
|
|
|
* GUI page for clans servers
|
|
|
|
*/
|
2016-07-25 16:55:18 +02:00
|
|
|
public class ClansServerPage extends ShopPageBase<ClansTransferManager, ClansServerShop>
|
|
|
|
{
|
|
|
|
public ClansServerPage(ClansTransferManager plugin, ClansServerShop shop, CoreClientManager clientManager,
|
|
|
|
DonationManager donationManager, Player player)
|
|
|
|
{
|
|
|
|
super(plugin, shop, clientManager, donationManager, "Clans", player, 54);
|
|
|
|
|
|
|
|
buildPage();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void buildPage()
|
|
|
|
{
|
|
|
|
if (!getPlugin().Get(_player).getClanName().isEmpty())
|
|
|
|
{
|
|
|
|
buildClanPage(getPlugin().Get(_player));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
buildNoClanPage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void buildClanPage(SimpleClanToken clan)
|
|
|
|
{
|
|
|
|
if (getClientManager().hasRank(_player, Rank.HELPER))
|
|
|
|
{
|
|
|
|
buildStaffJoinServers(clan);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
buildJoinHomeServer(clan);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void buildNoClanPage()
|
|
|
|
{
|
|
|
|
Collection<ServerInfo> servers = UtilAlg.sortSet(getPlugin().getServers(), new Comparator<ServerInfo>()
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public int compare(ServerInfo o1, ServerInfo o2)
|
|
|
|
{
|
|
|
|
return o1.Name.compareTo(o2.Name);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
int currentSlot = 9;
|
|
|
|
for (ServerInfo server : servers)
|
|
|
|
{
|
|
|
|
buildJoinServer(currentSlot, server);
|
|
|
|
currentSlot++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void buildJoinHomeServer(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 : "" );
|
|
|
|
String change = C.cRed + "Note: " + C.cWhite + "You must leave your Clan to ";
|
|
|
|
String change2 = C.cWhite + "play on a different Clans Server!";
|
|
|
|
ShopItem shopItem = new ShopItem(Material.EMERALD_BLOCK, title, new String[] {" ", serverName, serverDesc, players, " ", change, change2, " "}, 0, true, true);
|
|
|
|
addButton(13, shopItem, new JoinServerButton(this, getPlugin(), getServerInfo(clan.getHomeServer())));
|
|
|
|
}
|
|
|
|
|
|
|
|
private void buildJoinServer(int slot, ServerInfo server)
|
|
|
|
{
|
|
|
|
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!";
|
|
|
|
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
|
|
|
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>()
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public int compare(ServerInfo o1, ServerInfo o2)
|
|
|
|
{
|
|
|
|
return o1.Name.compareTo(o2.Name);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
int currentSlot = 27;
|
|
|
|
for (ServerInfo server : servers)
|
|
|
|
{
|
|
|
|
if (server.Name.equalsIgnoreCase(clan.getHomeServer()))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
buildJoinServer(currentSlot, server);
|
|
|
|
currentSlot++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private ServerInfo getServerInfo(String serverName)
|
|
|
|
{
|
|
|
|
return getPlugin().getServer(serverName);
|
|
|
|
}
|
|
|
|
|
2016-07-27 04:32:46 +02:00
|
|
|
/**
|
|
|
|
* Refresh all GUI pages and buttons
|
|
|
|
*/
|
2016-07-25 16:55:18 +02:00
|
|
|
public void update()
|
|
|
|
{
|
|
|
|
getButtonMap().clear();
|
|
|
|
buildPage();
|
|
|
|
}
|
|
|
|
}
|