Possibly fix issues
This commit is contained in:
parent
d931f38b18
commit
69fe7ef777
|
@ -628,6 +628,7 @@ public class FriendManager extends MiniDbClientPlugin<List<FriendStatus>>
|
|||
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<List<FriendStatus>>
|
|||
}
|
||||
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<List<FriendStatus>>
|
|||
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<List<FriendStatus>>
|
|||
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)
|
||||
|
|
|
@ -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<String> 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.
|
||||
*/
|
||||
|
@ -458,104 +420,58 @@ public class NextBestGameManager implements Listener
|
|||
private MinecraftServer findBestGame(boolean joinFull, Party party)
|
||||
{
|
||||
List<MinecraftServer> servers = Lists.newArrayList(ServerManager.getServerRepository(_region).getServersByGroup(_serverGroup));
|
||||
MinecraftServer server = null;
|
||||
List<MinecraftServer> possible = Lists.newArrayList();
|
||||
Collections.sort(servers, (a, b) -> b.getPlayerCount() - a.getPlayerCount());
|
||||
List<MinecraftServer> 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 (!joinFull || info.getJoinable() != GameJoinStatus.RANKS_ONLY)
|
||||
{
|
||||
if (countdown > acceptableCountdown || motd.contains("Recruiting"))
|
||||
{
|
||||
possible.add(other);
|
||||
}
|
||||
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))
|
||||
{
|
||||
server = other;
|
||||
case WAITING:
|
||||
case VOTING:
|
||||
break;
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (party != null)
|
||||
{
|
||||
int newPlayerCount = playerCount + party.getSize();
|
||||
|
||||
if (newPlayerCount >= other.getMaxPlayerCount())
|
||||
case STARTING:
|
||||
if (info.getTimer() < acceptableCountdown)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
playerCount = newPlayerCount;
|
||||
break;
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (other.getMaxPlayerCount() - playerCount > LOWEST_SOLO_PLAYERCOUNT)
|
||||
|
||||
int required = party == null ? 1 : party.getSize();
|
||||
|
||||
if (other.getPlayerCount() + required <= other.getMaxPlayerCount())
|
||||
{
|
||||
possible.add(other);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (highest < playerCount)
|
||||
{
|
||||
highest = playerCount;
|
||||
}
|
||||
else
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
server = other;
|
||||
}
|
||||
if (server == null)
|
||||
{
|
||||
if (possible.size() <= 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
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> ");
|
||||
|
|
|
@ -119,7 +119,11 @@ public class VotingManager extends ListenerComponent implements Lifetimed
|
|||
UtilPlayer.closeInventoryIfOpen(player);
|
||||
}
|
||||
|
||||
if (_manager.GetGame() != null)
|
||||
{
|
||||
_manager.GetLobby().displayGame(_manager.GetGame());
|
||||
}
|
||||
|
||||
_manager.GetLobby().displayWaiting(false);
|
||||
|
||||
_currentVote.onEnd();
|
||||
|
|
Loading…
Reference in New Issue