Fixed memory leaks.

Added in party joining for servers in Hub
Modified server status's in server UI.
This commit is contained in:
Jonathan Williams 2013-09-09 01:28:35 -07:00
parent ff0e39067a
commit d4b3c5d461
16 changed files with 298 additions and 93 deletions

View File

@ -1,7 +1,6 @@
package mineplex.core.account;
import java.util.AbstractMap;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map.Entry;
@ -38,7 +37,7 @@ public class CoreClientManager implements Listener
private JavaPlugin _plugin;
private AccountRepository _repository;
private HashSet<String> _allClients;
private HashMap<String, CoreClient> _clientList;
private NautHashMap<String, CoreClient> _clientList;
private HashSet<String> _dontRemoveList;
private NautHashMap<String, Entry<CoreClient, Long>> _cacheList;
@ -51,7 +50,7 @@ public class CoreClientManager implements Listener
_plugin = plugin;
_repository = new AccountRepository(webServer);
_allClients = new HashSet<String>();
_clientList = new HashMap<String, CoreClient>();
_clientList = new NautHashMap<String, CoreClient>();
_dontRemoveList = new HashSet<String>();
_cacheList = new NautHashMap<String, Entry<CoreClient, Long>>();
@ -77,7 +76,7 @@ public class CoreClientManager implements Listener
{
CoreClient newClient = null;
synchronized (this)
synchronized (_clientLock)
{
if (_cacheList.containsKey(name))
{
@ -106,24 +105,6 @@ public class CoreClientManager implements Listener
return newClient;
}
public CoreClient Add(Player player)
{
CoreClient newClient = new CoreClient(player);
CoreClient oldClient = null;
synchronized(_clientLock)
{
oldClient = _clientList.put(player.getName(), newClient);
}
if (oldClient != null)
{
oldClient.Delete();
}
return newClient;
}
public void Del(String name)
{
CoreClient removedClient = null;
@ -200,6 +181,14 @@ public class CoreClientManager implements Listener
@EventHandler(priority = EventPriority.LOWEST)
public void Login(PlayerLoginEvent event)
{
synchronized(_clientLock)
{
if (!_clientList.containsKey(event.getPlayer().getName()))
{
_clientList.put(event.getPlayer().getName(), new CoreClient(event.getPlayer().getName()));
}
}
CoreClient client = Get(event.getPlayer().getName());
client.SetPlayer(event.getPlayer());

View File

@ -27,6 +27,8 @@ public class PetTagPage extends ShopPageBase<PetManager, PetShop>
super(plugin, shop, clientManager, donationManager, name, player, 3);
BuildPage();
Player.setLevel(5);
}
@Override
@ -38,6 +40,14 @@ public class PetTagPage extends ShopPageBase<PetManager, PetShop>
ButtonMap.put(1, new CloseButton());
ButtonMap.put(2, new SelectTagButton(this));
}
@Override
public void PlayerClosed()
{
super.PlayerClosed();
Player.setLevel(0);
}
public void SelectTag()
{
@ -47,7 +57,6 @@ public class PetTagPage extends ShopPageBase<PetManager, PetShop>
PlayDenySound(Player);
Player.closeInventory();
Shop.ResetPlayer(Player);
return;
}
@ -76,7 +85,6 @@ public class PetTagPage extends ShopPageBase<PetManager, PetShop>
Plugin.GetRepository().RemovePetNameTag(Player.getName());
Player.closeInventory();
Shop.ResetPlayer(Player);
}
public void SetTagName(String tagName)

View File

@ -91,6 +91,9 @@ public abstract class ShopBase<PluginType extends MiniPlugin> implements Listene
if (!_openedShop.contains(player.getName()) && entity.isCustomNameVisible() && entity.getCustomName() != null && ChatColor.stripColor(entity.getCustomName()).equalsIgnoreCase(ChatColor.stripColor(Name)))
{
if (!CanOpenShop(player))
return false;
_openedShop.add(player.getName());
OpenShopForPlayer(player);
@ -138,14 +141,14 @@ public abstract class ShopBase<PluginType extends MiniPlugin> implements Listene
}
}
protected boolean CanOpenShop(Player player)
{
return true;
}
protected void OpenShopForPlayer(Player player) { }
protected void CloseShopForPlayer(Player player) { }
public void ResetPlayer(Player player)
{
PlayerPageMap.remove(player.getName());
}
@EventHandler
public void OnPlayerQuit(PlayerQuitEvent event)
@ -169,12 +172,10 @@ public abstract class ShopBase<PluginType extends MiniPlugin> implements Listene
if (PlayerPageMap.containsKey(player.getName()))
{
PlayerPageMap.get(player.getName()).PlayerClosed();
}
}
SetCurrentPageForPlayer(player, page);
player.closeInventory();
player.openInventory(page);
}

View File

@ -259,14 +259,26 @@ public class ConfirmationPage<PluginType extends MiniPlugin, ShopType extends Sh
{
if (_progressCount >= 20)
{
if (_returnPage != null)
Shop.OpenPageForPlayer(Player, _returnPage);
else
try
{
Player.closeInventory();
if (_returnPage != null)
{
Shop.OpenPageForPlayer(Player, _returnPage);
}
else
{
Player.closeInventory();
}
}
catch (Exception exception)
{
exception.printStackTrace();
}
finally
{
Plugin.GetScheduler().cancelTask(_taskId);
Dispose();
}
Plugin.GetScheduler().cancelTask(_taskId);
}
}

View File

@ -25,6 +25,7 @@ import mineplex.core.task.TaskManager;
import mineplex.core.teleport.Teleport;
import mineplex.core.updater.FileUpdater;
import mineplex.core.updater.Updater;
import mineplex.hub.party.PartyManager;
import mineplex.hub.server.ServerManager;
import mineplex.minecraft.game.classcombat.Class.ClassManager;
import mineplex.minecraft.game.classcombat.Condition.SkillConditionManager;
@ -74,9 +75,10 @@ public class Hub extends JavaPlugin implements INautilusPlugin, IRelation
//Main Modules
PacketHandler packetHandler = new PacketHandler(this);
Portal portal = new Portal(this);
new HubManager(this, clientManager, donationManager, new DisguiseManager(this, packetHandler), new TaskManager(this, GetWebServerAddress()), portal);
PartyManager partyManager = new PartyManager(this, clientManager);
new HubManager(this, clientManager, donationManager, new DisguiseManager(this, packetHandler), new TaskManager(this, GetWebServerAddress()), portal, partyManager);
new Stacker(this);
new ServerManager(this, clientManager, donationManager, portal);
new ServerManager(this, clientManager, donationManager, portal, partyManager);
new Chat(this, clientManager);
new MemoryFix(this);
new FileUpdater(this, portal);

View File

@ -23,7 +23,6 @@ import org.bukkit.entity.Chicken;
import org.bukkit.entity.Cow;
import org.bukkit.entity.Egg;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Horse;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Pig;
import org.bukkit.entity.Player;
@ -41,7 +40,6 @@ import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerPickupItemEvent;
import org.bukkit.event.player.PlayerQuitEvent;
@ -74,7 +72,6 @@ import mineplex.core.portal.Portal;
import mineplex.core.task.TaskManager;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.hub.commands.HorseSpawn;
import mineplex.hub.modules.MountManager;
import mineplex.hub.party.Party;
import mineplex.hub.party.PartyManager;
@ -106,7 +103,7 @@ public class HubManager extends MiniClientPlugin<HubClient>
private HashSet<LivingEntity> _mobs = new HashSet<LivingEntity>();
public HubManager(JavaPlugin plugin, CoreClientManager clientManager, DonationManager donationManager, DisguiseManager disguiseManager, TaskManager taskManager, Portal portal)
public HubManager(JavaPlugin plugin, CoreClientManager clientManager, DonationManager donationManager, DisguiseManager disguiseManager, TaskManager taskManager, Portal portal, PartyManager partyManager)
{
super("Hub Manager", plugin);
@ -122,7 +119,7 @@ public class HubManager extends MiniClientPlugin<HubClient>
new Dragon(this);
new MountManager(this);
_partyManager = new PartyManager(this);
_partyManager = partyManager;
_tutorialManager = new TutorialManager(this, donationManager, taskManager, _textCreator);
DragonTextB = GetDragonText();

View File

@ -59,7 +59,7 @@ public class Party
//Add Players
for (Player player : Bukkit.getOnlinePlayers())
{
_scoreboard.getTeam(Manager.Manager.GetClients().Get(player).GetRank().Name).addPlayer(player);
_scoreboard.getTeam(Manager.GetClients().Get(player).GetRank().Name).addPlayer(player);
}
//Owners
@ -132,7 +132,7 @@ public class Party
_players.remove(player.getName());
//Set Scoreboard
_scoreboard.getTeam(Manager.Manager.GetClients().Get(player).GetRank().Name).addPlayer(player);
_scoreboard.getTeam(Manager.GetClients().Get(player).GetRank().Name).addPlayer(player);
if (leader && _players.size() > 0)
{
@ -154,7 +154,7 @@ public class Party
if (_players.contains(player.getName()))
_scoreboard.getTeam("Party").addPlayer(player);
else
_scoreboard.getTeam(Manager.Manager.GetClients().Get(player).GetRank().Name).addPlayer(player);
_scoreboard.getTeam(Manager.GetClients().Get(player).GetRank().Name).addPlayer(player);
if (_creator.equals(player.getName()))
{
@ -182,8 +182,12 @@ public class Party
for (String name : _players)
{
Player player = UtilPlayer.searchExact(name);
UtilPlayer.message(player, F.main("Party", message));
player.playSound(player.getLocation(), Sound.NOTE_PLING, 1f, 1.5f);
if (player != null && player.isOnline())
{
UtilPlayer.message(player, F.main("Party", message));
player.playSound(player.getLocation(), Sound.NOTE_PLING, 1f, 1.5f);
}
}
}

View File

@ -8,24 +8,25 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.MiniPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.hub.HubManager;
import mineplex.hub.party.commands.PartyCommand;
public class PartyManager extends MiniPlugin
{
public HubManager Manager;
private CoreClientManager _clientManager;
public HashSet<Party> _parties = new HashSet<Party>();
public PartyManager(HubManager manager)
public PartyManager(JavaPlugin plugin, CoreClientManager clientManager)
{
super("Party Manager", manager.GetPlugin());
super("Party Manager", plugin);
Manager = manager;
_clientManager = clientManager;
}
@Override
@ -33,6 +34,11 @@ public class PartyManager extends MiniPlugin
{
AddCommand(new PartyCommand(this));
}
public CoreClientManager GetClients()
{
return _clientManager;
}
public Party CreateParty(Player player)
{

View File

@ -6,4 +6,7 @@ public class ServerInfo
public String MOTD = "Retrieving status";
public int CurrentPlayers = 0;
public int MaxPlayers = 0;
public String Map;
public String ServerType;
public String Game;
}

View File

@ -35,6 +35,8 @@ import mineplex.core.donation.DonationManager;
import mineplex.core.portal.Portal;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.hub.party.Party;
import mineplex.hub.party.PartyManager;
import mineplex.hub.server.command.ServerNpcCommand;
import mineplex.hub.server.ui.ServerNpcShop;
@ -43,6 +45,7 @@ public class ServerManager extends MiniPlugin implements PluginMessageListener
private CoreClientManager _clientManager;
private DonationManager _donationManager;
private Portal _portal;
private PartyManager _partyManager;
private NautHashMap<String, List<ServerInfo>> _serverNpcMap = new NautHashMap<String, List<ServerInfo>>();
private NautHashMap<String, ServerNpcShop> _serverNpcShopMap = new NautHashMap<String, ServerNpcShop>();
@ -52,13 +55,14 @@ public class ServerManager extends MiniPlugin implements PluginMessageListener
private boolean _update = true;
private boolean _loading = false;
public ServerManager(JavaPlugin plugin, CoreClientManager clientManager, DonationManager donationManager, Portal portal)
public ServerManager(JavaPlugin plugin, CoreClientManager clientManager, DonationManager donationManager, Portal portal, PartyManager partyManager)
{
super("Server Manager", plugin);
_clientManager = clientManager;
_donationManager = donationManager;
_portal = portal;
_partyManager = partyManager;
plugin.getServer().getMessenger().registerOutgoingPluginChannel(plugin, "BungeeCord");
plugin.getServer().getMessenger().registerOutgoingPluginChannel(plugin, "BungeeSigns");
@ -178,11 +182,22 @@ public class ServerManager extends MiniPlugin implements PluginMessageListener
if (_serverInfoMap.containsKey(serverName))
{
String[] args = motd.split("\\|");
ServerInfo serverInfo = _serverInfoMap.get(serverName);
serverInfo.MOTD = motd;
serverInfo.MOTD = args.length > 0 ? args[0] : motd;
serverInfo.CurrentPlayers = players;
serverInfo.MaxPlayers = maxPlayers;
if (args.length > 1)
serverInfo.ServerType = args[1];
if (args.length > 2)
serverInfo.Game = args[2];
if (args.length > 3)
serverInfo.Map = args[3];
_serverUpdate.put(serverName, System.currentTimeMillis());
}
}
@ -272,12 +287,59 @@ public class ServerManager extends MiniPlugin implements PluginMessageListener
Help(caller, null);
}
public void SelectServer(org.bukkit.entity.Player player, String serverName)
public PartyManager getPartyManager()
{
player.leaveVehicle();
player.eject();
return _partyManager;
}
public void SelectServer(org.bukkit.entity.Player player, ServerInfo serverInfo)
{
Party party = _partyManager.GetParty(player);
_portal.SendPlayerToServer(player, serverName);
if (party != null)
{
if (player.getName().equals(party.GetLeader()))
{
for (String name : party.GetPlayers())
{
Player partyPlayer = UtilPlayer.searchExact(name);
if (partyPlayer == null)
continue;
if (_clientManager.Get(partyPlayer).GetRank().Has(Rank.ULTRA) || _donationManager.Get(partyPlayer.getName()).OwnsUnknownPackage(serverInfo.ServerType + " ULTRA"))
continue;
partyPlayer.leaveVehicle();
partyPlayer.eject();
_portal.SendPlayerToServer(partyPlayer, serverInfo.Name);
}
for (String name : party.GetPlayers())
{
Player partyPlayer = UtilPlayer.searchExact(name);
if (partyPlayer == null)
continue;
if (_clientManager.Get(partyPlayer).GetRank().Has(Rank.ULTRA) || _donationManager.Get(partyPlayer.getName()).OwnsUnknownPackage(serverInfo.ServerType + " ULTRA"))
{
partyPlayer.leaveVehicle();
partyPlayer.eject();
_portal.SendPlayerToServer(partyPlayer, serverInfo.Name);
}
}
}
}
else
{
player.leaveVehicle();
player.eject();
_portal.SendPlayerToServer(player, serverInfo.Name);
}
}
public void ListServerNpcs(Player caller)
@ -437,4 +499,37 @@ public class ServerManager extends MiniPlugin implements PluginMessageListener
_loading = false;
}
}
public int GetRequiredSlots(Player player, String serverType)
{
int slots = 0;
Party party = _partyManager.GetParty(player);
if (party != null)
{
if (player.getName().equals(party.GetLeader()))
{
for (String name : party.GetPlayers())
{
Player partyPlayer = UtilPlayer.searchExact(name);
if (partyPlayer == null)
continue;
if (_clientManager.Get(partyPlayer).GetRank().Has(Rank.ULTRA) || _donationManager.Get(partyPlayer.getName()).OwnsUnknownPackage(serverType + " ULTRA"))
continue;
slots++;
}
}
}
else
{
if (!_clientManager.Get(player).GetRank().Has(Rank.ULTRA) && !_donationManager.Get(player.getName()).OwnsUnknownPackage(serverType + " ULTRA"))
slots++;
}
return slots;
}
}

View File

@ -4,6 +4,13 @@ import java.util.Comparator;
public class ServerSorter implements Comparator<ServerInfo>
{
private int _requiredSlots;
public ServerSorter(int slots)
{
_requiredSlots = slots;
}
public int compare(ServerInfo a, ServerInfo b)
{
if ((a.MOTD.contains("Restarting")))
@ -12,12 +19,18 @@ public class ServerSorter implements Comparator<ServerInfo>
if ((b.MOTD.contains("Restarting")))
return -1;
if ((a.MOTD.contains("Recruiting") || a.MOTD.contains("Waiting") || a.MOTD.contains("Cup")) && !b.MOTD.contains("Recruiting") && !b.MOTD.contains("Waiting") && !b.MOTD.contains("Cup"))
if ((a.MOTD.contains("Recruiting") || a.MOTD.contains("Waiting") || a.MOTD.contains("Starting") || a.MOTD.contains("Cup")) && !b.MOTD.contains("Recruiting") && !b.MOTD.contains("Waiting") && !b.MOTD.contains("Starting") && !b.MOTD.contains("Cup"))
return -1;
if ((b.MOTD.contains("Recruiting") || b.MOTD.contains("Waiting") || b.MOTD.contains("Cup")) && !a.MOTD.contains("Recruiting") && !a.MOTD.contains("Waiting") && !a.MOTD.contains("Cup"))
if ((b.MOTD.contains("Recruiting") || b.MOTD.contains("Waiting") || a.MOTD.contains("Starting") || b.MOTD.contains("Cup")) && !a.MOTD.contains("Recruiting") && !a.MOTD.contains("Waiting") && !a.MOTD.contains("Starting") && !a.MOTD.contains("Cup"))
return 1;
if (a.MaxPlayers - a.CurrentPlayers < _requiredSlots && b.MaxPlayers - b.CurrentPlayers >= _requiredSlots)
return 1;
if (b.MaxPlayers - b.CurrentPlayers < _requiredSlots && a.MaxPlayers - a.CurrentPlayers >= _requiredSlots)
return -1;
if (a.CurrentPlayers > b.CurrentPlayers)
return -1;

View File

@ -3,21 +3,22 @@ package mineplex.hub.server.ui;
import org.bukkit.entity.Player;
import mineplex.core.shop.item.IButton;
import mineplex.hub.server.ServerInfo;
public class JoinServerButton implements IButton
{
private ServerNpcPage _page;
private String _serverName;
private ServerInfo _serverInfo;
public JoinServerButton(ServerNpcPage page, String serverName)
public JoinServerButton(ServerNpcPage page, ServerInfo serverInfo)
{
_page = page;
_serverName = serverName;
_serverInfo = serverInfo;
}
@Override
public void Clicked(Player player)
{
_page.SelectServer(player, _serverName);
_page.SelectServer(player, _serverInfo);
}
}

View File

@ -6,9 +6,11 @@ import java.util.List;
import mineplex.core.account.CoreClientManager;
import mineplex.core.common.Rank;
import mineplex.core.common.util.C;
import mineplex.core.donation.DonationManager;
import mineplex.core.shop.item.ShopItem;
import mineplex.core.shop.page.ShopPageBase;
import mineplex.hub.party.Party;
import mineplex.hub.server.ServerInfo;
import mineplex.hub.server.ServerManager;
import mineplex.hub.server.ServerSorter;
@ -32,75 +34,102 @@ public class ServerNpcPage extends ShopPageBase<ServerManager, ServerNpcShop>
@Override
protected void BuildPage()
{
List<ServerInfo> serverList = Plugin.GetServerList(_serverNpcKey);
Collections.sort(serverList, new ServerSorter());
{
List<ServerInfo> serverList = Plugin.GetServerList(_serverNpcKey);
int slots = 1;
if (serverList.size() > 0)
{
slots = Plugin.GetRequiredSlots(Player, serverList.get(0).ServerType);
}
Collections.sort(serverList, new ServerSorter(slots));
int slot = 9;
int greenCount = 0;
int yellowCount = 0;
int yellowCount = 0;
String openFull = ChatColor.RESET + C.Line + "Get Ultra to join full servers!";
String openFullUltra = ChatColor.RESET + C.Line + "Click to join!";
for (ServerInfo serverInfo : serverList)
{
String inProgress = (serverInfo.Game == null || serverInfo.ServerType.equalsIgnoreCase("Competitive")) ? (ChatColor.RESET + C.Line + "Game in progress.") : (ChatColor.RESET + C.Line + "Click to spectate and wait for next game!");
Material status = Material.REDSTONE_BLOCK;
List<String> lore = new ArrayList<String>();
if (slot >= 53)
break;
if ((serverInfo.MOTD.contains("Recruiting") || serverInfo.MOTD.contains("Waiting") || serverInfo.MOTD.contains("Cup")) && slot < 15)
if ((serverInfo.MOTD.contains("Starting") || serverInfo.MOTD.contains("Recruiting") || serverInfo.MOTD.contains("Waiting") || serverInfo.MOTD.contains("Cup")) && slot < 15 && (serverInfo.MaxPlayers - serverInfo.CurrentPlayers) >= slots)
{
slot += 2;
status = Material.EMERALD_BLOCK;
lore.add(ChatColor.RESET + serverInfo.MOTD);
lore.add(ChatColor.RESET + "" + serverInfo.CurrentPlayers + "/" + serverInfo.MaxPlayers);
lore.add(ChatColor.RESET + "");
if (serverInfo.Game != null)
lore.add(ChatColor.RESET + "" + ChatColor.YELLOW + "Game: " + ChatColor.WHITE + serverInfo.Game);
if (serverInfo.Map != null && !serverInfo.ServerType.equalsIgnoreCase("Competitive"))
lore.add(ChatColor.RESET + "" + ChatColor.YELLOW + "Map: " + ChatColor.WHITE + serverInfo.Map);
lore.add(ChatColor.RESET + "" + ChatColor.YELLOW + "Players: " + ChatColor.WHITE + serverInfo.CurrentPlayers + "/" + serverInfo.MaxPlayers);
lore.add(ChatColor.RESET + "");
lore.add(ChatColor.RESET + serverInfo.MOTD);
if (serverInfo.CurrentPlayers >= serverInfo.MaxPlayers)
{
if (!Client.GetRank().Has(Rank.ULTRA))
lore.add(ChatColor.RESET + "" + ChatColor.YELLOW + "Get Ultra to join full servers!");
lore.add(openFull);
else
lore.add(ChatColor.RESET + "" + ChatColor.GREEN + "Click to join!");
lore.add(openFullUltra);
}
else
lore.add(ChatColor.RESET + "" + ChatColor.GREEN + "Click to join!");
lore.add(ChatColor.RESET + C.Line + "Click to join!");
greenCount++;
}
else if (serverInfo.MOTD.contains("In") || serverInfo.MOTD.contains("Restarting") || serverInfo.MOTD.contains("Starting"))
else if (serverInfo.MOTD.contains("In") || serverInfo.MOTD.contains("Restarting"))
{
if (slot <= 15)
slot = 27;
else
slot++;
status = Material.GOLD_BLOCK;
lore.add(ChatColor.RESET + serverInfo.MOTD);
lore.add(ChatColor.RESET + "" + serverInfo.CurrentPlayers + "/" + serverInfo.MaxPlayers);
status = Material.GOLD_BLOCK;
lore.add(ChatColor.RESET + "");
if (serverInfo.Game != null)
lore.add(ChatColor.RESET + "" + ChatColor.YELLOW + "Game: " + ChatColor.WHITE + serverInfo.Game);
if (serverInfo.Map != null && !serverInfo.ServerType.equalsIgnoreCase("Competitive"))
lore.add(ChatColor.RESET + "" + ChatColor.YELLOW + "Map: " + ChatColor.WHITE + serverInfo.Map);
lore.add(ChatColor.RESET + "" + ChatColor.YELLOW + "Players: " + ChatColor.WHITE + serverInfo.CurrentPlayers + "/" + serverInfo.MaxPlayers);
lore.add(ChatColor.RESET + "");
lore.add(ChatColor.RESET + serverInfo.MOTD);
if (serverInfo.MOTD.contains("Restarting"))
{
lore.add(ChatColor.RESET + "" + ChatColor.YELLOW + "Get Ultra to spectate full servers!");
lore.add(ChatColor.RESET + C.Line + "This server will be open shortly!");
status = Material.IRON_BLOCK;
}
else if (serverInfo.CurrentPlayers >= serverInfo.MaxPlayers)
{
if (!Client.GetRank().Has(Rank.ULTRA))
lore.add(ChatColor.RESET + "" + ChatColor.YELLOW + "Get Ultra to spectate full servers!");
lore.add(openFull);
else
lore.add(ChatColor.RESET + "" + ChatColor.GREEN + "Click to spectate!");
lore.add(inProgress);
}
else
lore.add(ChatColor.RESET + "" + ChatColor.GREEN + "Click to spectate!");
lore.add(inProgress);
yellowCount++;
}
else
continue;
AddButton(slot, new ShopItem(status, ChatColor.UNDERLINE + "" + ChatColor.BOLD + "" + ChatColor.WHITE + "Server " + serverInfo.Name.substring(serverInfo.Name.indexOf('-') + 1), lore.toArray(new String[lore.size()]), Math.max(1, serverInfo.CurrentPlayers), false), new JoinServerButton(this, serverInfo.Name));
AddButton(slot, new ShopItem(status, ChatColor.UNDERLINE + "" + ChatColor.BOLD + "" + ChatColor.WHITE + "Server " + serverInfo.Name.substring(serverInfo.Name.indexOf('-') + 1), lore.toArray(new String[lore.size()]), Math.max(1, serverInfo.CurrentPlayers), false), new JoinServerButton(this, serverInfo));
}
while (greenCount < 3)
@ -122,8 +151,16 @@ public class ServerNpcPage extends ShopPageBase<ServerManager, ServerNpcShop>
BuildPage();
}
public void SelectServer(Player player, String serverName)
public void SelectServer(Player player, ServerInfo serverInfo)
{
Plugin.SelectServer(player, serverName);
int slots = Plugin.GetRequiredSlots(player, serverInfo.ServerType);
if (serverInfo.MaxPlayers - serverInfo.CurrentPlayers < slots)
{
PlayDenySound(player);
return;
}
Plugin.SelectServer(player, serverInfo);
}
}

View File

@ -1,11 +1,18 @@
package mineplex.hub.server.ui;
import java.util.List;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import mineplex.core.account.CoreClientManager;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.donation.DonationManager;
import mineplex.core.shop.ShopBase;
import mineplex.core.shop.page.ShopPageBase;
import mineplex.hub.party.Party;
import mineplex.hub.server.ServerInfo;
import mineplex.hub.server.ServerManager;
public class ServerNpcShop extends ShopBase<ServerManager>
@ -20,6 +27,32 @@ public class ServerNpcShop extends ShopBase<ServerManager>
{
return new ServerNpcPage(Plugin, this, ClientManager, DonationManager, Name, player, Name);
}
@Override
protected boolean CanOpenShop(Player player)
{
List<ServerInfo> serverInfos = Plugin.GetServerList(Name);
Party party = Plugin.getPartyManager().GetParty(player);
if (party != null && !player.getName().equalsIgnoreCase(party.GetLeader()))
{
player.playSound(player.getLocation(), Sound.ITEM_BREAK, 1, .6f);
player.sendMessage(F.main("Party", "Only Party Leaders can join games."));
player.sendMessage(F.main("Party", "Type " + C.cGreen + "/party leave" + C.cGray + " if you wish to leave your party."));
return false;
}
int slots = serverInfos.size() > 0 ? Plugin.GetRequiredSlots(player, serverInfos.get(0).ServerType) : 1;
for (ServerInfo serverInfo : serverInfos)
{
if (serverInfo.MaxPlayers - serverInfo.CurrentPlayers >= slots)
return true;
}
return false;
}
public void UpdatePages()
{

View File

@ -332,21 +332,23 @@ public class ArcadeManager extends MiniPlugin implements IRelation
@EventHandler
public void MessageMOTD(ServerListPingEvent event)
{
String extrainformation = "|" + _serverConfig.ServerType + "|" + (_game == null ? "Unknown" : _game.GetName()) + "|" + ((_game == null || _game.WorldData == null) ? "Unknown" : _game.WorldData.MapName);
if (_game == null || _game.GetState() == GameState.Recruit)
{
if (_game != null && _game.GetCountdown() != -1)
{
event.setMotd(ChatColor.GREEN + "Starting in " + _game.GetCountdown() + " Seconds");
event.setMotd(ChatColor.GREEN + "Starting in " + _game.GetCountdown() + " Seconds" + extrainformation);
}
else
{
event.setMotd(ChatColor.GREEN + "Recruiting");
event.setMotd(ChatColor.GREEN + "Recruiting" + extrainformation);
}
}
else
{
event.setMotd(ChatColor.YELLOW + "In Progress");
event.setMotd(ChatColor.YELLOW + "In Progress" + extrainformation);
}
}

View File

@ -447,13 +447,15 @@ public abstract class GameEngine<GameType extends IGame<ArenaType, PlayerType>,
@EventHandler
public void MessageMOTD(ServerListPingEvent event)
{
String extrainformation = "|Competitive|" + GetGameType() + (GetActiveGames().size() != 0 ? "|" + GetActiveGames().get(0).GetArena().GetName() : "");
if (ActiveGames.size() > 0 || GamesInSetup.size() > 0)
{
event.setMotd(ChatColor.YELLOW + "In Progress");
event.setMotd(ChatColor.YELLOW + "In Progress" + extrainformation);
}
else
{
event.setMotd(ChatColor.GREEN + "Recruiting");
event.setMotd(ChatColor.GREEN + "Recruiting" + extrainformation);
}
event.setMaxPlayers(10);