mirror of
https://github.com/BGHDDevelopment/PlayerBalancer.git
synced 2024-11-05 02:19:48 +01:00
Added an option to exclude the server the player is being kicked from for the connection intent
This commit is contained in:
parent
b06d0d5e7b
commit
cfc104fb11
@ -28,6 +28,7 @@ public class ConfigEntries implements ConfigEntryHolder {
|
||||
public static final ConfigEntry<List<String>> RECONNECT_KICK_REASONS = new ConfigEntry<>(0, "settings.reconnect-kick.reasons", Collections.emptyList());
|
||||
public static final ConfigEntry<Boolean> RECONNECT_KICK_PRINT_INFO = new ConfigEntry<>(0, "settings.reconnect-kick.print-info", false);
|
||||
public static final ConfigEntry<List<String>> RECONNECT_KICK_IGNORED_SECTIONS = new ConfigEntry<>(0, "settings.reconnect-kick.ignored", Collections.emptyList());
|
||||
public static final ConfigEntry<Boolean> RECONNECT_KICK_EXCLUDE_FROM = new ConfigEntry<>(0, "settings.reconnect-kick.exclude-from", true);
|
||||
public static final ConfigEntry<String> RECONNECT_KICK_MESSAGE = new ConfigEntry<>(0, "settings.reconnect-kick.message", "&cYou have been kicked from &a{from} &cand you are being moved to &a{to}&c, reason: &a{reason}");
|
||||
|
||||
public static final ConfigEntry<Boolean> FALLBACK_COMMAND_ENABLED = new ConfigEntry<>(0, "settings.fallback-command.enabled", true);
|
||||
|
@ -15,7 +15,15 @@ import java.util.List;
|
||||
public abstract class ConnectionIntent {
|
||||
|
||||
protected ConnectionIntent(LobbyBalancer plugin, ProxiedPlayer player, ServerSection section) {
|
||||
ServerInfo target = this.findTarget(plugin, player, section);
|
||||
this(plugin, player, section, new ArrayList<>(section.getServers()));
|
||||
}
|
||||
|
||||
protected ConnectionIntent(LobbyBalancer plugin, ProxiedPlayer player, ServerSection section, List<ServerInfo> servers) {
|
||||
if (servers == section.getServers()) {
|
||||
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);
|
||||
Messager msgr = new Messager(player);
|
||||
|
||||
if (target != null) {
|
||||
@ -27,7 +35,7 @@ public abstract class ConnectionIntent {
|
||||
}
|
||||
}
|
||||
|
||||
private ServerInfo findTarget(LobbyBalancer plugin, ProxiedPlayer player, ServerSection section) {
|
||||
private ServerInfo findTarget(LobbyBalancer plugin, ProxiedPlayer player, ServerSection section, List<ServerInfo> servers) {
|
||||
if (ConfigEntries.ASSIGN_TARGETS_ENABLED.get()) {
|
||||
if (ServerAssignRegistry.hasAssignedServer(player, section)) {
|
||||
ServerInfo target = ServerAssignRegistry.getAssignedServer(player, section);
|
||||
@ -42,8 +50,6 @@ public abstract class ConnectionIntent {
|
||||
|
||||
ProviderType provider = section.getProvider();
|
||||
int intents = ConfigEntries.SERVER_CHECK_ATTEMPTS.get();
|
||||
List<ServerInfo> servers = new ArrayList<>();
|
||||
servers.addAll(section.getServers());
|
||||
|
||||
while (intents-- >= 1) {
|
||||
if (servers.size() == 0) return null;
|
||||
@ -67,4 +73,4 @@ public abstract class ConnectionIntent {
|
||||
public void failure() {
|
||||
//Nothing to do
|
||||
}
|
||||
}
|
||||
}
|
@ -16,6 +16,8 @@ import net.md_5.bungee.config.Configuration;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
import net.md_5.bungee.event.EventPriority;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
@ -90,7 +92,15 @@ public class ServerKickListener implements Listener {
|
||||
try {
|
||||
ServerSection target = task.call();
|
||||
if (target != null) {
|
||||
new ConnectionIntent(plugin, player, target) {
|
||||
//Do not try to reconnect to the server we are kicked from
|
||||
List<ServerInfo> servers = new ArrayList<>();
|
||||
servers.addAll(target.getServers());
|
||||
|
||||
if (ConfigEntries.RECONNECT_KICK_EXCLUDE_FROM.get()) {
|
||||
servers.remove(from);
|
||||
}
|
||||
|
||||
new ConnectionIntent(plugin, player, target, servers) {
|
||||
@Override
|
||||
public void connect(ServerInfo server) {
|
||||
Messager msgr = new Messager(player);
|
||||
@ -111,4 +121,4 @@ public class ServerKickListener implements Listener {
|
||||
//Nothing to do
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -8,6 +8,7 @@ import net.md_5.bungee.config.Configuration;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.regex.Matcher;
|
||||
@ -163,7 +164,7 @@ public class ServerSection {
|
||||
}
|
||||
|
||||
public List<ServerInfo> getServers() {
|
||||
return servers;
|
||||
return Collections.unmodifiableList(servers);
|
||||
}
|
||||
|
||||
public ProviderType getProvider() {
|
||||
|
@ -60,6 +60,9 @@ settings:
|
||||
# Sections where this feature is ignored
|
||||
ignored: []
|
||||
|
||||
# This will make it so that the server the player is kicked from will be excluded
|
||||
exclude-from: true
|
||||
|
||||
# This prints info every time a player gets kicked telling you the reason and if it matches the reasons
|
||||
print-info: false
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user