The behaviour of the provider NONE not just for the ServerConnectEvent

This commit is contained in:
Jaime Martinez Rincon 2017-01-24 22:01:35 +01:00
parent f461e2070d
commit a8f6c9a964
4 changed files with 21 additions and 20 deletions

View File

@ -13,29 +13,36 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
public abstract class ConnectionIntent { public abstract class ConnectionIntent {
protected ConnectionIntent(LobbyBalancer plugin, ProxiedPlayer player, ServerSection section) { protected ConnectionIntent(LobbyBalancer plugin, ProxiedPlayer player, ServerSection section) {
this(plugin, player, section, new ArrayList<>(section.getServers())); this(plugin, player, section.getProvider(), section);
}
protected ConnectionIntent(LobbyBalancer plugin, ProxiedPlayer player, ProviderType type, ServerSection section) {
this(plugin, player, type, section, new ArrayList<>(section.getServers()));
} }
protected ConnectionIntent(LobbyBalancer plugin, ProxiedPlayer player, ServerSection section, List<ServerInfo> servers) { protected ConnectionIntent(LobbyBalancer plugin, ProxiedPlayer player, ServerSection section, List<ServerInfo> servers) {
this(plugin, player, section.getProvider(), section, servers);
}
protected ConnectionIntent(LobbyBalancer plugin, ProxiedPlayer player, ProviderType provider, ServerSection section, List<ServerInfo> servers) {
if (servers == section.getServers()) { if (servers == section.getServers()) {
throw new IllegalStateException("The servers list parameter is the same object as the section servers list, this cannot happen"); throw new IllegalStateException("The servers list parameter is the same object as the section servers list, this cannot happen");
} }
ServerInfo target = this.findTarget(plugin, player, section, servers); if (section.getProvider() != ProviderType.NONE) {
Messager msgr = new Messager(player); ServerInfo target = this.fetchServer(plugin, player, section, provider, servers);
if (target != null) { if (target != null) {
msgr.send(ConfigEntries.CONNECTING_MESSAGE.get(), new Replacement("{server}", target.getName())); new Messager(player).send(ConfigEntries.CONNECTING_MESSAGE.get(), new Replacement("{server}", target.getName()));
this.connect(target); this.connect(target);
} else { } else {
msgr.send(ConfigEntries.FAILURE_MESSAGE.get()); new Messager(player).send(ConfigEntries.FAILURE_MESSAGE.get());
this.failure(); this.failure();
} }
} }
}
private ServerInfo findTarget(LobbyBalancer plugin, ProxiedPlayer player, ServerSection section, List<ServerInfo> servers) { final ServerInfo fetchServer(LobbyBalancer plugin, ProxiedPlayer player, ServerSection section, ProviderType provider, List<ServerInfo> servers) {
if (ConfigEntries.ASSIGN_TARGETS_ENABLED.get()) { if (ConfigEntries.ASSIGN_TARGETS_ENABLED.get()) {
if (ServerAssignRegistry.hasAssignedServer(player, section)) { if (ServerAssignRegistry.hasAssignedServer(player, section)) {
ServerInfo target = ServerAssignRegistry.getAssignedServer(player, section); ServerInfo target = ServerAssignRegistry.getAssignedServer(player, section);
@ -48,9 +55,7 @@ public abstract class ConnectionIntent {
} }
} }
ProviderType provider = section.getProvider();
int intents = ConfigEntries.SERVER_CHECK_ATTEMPTS.get(); int intents = ConfigEntries.SERVER_CHECK_ATTEMPTS.get();
while (intents-- >= 1) { while (intents-- >= 1) {
if (servers.size() == 0) return null; if (servers.size() == 0) return null;
if (servers.size() == 1) return servers.get(0); if (servers.size() == 1) return servers.get(0);

View File

@ -21,7 +21,7 @@ import java.util.concurrent.ThreadLocalRandom;
import static me.jaimemartz.lobbybalancer.LobbyBalancer.getPlayerCount; import static me.jaimemartz.lobbybalancer.LobbyBalancer.getPlayerCount;
public enum ProviderType { public enum ProviderType {
NONE(0, "Returns no server") { NONE(0, "Returns no server (dummy provider)") {
@Override @Override
public ServerInfo requestTarget(LobbyBalancer plugin, ServerSection section, List<ServerInfo> list, ProxiedPlayer player) { public ServerInfo requestTarget(LobbyBalancer plugin, ServerSection section, List<ServerInfo> list, ProxiedPlayer player) {
return null; return null;

View File

@ -52,10 +52,6 @@ public class ServerConnectListener implements Listener {
} }
} }
if (section.getProvider() == ProviderType.NONE) {
return;
}
new ConnectionIntent(plugin, player, section) { new ConnectionIntent(plugin, player, section) {
@Override @Override
public void connect(ServerInfo server) { public void connect(ServerInfo server) {

View File

@ -5,7 +5,7 @@
# Remember to set enabled under settings to true # Remember to set enabled under settings to true
# Providers of this plugin # Providers of this plugin
# NONE: Returns no server # NONE: Returns no server (dummy provider)
# DIRECT: Returns the only server in the list # DIRECT: Returns the only server in the list
# LOCALIZED: Returns the server that matches a region (testing) # LOCALIZED: Returns the server that matches a region (testing)
# LOWEST: Returns the server with the least players online # LOWEST: Returns the server with the least players online