mirror of
https://github.com/BGHDDevelopment/PlayerBalancer.git
synced 2024-11-27 05:05:19 +01:00
Implemented section position
This commit is contained in:
parent
d37005ce3c
commit
5fba98449e
@ -31,8 +31,16 @@ public class FallbackCommand extends Command {
|
||||
ServerSection section = plugin.getSectionManager().getByServer(player.getServer().getInfo());
|
||||
|
||||
if (section != null) {
|
||||
/* TODO REFERENCE TO ServerKickListener
|
||||
if (ConfigEntries.FALLBACK_COMMAND_RESTRICTED.get() && section.isPrincipal()) {
|
||||
msgr.send(ConfigEntries.UNAVAILABLE_MESSAGE.get());
|
||||
return null;
|
||||
}
|
||||
*/
|
||||
|
||||
if ((ConfigEntries.FALLBACK_COMMAND_IGNORED_SECTIONS.get()).contains(section.getName())) {
|
||||
msgr.send(ConfigEntries.UNAVAILABLE_MESSAGE.get());
|
||||
return null;
|
||||
}
|
||||
|
||||
if (ConfigEntries.FALLBACK_COMMAND_ARGUMENTS.get() && args.length == 1) {
|
||||
@ -63,12 +71,9 @@ public class FallbackCommand extends Command {
|
||||
ServerSection section = callable.call();
|
||||
if (section != null) {
|
||||
ConnectionIntent.connect(plugin, player, section);
|
||||
} else {
|
||||
msgr.send(ConfigEntries.UNAVAILABLE_MESSAGE.get());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
msgr.send(ConfigEntries.FAILURE_MESSAGE.get());
|
||||
//Nothing to do
|
||||
}
|
||||
} else {
|
||||
msgr.send(ChatColor.RED + "This command can only be executed by a player");
|
||||
|
@ -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_RESTRICTED = new ConfigEntry<>(0, "settings.reconnect-kick.restricted", true);
|
||||
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}");
|
||||
|
||||
@ -36,8 +37,8 @@ public class ConfigEntries implements ConfigEntryHolder {
|
||||
public static final ConfigEntry<List<String>> FALLBACK_COMMAND_ALIASES = new ConfigEntry<>(0, "settings.fallback-command.aliases", Arrays.asList("lobby", "hub", "back"));
|
||||
public static final ConfigEntry<String> FALLBACK_COMMAND_PERMISSION = new ConfigEntry<>(0, "settings.fallback-command.permission", "");
|
||||
public static final ConfigEntry<List<String>> FALLBACK_COMMAND_IGNORED_SECTIONS = new ConfigEntry<>(0, "settings.fallback-command.ignored", Collections.emptyList());
|
||||
public static final ConfigEntry<Boolean> FALLBACK_COMMAND_RESTRICTED = new ConfigEntry<>(0, "settings.fallback-command.restricted", true);
|
||||
public static final ConfigEntry<Boolean> FALLBACK_COMMAND_ARGUMENTS = new ConfigEntry<>(0, "settings.fallback-command.arguments", true);
|
||||
|
||||
public static final ConfigEntry<Boolean> AUTO_RELOAD_ENABLED = new ConfigEntry<>(0, "settings.auto-reload", true);
|
||||
public static final ConfigEntry<Boolean> REDIS_BUNGEE_ENABLED = new ConfigEntry<>(0, "settings.redis-bungee", false);
|
||||
public static final ConfigEntry<Boolean> ASSIGN_TARGETS_ENABLED = new ConfigEntry<>(0, "settings.assign-targets", false);
|
||||
|
@ -19,18 +19,6 @@ public abstract class ConnectionIntent {
|
||||
protected final ProxiedPlayer player;
|
||||
protected final ServerSection section;
|
||||
|
||||
public ConnectionIntent(LobbyBalancer plugin, ProxiedPlayer player, ServerSection section) {
|
||||
this(plugin, player, section.getProvider(), section);
|
||||
}
|
||||
|
||||
public ConnectionIntent(LobbyBalancer plugin, ProxiedPlayer player, ProviderType type, ServerSection section) {
|
||||
this(plugin, player, type, section, new ArrayList<>(section.getServers()));
|
||||
}
|
||||
|
||||
public ConnectionIntent(LobbyBalancer plugin, ProxiedPlayer player, ServerSection section, List<ServerInfo> servers) {
|
||||
this(plugin, player, section.getProvider(), section, servers);
|
||||
}
|
||||
|
||||
public ConnectionIntent(LobbyBalancer plugin, ProxiedPlayer player, ProviderType provider, ServerSection section, List<ServerInfo> servers) {
|
||||
this.plugin = plugin;
|
||||
this.player = player;
|
||||
@ -52,6 +40,18 @@ public abstract class ConnectionIntent {
|
||||
}
|
||||
}
|
||||
|
||||
public ConnectionIntent(LobbyBalancer plugin, ProxiedPlayer player, ServerSection section) {
|
||||
this(plugin, player, section.getProvider(), section);
|
||||
}
|
||||
|
||||
public ConnectionIntent(LobbyBalancer plugin, ProxiedPlayer player, ProviderType type, ServerSection section) {
|
||||
this(plugin, player, type, section, new ArrayList<>(section.getServers()));
|
||||
}
|
||||
|
||||
public ConnectionIntent(LobbyBalancer plugin, ProxiedPlayer player, ServerSection section, List<ServerInfo> servers) {
|
||||
this(plugin, player, section.getProvider(), section, servers);
|
||||
}
|
||||
|
||||
private ServerInfo fetchServer(LobbyBalancer plugin, ProxiedPlayer player, ServerSection section, ProviderType provider, List<ServerInfo> servers) {
|
||||
if (ConfigEntries.ASSIGN_TARGETS_ENABLED.get()) {
|
||||
if (ServerAssignRegistry.hasAssignedServer(player, section)) {
|
||||
|
@ -30,41 +30,39 @@ public class ServerConnectListener implements Listener {
|
||||
|
||||
ServerSection section = plugin.getSectionManager().getByServer(target);
|
||||
|
||||
if (section == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (PlayerLocker.isLocked(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (section.getServers().contains(target)) {
|
||||
if (section.isDummy()) {
|
||||
if (section != null) {
|
||||
if (PlayerLocker.isLocked(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (player.hasPermission("lobbybalancer.bypass")) {
|
||||
msgr.send(ChatColor.RED + "You have not been moved because you have the lobbybalancer.bypass permission");
|
||||
return;
|
||||
}
|
||||
|
||||
if (player.getServer() != null && section.getServers().contains(player.getServer().getInfo())) {
|
||||
if (ConfigEntries.ASSIGN_TARGETS_ENABLED.get()) {
|
||||
ServerAssignRegistry.assignTarget(player, section, target);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
new ConnectionIntent(plugin, player, section) {
|
||||
@Override
|
||||
public void connect(ServerInfo server) {
|
||||
if (ConfigEntries.ASSIGN_TARGETS_ENABLED.get()) {
|
||||
ServerAssignRegistry.assignTarget(player, section, server);
|
||||
if (section.getServers().contains(target)) {
|
||||
if (section.isDummy()) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.setTarget(server);
|
||||
if (player.hasPermission("lobbybalancer.bypass")) {
|
||||
msgr.send(ChatColor.RED + "You have not been moved because you have the lobbybalancer.bypass permission");
|
||||
return;
|
||||
}
|
||||
|
||||
if (player.getServer() != null && section.getServers().contains(player.getServer().getInfo())) {
|
||||
if (ConfigEntries.ASSIGN_TARGETS_ENABLED.get()) {
|
||||
ServerAssignRegistry.assignTarget(player, section, target);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
new ConnectionIntent(plugin, player, section) {
|
||||
@Override
|
||||
public void connect(ServerInfo server) {
|
||||
if (ConfigEntries.ASSIGN_TARGETS_ENABLED.get()) {
|
||||
ServerAssignRegistry.assignTarget(player, section, server);
|
||||
}
|
||||
|
||||
event.setTarget(server);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ public class ServerKickListener implements Listener {
|
||||
public void onKick(ServerKickEvent event) {
|
||||
ProxiedPlayer player = event.getPlayer();
|
||||
ServerInfo from = event.getKickedFrom();
|
||||
Messager msgr = new Messager(player);
|
||||
|
||||
//Player is not connected to any server
|
||||
if (player.getServer() == null) {
|
||||
@ -48,8 +49,10 @@ public class ServerKickListener implements Listener {
|
||||
Callable<ServerSection> callable = () -> {
|
||||
ServerSection section = plugin.getSectionManager().getByServer(from);
|
||||
|
||||
if (section != null && (ConfigEntries.RECONNECT_KICK_IGNORED_SECTIONS.get()).contains(section.getName())) {
|
||||
return null;
|
||||
if (section != null) {
|
||||
if ((ConfigEntries.RECONNECT_KICK_IGNORED_SECTIONS.get()).contains(section.getName())) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
AtomicBoolean matches = new AtomicBoolean(false);
|
||||
@ -75,7 +78,30 @@ public class ServerKickListener implements Listener {
|
||||
String name = rules.getString(section.getName());
|
||||
ServerSection target = plugin.getSectionManager().getByName(name);
|
||||
|
||||
return target == null ? section.getParent() : target;
|
||||
if (target == null) {
|
||||
target = section.getParent();
|
||||
}
|
||||
|
||||
if (ConfigEntries.RECONNECT_KICK_RESTRICTED.get()) {
|
||||
//todo 0 is principal section
|
||||
//todo -1 is parent of principal
|
||||
//todo 1 is child of principal
|
||||
if (target.getPosition() < 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
if (section.isPrincipal()) {
|
||||
todo: check if target is parent of section (or more parents of section)
|
||||
todo: I think that instead of checking if the player is in a principal section we should check
|
||||
todo: if the target section is above the parent section
|
||||
|
||||
return null;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
return target;
|
||||
} else {
|
||||
if (ConfigEntries.FALLBACK_PRINCIPAL_ENABLED.get()) {
|
||||
return plugin.getSectionManager().getPrincipal();
|
||||
@ -101,7 +127,6 @@ public class ServerKickListener implements Listener {
|
||||
new ConnectionIntent(plugin, player, section, servers) {
|
||||
@Override
|
||||
public void connect(ServerInfo server) {
|
||||
Messager msgr = new Messager(player);
|
||||
PlayerLocker.lock(player);
|
||||
msgr.send(ConfigEntries.RECONNECT_KICK_MESSAGE.get(),
|
||||
new Replacement("{from}", from.getName()),
|
||||
|
@ -45,6 +45,7 @@ public class SectionManager {
|
||||
section.postInit(plugin);
|
||||
});
|
||||
|
||||
|
||||
long ending = System.currentTimeMillis() - starting;
|
||||
plugin.getLogger().info(String.format("A total of %s section(s) have been loaded in %sms", sectionStorage.size(), ending));
|
||||
}
|
||||
|
@ -11,14 +11,34 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.function.Function;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class ServerSection {
|
||||
private static transient final Function<ServerSection, Integer> function = (section) -> {
|
||||
if (section.isPrincipal()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int iterations = 0;
|
||||
while (true) {
|
||||
section = section.getParent();
|
||||
iterations++;
|
||||
|
||||
if (section == null) {
|
||||
return iterations;
|
||||
} else if (section.isPrincipal()) {
|
||||
return -iterations;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private transient final Configuration section;
|
||||
|
||||
private final String name;
|
||||
private boolean principal;
|
||||
private int position = Integer.MAX_VALUE;
|
||||
private boolean dummy;
|
||||
private ServerSection parent;
|
||||
private boolean inherited = false;
|
||||
@ -107,6 +127,8 @@ public class ServerSection {
|
||||
}
|
||||
|
||||
void postInit(LobbyBalancer plugin) {
|
||||
position = function.apply(this);
|
||||
|
||||
if (provider == null) {
|
||||
ServerSection sect = this.parent;
|
||||
while (sect.provider == null) {
|
||||
@ -156,6 +178,10 @@ public class ServerSection {
|
||||
return principal;
|
||||
}
|
||||
|
||||
public int getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
public boolean isDummy() {
|
||||
return dummy;
|
||||
}
|
||||
|
@ -51,6 +51,9 @@ settings:
|
||||
# Sections where this feature is ignored
|
||||
ignored: []
|
||||
|
||||
# If enabled, players will not be able to get back to any server in a section that is parent of the principal section
|
||||
restricted: true
|
||||
|
||||
# This will make it so that the server the player is kicked from will be excluded
|
||||
exclude-from: true
|
||||
|
||||
@ -83,6 +86,9 @@ settings:
|
||||
# Sections where this command is ignored
|
||||
ignored: []
|
||||
|
||||
# If enabled, players will not be able to get back to any server in a section that is parent of the principal section
|
||||
restricted: true
|
||||
|
||||
# Whether the command can accept the name of a section as a target
|
||||
arguments: false
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user