From d4b3c5d461ab495a6f195119db88eb8133e670ca Mon Sep 17 00:00:00 2001 From: Jonathan Williams Date: Mon, 9 Sep 2013 01:28:35 -0700 Subject: [PATCH] Fixed memory leaks. Added in party joining for servers in Hub Modified server status's in server UI. --- .../core/account/CoreClientManager.java | 33 ++---- .../src/mineplex/core/pet/ui/PetTagPage.java | 12 +- .../src/mineplex/core/shop/ShopBase.java | 17 +-- .../core/shop/page/ConfirmationPage.java | 24 +++- .../Mineplex.Hub/src/mineplex/hub/Hub.java | 6 +- .../src/mineplex/hub/HubManager.java | 7 +- .../src/mineplex/hub/party/Party.java | 14 ++- .../src/mineplex/hub/party/PartyManager.java | 16 ++- .../src/mineplex/hub/server/ServerInfo.java | 3 + .../mineplex/hub/server/ServerManager.java | 107 +++++++++++++++++- .../src/mineplex/hub/server/ServerSorter.java | 17 ++- .../hub/server/ui/JoinServerButton.java | 9 +- .../mineplex/hub/server/ui/ServerNpcPage.java | 79 +++++++++---- .../mineplex/hub/server/ui/ServerNpcShop.java | 33 ++++++ .../nautilus/game/arcade/ArcadeManager.java | 8 +- .../nautilus/game/core/engine/GameEngine.java | 6 +- 16 files changed, 298 insertions(+), 93 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClientManager.java b/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClientManager.java index 4a2207da5..2231cf111 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClientManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClientManager.java @@ -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 _allClients; - private HashMap _clientList; + private NautHashMap _clientList; private HashSet _dontRemoveList; private NautHashMap> _cacheList; @@ -51,7 +50,7 @@ public class CoreClientManager implements Listener _plugin = plugin; _repository = new AccountRepository(webServer); _allClients = new HashSet(); - _clientList = new HashMap(); + _clientList = new NautHashMap(); _dontRemoveList = new HashSet(); _cacheList = new NautHashMap>(); @@ -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()); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/pet/ui/PetTagPage.java b/Plugins/Mineplex.Core/src/mineplex/core/pet/ui/PetTagPage.java index e6731b890..a3145821a 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/pet/ui/PetTagPage.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/pet/ui/PetTagPage.java @@ -27,6 +27,8 @@ public class PetTagPage extends ShopPageBase super(plugin, shop, clientManager, donationManager, name, player, 3); BuildPage(); + + Player.setLevel(5); } @Override @@ -38,6 +40,14 @@ public class PetTagPage extends ShopPageBase 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 PlayDenySound(Player); Player.closeInventory(); - Shop.ResetPlayer(Player); return; } @@ -76,7 +85,6 @@ public class PetTagPage extends ShopPageBase Plugin.GetRepository().RemovePetNameTag(Player.getName()); Player.closeInventory(); - Shop.ResetPlayer(Player); } public void SetTagName(String tagName) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/shop/ShopBase.java b/Plugins/Mineplex.Core/src/mineplex/core/shop/ShopBase.java index 16971a97a..609be56c8 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/shop/ShopBase.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/shop/ShopBase.java @@ -91,6 +91,9 @@ public abstract class ShopBase 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 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 implements Listene if (PlayerPageMap.containsKey(player.getName())) { PlayerPageMap.get(player.getName()).PlayerClosed(); - } + } SetCurrentPageForPlayer(player, page); - player.closeInventory(); - player.openInventory(page); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/shop/page/ConfirmationPage.java b/Plugins/Mineplex.Core/src/mineplex/core/shop/page/ConfirmationPage.java index a3a636124..8fc01542f 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/shop/page/ConfirmationPage.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/shop/page/ConfirmationPage.java @@ -259,14 +259,26 @@ public class ConfirmationPage= 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); } } diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java b/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java index d74b1b053..c059752a2 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java @@ -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); diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java index fc07a9fce..51d218e62 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java @@ -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 private HashSet _mobs = new HashSet(); - 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 new Dragon(this); new MountManager(this); - _partyManager = new PartyManager(this); + _partyManager = partyManager; _tutorialManager = new TutorialManager(this, donationManager, taskManager, _textCreator); DragonTextB = GetDragonText(); diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/party/Party.java b/Plugins/Mineplex.Hub/src/mineplex/hub/party/Party.java index 5ffc6fd7a..d96455ab9 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/party/Party.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/party/Party.java @@ -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); + } } } diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/party/PartyManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/party/PartyManager.java index ec6881762..6bbf4ca98 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/party/PartyManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/party/PartyManager.java @@ -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 _parties = new HashSet(); - 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) { diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerInfo.java b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerInfo.java index 4787f1378..688cc034a 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerInfo.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerInfo.java @@ -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; } \ No newline at end of file diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerManager.java index ee5c77503..32add05cf 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerManager.java @@ -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> _serverNpcMap = new NautHashMap>(); private NautHashMap _serverNpcShopMap = new NautHashMap(); @@ -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; + } } diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerSorter.java b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerSorter.java index 16a6dec4b..c93d7265b 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerSorter.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerSorter.java @@ -4,6 +4,13 @@ import java.util.Comparator; public class ServerSorter implements Comparator { + 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 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; diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/JoinServerButton.java b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/JoinServerButton.java index 96a134aeb..2670b67d2 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/JoinServerButton.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/JoinServerButton.java @@ -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); } } diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/ServerNpcPage.java b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/ServerNpcPage.java index 0f56b6978..e4b7b38fe 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/ServerNpcPage.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/ServerNpcPage.java @@ -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 @Override protected void BuildPage() - { - List serverList = Plugin.GetServerList(_serverNpcKey); - Collections.sort(serverList, new ServerSorter()); + { + List 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 lore = new ArrayList(); 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 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); } } diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/ServerNpcShop.java b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/ServerNpcShop.java index 421ba2482..7871d1d13 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/ServerNpcShop.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/ServerNpcShop.java @@ -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 @@ -20,6 +27,32 @@ public class ServerNpcShop extends ShopBase { return new ServerNpcPage(Plugin, this, ClientManager, DonationManager, Name, player, Name); } + + @Override + protected boolean CanOpenShop(Player player) + { + List 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() { diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java index 1dc548604..e0b4305d7 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java @@ -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); } } diff --git a/Plugins/Nautilus.Game.Core/src/nautilus/game/core/engine/GameEngine.java b/Plugins/Nautilus.Game.Core/src/nautilus/game/core/engine/GameEngine.java index 7705eaae0..11571b3a3 100644 --- a/Plugins/Nautilus.Game.Core/src/nautilus/game/core/engine/GameEngine.java +++ b/Plugins/Nautilus.Game.Core/src/nautilus/game/core/engine/GameEngine.java @@ -447,13 +447,15 @@ public abstract class GameEngine, @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);