diff --git a/Plugins/Mineplex.Core/src/mineplex/core/friend/FriendManager.java b/Plugins/Mineplex.Core/src/mineplex/core/friend/FriendManager.java index 6b5c1c23c..66d68d81c 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/friend/FriendManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/friend/FriendManager.java @@ -628,6 +628,7 @@ public class FriendManager extends MiniDbClientPlugin> TextComponent message = new TextComponent(""); boolean online = friend.Online && friend.Visibility != FriendVisibility.INVISIBLE; boolean canJoin = canJoin(friend.ServerName, isStaff) && friend.Visibility == FriendVisibility.SHOWN; + boolean clans = isClans(friend.ServerName); switch (type) { @@ -707,7 +708,7 @@ public class FriendManager extends MiniDbClientPlugin> } else { - TextComponent server = new TextComponent("Private Staff Server"); + TextComponent server = new TextComponent(clans ? "Clans" : "Private Staff Server"); server.setColor(ChatColor.YELLOW); message.addExtra(server); } @@ -831,7 +832,7 @@ public class FriendManager extends MiniDbClientPlugin> return canJoin(serverName, ClientManager.Get(player).hasPermission(Perm.JOIN_STAFF)); } - public boolean canJoin(String serverName, boolean isPlayerStaff) + private boolean canJoin(String serverName, boolean isPlayerStaff) { if (serverName == null) { @@ -843,7 +844,12 @@ public class FriendManager extends MiniDbClientPlugin> return isPlayerStaff; } - return !serverName.startsWith("CUST-"); + return !serverName.startsWith("CUST-") && !isClans(serverName); + } + + private boolean isClans(String serverName) + { + return serverName != null && serverName.startsWith("Clans-"); } public void updatePlayerStatus(UUID playerUUID, PlayerStatus status) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/NextBestGameManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/NextBestGameManager.java index 729bcc0f9..f34e3c3fc 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/NextBestGameManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/NextBestGameManager.java @@ -1,6 +1,6 @@ package nautilus.game.arcade.managers; -import java.util.Collections; +import java.util.Comparator; import java.util.List; import java.util.Map; import java.util.UUID; @@ -24,11 +24,13 @@ import org.bukkit.scheduler.BukkitRunnable; import com.google.common.collect.Lists; import com.google.common.collect.Maps; +import com.google.gson.JsonSyntaxException; -import mineplex.core.Managers; import mineplex.core.common.util.C; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilServer; +import mineplex.core.game.status.GameInfo; +import mineplex.core.game.status.GameInfo.GameJoinStatus; import mineplex.core.itemstack.ItemBuilder; import mineplex.core.party.Lang; import mineplex.core.party.Party; @@ -88,51 +90,11 @@ public class NextBestGameManager implements Listener */ private static final int INVENTORY_SLOT = 2; - /** - * Games that have a hard set cap, whether it be via Map or Actual, of the maximum players that can be in a game. - * This is designed so that the best algorithm will correctly allow full servers to be calculated. - */ - private static final List FULL_CAP = Lists.newArrayList( - "DominateTDM", - "Skywars", - "ChampionsCTF", - "MCLeague", - "UHC", - "Halloween", - "Dominate", - "SpeedBuilders", - "Build", - "Gladiators", - "SkywarsTeams", - "MineStrike" - ); - - /** - * The maximum difference a maxPlayerCount - onlinePlayerCount may be for serverGroups which are in FULL_CAP - */ - private static final int FULL_CAP_PLAYERCOUNT = 2; - - /** - * This is the lowest a countdown may be at in order to be a "best" server for non partied players - */ - private static final int LOWEST_SOLO_COUNTDOWN = 10; - /** * This is the lowest a countdown may be in order to be taken into account in the case of the "best" server not being found for non partied players. */ private static final int ACCEPTABLE_SOLO_COUNTDOWN = 5; - /** - * This is the lowest a server's player count difference (max - on) may be for solo (non partied) player - * Note: This is not the ACTUAL player count of the server, this is just the most ideal player count (a game being N away from being full) - */ - private static final int LOWEST_SOLO_PLAYERCOUNT = 3; - - /** - * This is the lowest a countdown may be at in order to be a "best" server for partied players - */ - private static final int LOWEST_PARTY_COUNTDOWN = 30; - /** * This is the lowest a countdown may be in order to be taken into account in the case of the "best" server not being found for partied players. */ @@ -140,8 +102,8 @@ public class NextBestGameManager implements Listener /* - * Text Components - */ + * Text Components + */ private static final TextComponent DONT_WORRY = new TextComponent("You are out of the game! "); private static final TextComponent CLICK_HERE = new TextComponent("Click Here"); @@ -458,104 +420,58 @@ public class NextBestGameManager implements Listener private MinecraftServer findBestGame(boolean joinFull, Party party) { List servers = Lists.newArrayList(ServerManager.getServerRepository(_region).getServersByGroup(_serverGroup)); - MinecraftServer server = null; List possible = Lists.newArrayList(); - Collections.sort(servers, (a, b) -> b.getPlayerCount() - a.getPlayerCount()); - List buffer = Lists.newArrayList(servers); + servers.sort((a, b) -> b.getPlayerCount() - a.getPlayerCount()); - if (FULL_CAP.contains(_serverGroup)) - { - servers.stream().filter(other -> other.getMaxPlayerCount() - other.getPlayerCount() <= FULL_CAP_PLAYERCOUNT).forEach(buffer::remove); - } - - servers = buffer; - - int highest = Integer.MIN_VALUE; - int lowestCountdown = party == null ? LOWEST_SOLO_COUNTDOWN : LOWEST_PARTY_COUNTDOWN; int acceptableCountdown = party == null ? ACCEPTABLE_SOLO_COUNTDOWN : ACCEPTABLE_PARTY_COUNTDOWN; for (MinecraftServer other : servers) { - int playerCount = other.getPlayerCount(); - String motd = other.getMotd(); + GameInfo info; - if (isInUnjoinableState(motd)) + try + { + info = GameInfo.fromString(other.getMotd()); + } + catch (JsonSyntaxException ex) { continue; } - if (motd.split("\\|").length > 0) + if (info.getJoinable() != GameJoinStatus.OPEN) { - motd = motd.split("\\|")[0]; - } - - int countdown = getCountdown(motd); - - if (countdown < lowestCountdown) - { - if (countdown > acceptableCountdown || motd.contains("Recruiting")) + if (!joinFull || info.getJoinable() != GameJoinStatus.RANKS_ONLY) { - possible.add(other); + continue; } - continue; } - int tooFull = other.getMaxPlayerCount() - (playerCount + (party == null ? 0 : party.getSize())); - - if (tooFull <= FULL_CAP_PLAYERCOUNT) + switch (info.getStatus()) { - if (tooFull == FULL_CAP_PLAYERCOUNT) - { - if (joinFull && !FULL_CAP.contains(_serverGroup)) + case WAITING: + case VOTING: + break; + case STARTING: + if (info.getTimer() < acceptableCountdown) { - server = other; - break; + continue; } - } - continue; - } - - if (party != null) - { - int newPlayerCount = playerCount + party.getSize(); - - if (newPlayerCount >= other.getMaxPlayerCount()) - { + break; + default: continue; - } - - playerCount = newPlayerCount; - } - else - { - if (other.getMaxPlayerCount() - playerCount > LOWEST_SOLO_PLAYERCOUNT) - { - possible.add(other); - continue; - } } - if (highest < playerCount) - { - highest = playerCount; - } - else - { - continue; - } + int required = party == null ? 1 : party.getSize(); - server = other; - } - if (server == null) - { - if (possible.size() <= 0) + if (other.getPlayerCount() + required <= other.getMaxPlayerCount()) { - return null; + possible.add(other); } - server = possible.get(0); } - return server; + return possible.stream() + .max(Comparator.comparingInt(MinecraftServer::getPlayerCount)) + .orElse(null); } private void sendToServer(Player player, MinecraftServer server) @@ -589,26 +505,6 @@ public class NextBestGameManager implements Listener player.getInventory().setItem(INVENTORY_SLOT, GO_TO_NEXT_ITEM); } - private int getCountdown(String motd) - { - int countdown; - try - { - countdown = Integer.parseInt(motd.split(" ")[2]); - } - catch (Exception e) - { - countdown = -1; - } - return countdown; - } - - private boolean isInUnjoinableState(String motd) - { - return (motd == null || motd.isEmpty() || - !(motd.contains("Starting") || motd.contains("Recruiting") || motd.contains("Waiting") || motd.contains("Open in") || motd.contains("Generating"))); - } - private void sendWarning(Player player) { TextComponent message = new TextComponent("Game> "); diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/voting/VotingManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/voting/VotingManager.java index 77b80eea3..24596994d 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/voting/VotingManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/voting/VotingManager.java @@ -119,7 +119,11 @@ public class VotingManager extends ListenerComponent implements Lifetimed UtilPlayer.closeInventoryIfOpen(player); } - _manager.GetLobby().displayGame(_manager.GetGame()); + if (_manager.GetGame() != null) + { + _manager.GetLobby().displayGame(_manager.GetGame()); + } + _manager.GetLobby().displayWaiting(false); _currentVote.onEnd();