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("");
|
TextComponent message = new TextComponent("");
|
||||||
boolean online = friend.Online && friend.Visibility != FriendVisibility.INVISIBLE;
|
boolean online = friend.Online && friend.Visibility != FriendVisibility.INVISIBLE;
|
||||||
boolean canJoin = canJoin(friend.ServerName, isStaff) && friend.Visibility == FriendVisibility.SHOWN;
|
boolean canJoin = canJoin(friend.ServerName, isStaff) && friend.Visibility == FriendVisibility.SHOWN;
|
||||||
|
boolean clans = isClans(friend.ServerName);
|
||||||
|
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
|
@ -707,7 +708,7 @@ public class FriendManager extends MiniDbClientPlugin<List<FriendStatus>>
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
TextComponent server = new TextComponent("Private Staff Server");
|
TextComponent server = new TextComponent(clans ? "Clans" : "Private Staff Server");
|
||||||
server.setColor(ChatColor.YELLOW);
|
server.setColor(ChatColor.YELLOW);
|
||||||
message.addExtra(server);
|
message.addExtra(server);
|
||||||
}
|
}
|
||||||
|
@ -831,7 +832,7 @@ public class FriendManager extends MiniDbClientPlugin<List<FriendStatus>>
|
||||||
return canJoin(serverName, ClientManager.Get(player).hasPermission(Perm.JOIN_STAFF));
|
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)
|
if (serverName == null)
|
||||||
{
|
{
|
||||||
|
@ -843,7 +844,12 @@ public class FriendManager extends MiniDbClientPlugin<List<FriendStatus>>
|
||||||
return isPlayerStaff;
|
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)
|
public void updatePlayerStatus(UUID playerUUID, PlayerStatus status)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package nautilus.game.arcade.managers;
|
package nautilus.game.arcade.managers;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
@ -24,11 +24,13 @@ import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.collect.Maps;
|
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.C;
|
||||||
import mineplex.core.common.util.F;
|
import mineplex.core.common.util.F;
|
||||||
import mineplex.core.common.util.UtilServer;
|
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.itemstack.ItemBuilder;
|
||||||
import mineplex.core.party.Lang;
|
import mineplex.core.party.Lang;
|
||||||
import mineplex.core.party.Party;
|
import mineplex.core.party.Party;
|
||||||
|
@ -88,51 +90,11 @@ public class NextBestGameManager implements Listener
|
||||||
*/
|
*/
|
||||||
private static final int INVENTORY_SLOT = 2;
|
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.
|
* 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;
|
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.
|
* 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 DONT_WORRY = new TextComponent("You are out of the game! ");
|
||||||
private static final TextComponent CLICK_HERE = new TextComponent("Click Here");
|
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)
|
private MinecraftServer findBestGame(boolean joinFull, Party party)
|
||||||
{
|
{
|
||||||
List<MinecraftServer> servers = Lists.newArrayList(ServerManager.getServerRepository(_region).getServersByGroup(_serverGroup));
|
List<MinecraftServer> servers = Lists.newArrayList(ServerManager.getServerRepository(_region).getServersByGroup(_serverGroup));
|
||||||
MinecraftServer server = null;
|
|
||||||
List<MinecraftServer> possible = Lists.newArrayList();
|
List<MinecraftServer> possible = Lists.newArrayList();
|
||||||
Collections.sort(servers, (a, b) -> b.getPlayerCount() - a.getPlayerCount());
|
servers.sort((a, b) -> b.getPlayerCount() - a.getPlayerCount());
|
||||||
List<MinecraftServer> buffer = Lists.newArrayList(servers);
|
|
||||||
|
|
||||||
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;
|
int acceptableCountdown = party == null ? ACCEPTABLE_SOLO_COUNTDOWN : ACCEPTABLE_PARTY_COUNTDOWN;
|
||||||
|
|
||||||
for (MinecraftServer other : servers)
|
for (MinecraftServer other : servers)
|
||||||
{
|
{
|
||||||
int playerCount = other.getPlayerCount();
|
GameInfo info;
|
||||||
String motd = other.getMotd();
|
|
||||||
|
|
||||||
if (isInUnjoinableState(motd))
|
try
|
||||||
|
{
|
||||||
|
info = GameInfo.fromString(other.getMotd());
|
||||||
|
}
|
||||||
|
catch (JsonSyntaxException ex)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (motd.split("\\|").length > 0)
|
if (info.getJoinable() != GameJoinStatus.OPEN)
|
||||||
{
|
{
|
||||||
motd = motd.split("\\|")[0];
|
if (!joinFull || info.getJoinable() != GameJoinStatus.RANKS_ONLY)
|
||||||
}
|
|
||||||
|
|
||||||
int countdown = getCountdown(motd);
|
|
||||||
|
|
||||||
if (countdown < lowestCountdown)
|
|
||||||
{
|
|
||||||
if (countdown > acceptableCountdown || motd.contains("Recruiting"))
|
|
||||||
{
|
{
|
||||||
possible.add(other);
|
continue;
|
||||||
}
|
}
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int tooFull = other.getMaxPlayerCount() - (playerCount + (party == null ? 0 : party.getSize()));
|
switch (info.getStatus())
|
||||||
|
|
||||||
if (tooFull <= FULL_CAP_PLAYERCOUNT)
|
|
||||||
{
|
{
|
||||||
if (tooFull == FULL_CAP_PLAYERCOUNT)
|
case WAITING:
|
||||||
{
|
case VOTING:
|
||||||
if (joinFull && !FULL_CAP.contains(_serverGroup))
|
break;
|
||||||
|
case STARTING:
|
||||||
|
if (info.getTimer() < acceptableCountdown)
|
||||||
{
|
{
|
||||||
server = other;
|
continue;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
continue;
|
default:
|
||||||
}
|
|
||||||
|
|
||||||
if (party != null)
|
|
||||||
{
|
|
||||||
int newPlayerCount = playerCount + party.getSize();
|
|
||||||
|
|
||||||
if (newPlayerCount >= other.getMaxPlayerCount())
|
|
||||||
{
|
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
playerCount = newPlayerCount;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (other.getMaxPlayerCount() - playerCount > LOWEST_SOLO_PLAYERCOUNT)
|
|
||||||
{
|
|
||||||
possible.add(other);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (highest < playerCount)
|
int required = party == null ? 1 : party.getSize();
|
||||||
{
|
|
||||||
highest = playerCount;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
server = other;
|
if (other.getPlayerCount() + required <= other.getMaxPlayerCount())
|
||||||
}
|
|
||||||
if (server == null)
|
|
||||||
{
|
|
||||||
if (possible.size() <= 0)
|
|
||||||
{
|
{
|
||||||
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)
|
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);
|
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)
|
private void sendWarning(Player player)
|
||||||
{
|
{
|
||||||
TextComponent message = new TextComponent("Game> ");
|
TextComponent message = new TextComponent("Game> ");
|
||||||
|
|
|
@ -119,7 +119,11 @@ public class VotingManager extends ListenerComponent implements Lifetimed
|
||||||
UtilPlayer.closeInventoryIfOpen(player);
|
UtilPlayer.closeInventoryIfOpen(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
_manager.GetLobby().displayGame(_manager.GetGame());
|
if (_manager.GetGame() != null)
|
||||||
|
{
|
||||||
|
_manager.GetLobby().displayGame(_manager.GetGame());
|
||||||
|
}
|
||||||
|
|
||||||
_manager.GetLobby().displayWaiting(false);
|
_manager.GetLobby().displayWaiting(false);
|
||||||
|
|
||||||
_currentVote.onEnd();
|
_currentVote.onEnd();
|
||||||
|
|
Loading…
Reference in New Issue