mirror of
https://github.com/BGHDDevelopment/PlayerBalancer.git
synced 2024-11-27 05:05:19 +01:00
Outdated version checks v1
This commit is contained in:
parent
a3b9aced7f
commit
a95268530a
4
pom.xml
4
pom.xml
@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>me.jaimemartz</groupId>
|
||||
<artifactId>lobbybalancer</artifactId>
|
||||
<version>2.0.1</version>
|
||||
<version>2.0.2</version>
|
||||
<name>LobbyBalancer</name>
|
||||
|
||||
<repositories>
|
||||
@ -63,7 +63,7 @@
|
||||
<dependency>
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-api</artifactId>
|
||||
<version>1.9-SNAPSHOT</version>
|
||||
<version>1.10-SNAPSHOT</version>
|
||||
<type>jar</type>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
@ -3,16 +3,17 @@ package me.jaimemartz.lobbybalancer;
|
||||
import com.google.gson.Gson;
|
||||
import com.imaginarycode.minecraft.redisbungee.RedisBungee;
|
||||
import me.jaimemartz.faucet.ConfigFactory;
|
||||
import me.jaimemartz.lobbybalancer.commands.BackwardCommand;
|
||||
import me.jaimemartz.lobbybalancer.commands.RegressCommand;
|
||||
import me.jaimemartz.lobbybalancer.commands.MainCommand;
|
||||
import me.jaimemartz.lobbybalancer.configuration.ConfigEntries;
|
||||
import me.jaimemartz.lobbybalancer.connection.ServerAssignRegistry;
|
||||
import me.jaimemartz.lobbybalancer.listener.*;
|
||||
import me.jaimemartz.lobbybalancer.ping.PingManager;
|
||||
import me.jaimemartz.lobbybalancer.section.SectionManager;
|
||||
import me.jaimemartz.lobbybalancer.utils.AdapterFix;
|
||||
import me.jaimemartz.lobbybalancer.utils.GeolocationManager;
|
||||
import me.jaimemartz.lobbybalancer.utils.PlayerLocker;
|
||||
import me.jaimemartz.lobbybalancer.manager.AdapterFix;
|
||||
import me.jaimemartz.lobbybalancer.manager.GeolocationManager;
|
||||
import me.jaimemartz.lobbybalancer.manager.PlayerLocker;
|
||||
import me.jaimemartz.lobbybalancer.utils.DigitUtils;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
@ -29,13 +30,15 @@ public class LobbyBalancer extends Plugin {
|
||||
public static final String RESOURCE_ID = "%%__RESOURCE__%%";
|
||||
public static final String NONCE_ID = "%%__NONCE__%%";
|
||||
|
||||
public static final int LAST_CONFIG_UPDATE_VER = 20200;
|
||||
|
||||
private boolean failed = false;
|
||||
private Gson gson;
|
||||
|
||||
private ConfigFactory factory;
|
||||
private PingManager pingManager;
|
||||
private SectionManager sectionManager;
|
||||
private Command backwardCommand, mainCommand;
|
||||
private Command regressCommand, mainCommand;
|
||||
private GeolocationManager geolocationManager;
|
||||
private Listener connectListener, kickListener, messageListener, reloadListener;
|
||||
|
||||
@ -43,17 +46,24 @@ public class LobbyBalancer extends Plugin {
|
||||
public void onEnable() {
|
||||
instance = this;
|
||||
gson = new Gson();
|
||||
|
||||
if (factory == null) {
|
||||
factory = new ConfigFactory(this);
|
||||
factory.register(0, "config.yml");
|
||||
factory.submit(ConfigEntries.class);
|
||||
}
|
||||
enable();
|
||||
|
||||
factory.load(0, true);
|
||||
|
||||
int configVersion = DigitUtils.getDigits(ConfigEntries.CONFIG_VERSION.get(), 5);
|
||||
if (configVersion < LAST_CONFIG_UPDATE_VER) {
|
||||
throw new IllegalStateException("Your config is outdated, please reset it and configure it again");
|
||||
} else {
|
||||
this.enable();
|
||||
}
|
||||
}
|
||||
|
||||
private void enable() {
|
||||
factory.load(0, true);
|
||||
|
||||
mainCommand = new MainCommand(this);
|
||||
getProxy().getPluginManager().registerCommand(this, mainCommand);
|
||||
|
||||
@ -81,9 +91,9 @@ public class LobbyBalancer extends Plugin {
|
||||
pingManager.start();
|
||||
}
|
||||
|
||||
if (ConfigEntries.BACKWARD_COMMAND_ENABLED.get()) {
|
||||
backwardCommand = new BackwardCommand(this);
|
||||
getProxy().getPluginManager().registerCommand(this, backwardCommand);
|
||||
if (ConfigEntries.REGRESS_COMMAND_ENABLED.get()) {
|
||||
regressCommand = new RegressCommand(this);
|
||||
getProxy().getPluginManager().registerCommand(this, regressCommand);
|
||||
}
|
||||
|
||||
connectListener = new ServerConnectListener(this);
|
||||
@ -129,6 +139,7 @@ public class LobbyBalancer extends Plugin {
|
||||
private void disable() {
|
||||
getProxy().getPluginManager().unregisterCommand(mainCommand);
|
||||
mainCommand = null;
|
||||
|
||||
if (ConfigEntries.AUTO_RELOAD_ENABLED.get()) {
|
||||
getProxy().getPluginManager().unregisterListener(reloadListener);
|
||||
reloadListener = null;
|
||||
@ -138,9 +149,13 @@ public class LobbyBalancer extends Plugin {
|
||||
//Do not try to do anything if the plugin has not loaded correctly
|
||||
if (hasFailed()) return;
|
||||
|
||||
if (ConfigEntries.BACKWARD_COMMAND_ENABLED.get()) {
|
||||
getProxy().getPluginManager().unregisterCommand(backwardCommand);
|
||||
backwardCommand = null;
|
||||
if (ConfigEntries.SERVER_CHECK_ENABLED.get()) {
|
||||
pingManager.stop();
|
||||
}
|
||||
|
||||
if (ConfigEntries.REGRESS_COMMAND_ENABLED.get()) {
|
||||
getProxy().getPluginManager().unregisterCommand(regressCommand);
|
||||
regressCommand = null;
|
||||
}
|
||||
|
||||
getProxy().getPluginManager().unregisterListener(connectListener);
|
||||
@ -169,8 +184,9 @@ public class LobbyBalancer extends Plugin {
|
||||
printStartupInfo("Reloading the plugin...");
|
||||
long starting = System.currentTimeMillis();
|
||||
|
||||
disable();
|
||||
enable();
|
||||
this.disable();
|
||||
factory.load(0, true);
|
||||
this.enable();
|
||||
|
||||
long ending = System.currentTimeMillis() - starting;
|
||||
printStartupInfo("The plugin has been reloaded, took %sms", ending);
|
||||
|
@ -2,7 +2,7 @@ package me.jaimemartz.lobbybalancer.commands;
|
||||
|
||||
import me.jaimemartz.faucet.Messager;
|
||||
import me.jaimemartz.lobbybalancer.LobbyBalancer;
|
||||
import me.jaimemartz.lobbybalancer.utils.PasteHelper;
|
||||
import me.jaimemartz.lobbybalancer.manager.PasteHelper;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.plugin.Command;
|
||||
|
@ -5,7 +5,7 @@ import me.jaimemartz.lobbybalancer.LobbyBalancer;
|
||||
import me.jaimemartz.lobbybalancer.configuration.ConfigEntries;
|
||||
import me.jaimemartz.lobbybalancer.connection.ConnectionIntent;
|
||||
import me.jaimemartz.lobbybalancer.section.ServerSection;
|
||||
import me.jaimemartz.lobbybalancer.utils.PlayerLocker;
|
||||
import me.jaimemartz.lobbybalancer.manager.PlayerLocker;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
@ -13,10 +13,13 @@ import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.plugin.Command;
|
||||
import net.md_5.bungee.config.Configuration;
|
||||
|
||||
public class BackwardCommand extends Command {
|
||||
import java.util.concurrent.*;
|
||||
|
||||
public class RegressCommand extends Command {
|
||||
private final LobbyBalancer plugin;
|
||||
public BackwardCommand(LobbyBalancer plugin) {
|
||||
super(ConfigEntries.BACKWARD_COMMAND_NAME.get(), ConfigEntries.BACKWARD_COMMAND_PERMISSION.get(), (ConfigEntries.BACKWARD_COMMAND_ALIASES.get().stream()).toArray(String[]::new));
|
||||
|
||||
public RegressCommand(LobbyBalancer plugin) {
|
||||
super(ConfigEntries.REGRESS_COMMAND_NAME.get(), ConfigEntries.REGRESS_COMMAND_PERMISSION.get(), (ConfigEntries.REGRESS_COMMAND_ALIASES.get().stream()).toArray(String[]::new));
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@ -25,22 +28,47 @@ public class BackwardCommand extends Command {
|
||||
Messager msgr = new Messager(sender);
|
||||
if (sender instanceof ProxiedPlayer) {
|
||||
ProxiedPlayer player = (ProxiedPlayer) sender;
|
||||
|
||||
ServerSection section = plugin.getSectionManager().getByServer(player.getServer().getInfo());
|
||||
if (section != null) {
|
||||
if ((ConfigEntries.BACKWARD_COMMAND_IGNORED_SECTIONS.get()).contains(section.getName())) {
|
||||
msgr.send(ConfigEntries.UNAVAILABLE_MESSAGE.get());
|
||||
}
|
||||
|
||||
PlayerLocker.lock(player);
|
||||
|
||||
if (ConfigEntries.BACKWARD_COMMAND_ARGUMENTS.get() && args.length == 1) {
|
||||
ServerSection target = plugin.getSectionManager().getByName(args[0]);
|
||||
|
||||
if (target == null) {
|
||||
msgr.send(ConfigEntries.UNKNOWN_SECTION_MESSAGE.get());
|
||||
Callable<ServerSection> task = () -> {
|
||||
if (section != null) {
|
||||
if ((ConfigEntries.REGRESS_COMMAND_IGNORED_SECTIONS.get()).contains(section.getName())) {
|
||||
msgr.send(ConfigEntries.UNAVAILABLE_MESSAGE.get());
|
||||
}
|
||||
|
||||
PlayerLocker.lock(player);
|
||||
|
||||
if (ConfigEntries.REGRESS_COMMAND_ARGUMENTS.get() && args.length == 1) {
|
||||
ServerSection target = plugin.getSectionManager().getByName(args[0]);
|
||||
|
||||
if (target == null) {
|
||||
msgr.send(ConfigEntries.UNKNOWN_SECTION_MESSAGE.get());
|
||||
}
|
||||
|
||||
return target;
|
||||
} else {
|
||||
Configuration rules = plugin.getConfig().getSection("settings.backward-command.rules");
|
||||
String bind = rules.getString(section.getName());
|
||||
ServerSection target = plugin.getSectionManager().getByName(bind);
|
||||
|
||||
if (target == null) {
|
||||
target = section.getParent();
|
||||
}
|
||||
|
||||
return target;
|
||||
}
|
||||
} else {
|
||||
if (ConfigEntries.FALLBACK_PRINCIPAL_ENABLED.get()) {
|
||||
return plugin.getSectionManager().getPrincipal();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
try {
|
||||
ServerSection target = task.call();
|
||||
if (target != null) {
|
||||
new ConnectionIntent(plugin, player, target) {
|
||||
@Override
|
||||
public void connect(ServerInfo server) {
|
||||
@ -49,28 +77,9 @@ public class BackwardCommand extends Command {
|
||||
}
|
||||
};
|
||||
} else {
|
||||
Configuration rules = plugin.getConfig().getSection("settings.backward-command.rules");
|
||||
String name = rules.getString(section.getName());
|
||||
ServerSection target = plugin.getSectionManager().getByName(name);
|
||||
|
||||
if (target == null) {
|
||||
target = section.getParent();
|
||||
}
|
||||
|
||||
if (target == null) {
|
||||
msgr.send(ConfigEntries.UNAVAILABLE_MESSAGE.get());
|
||||
}
|
||||
|
||||
new ConnectionIntent(plugin, player, target) {
|
||||
@Override
|
||||
public void connect(ServerInfo server) {
|
||||
player.connect(server);
|
||||
PlayerLocker.unlock(player);
|
||||
}
|
||||
};
|
||||
|
||||
msgr.send(ConfigEntries.UNAVAILABLE_MESSAGE.get());
|
||||
}
|
||||
} else {
|
||||
} catch (Exception e) {
|
||||
msgr.send(ConfigEntries.UNAVAILABLE_MESSAGE.get());
|
||||
}
|
||||
} else {
|
@ -8,7 +8,6 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class ConfigEntries implements ConfigEntryHolder {
|
||||
public static final ConfigEntry<String> CONFIG_VERSION = new ConfigEntry<>(0, "version", null);
|
||||
public static final ConfigEntry<Boolean> PLUGIN_ENABLED = new ConfigEntry<>(0, "settings.enabled", false);
|
||||
public static final ConfigEntry<Boolean> SILENT_STARTUP = new ConfigEntry<>(0, "settings.silent-startup", false);
|
||||
public static final ConfigEntry<Boolean> CHECK_UPDATES_ENABLED = new ConfigEntry<>(0, "settings.check-updates", true);
|
||||
@ -30,19 +29,22 @@ public class ConfigEntries implements ConfigEntryHolder {
|
||||
public static final ConfigEntry<List<String>> RECONNECT_KICK_IGNORED_SECTIONS = new ConfigEntry<>(0, "settings.reconnect-kick.ignored", Collections.emptyList());
|
||||
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> BACKWARD_COMMAND_ENABLED = new ConfigEntry<>(0, "settings.backward-command.enabled", true);
|
||||
public static final ConfigEntry<String> BACKWARD_COMMAND_NAME = new ConfigEntry<>(0, "settings.backward-command.name", "backward");
|
||||
public static final ConfigEntry<List<String>> BACKWARD_COMMAND_ALIASES = new ConfigEntry<>(0, "settings.backward-command.aliases", Arrays.asList("lobby", "hub", "back"));
|
||||
public static final ConfigEntry<String> BACKWARD_COMMAND_PERMISSION = new ConfigEntry<>(0, "settings.backward-command.permission", "");
|
||||
public static final ConfigEntry<List<String>> BACKWARD_COMMAND_IGNORED_SECTIONS = new ConfigEntry<>(0, "settings.backward-command.ignored", Collections.emptyList());
|
||||
public static final ConfigEntry<Boolean> BACKWARD_COMMAND_ARGUMENTS = new ConfigEntry<>(0, "settings.backward-command.arguments", true);
|
||||
public static final ConfigEntry<Boolean> REGRESS_COMMAND_ENABLED = new ConfigEntry<>(0, "settings.regress-command.enabled", true);
|
||||
public static final ConfigEntry<String> REGRESS_COMMAND_NAME = new ConfigEntry<>(0, "settings.regress-command.name", "backward");
|
||||
public static final ConfigEntry<List<String>> REGRESS_COMMAND_ALIASES = new ConfigEntry<>(0, "settings.regress-command.aliases", Arrays.asList("lobby", "hub", "back"));
|
||||
public static final ConfigEntry<String> REGRESS_COMMAND_PERMISSION = new ConfigEntry<>(0, "settings.regress-command.permission", "");
|
||||
public static final ConfigEntry<List<String>> REGRESS_COMMAND_IGNORED_SECTIONS = new ConfigEntry<>(0, "settings.regress-command.ignored", Collections.emptyList());
|
||||
public static final ConfigEntry<Boolean> REGRESS_COMMAND_ARGUMENTS = new ConfigEntry<>(0, "settings.regress-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);
|
||||
public static final ConfigEntry<Boolean> FALLBACK_PRINCIPAL_ENABLED = new ConfigEntry<>(0, "settings.fallback-principal", true);
|
||||
|
||||
public static final ConfigEntry<String> CONNECTING_MESSAGE = new ConfigEntry<>(0, "settings.messages.connecting", "&aConnecting to {server}");
|
||||
public static final ConfigEntry<String> FAILURE_MESSAGE = new ConfigEntry<>(0, "settings.messages.failure", "&cCould not find a server to connect to");
|
||||
public static final ConfigEntry<String> UNAVAILABLE_MESSAGE = new ConfigEntry<>(0, "settings.messages.unavailable", "&cThis command cannot be executed on this server");
|
||||
public static final ConfigEntry<String> UNKNOWN_SECTION_MESSAGE = new ConfigEntry<>(0, "settings.messages.unknown", "&cCould not find a section with that name");
|
||||
|
||||
public static final ConfigEntry<String> CONFIG_VERSION = new ConfigEntry<>(0, "version", null);
|
||||
}
|
||||
|
@ -3,7 +3,8 @@ package me.jaimemartz.lobbybalancer.listener;
|
||||
import me.jaimemartz.lobbybalancer.LobbyBalancer;
|
||||
import me.jaimemartz.lobbybalancer.configuration.ConfigEntries;
|
||||
import me.jaimemartz.lobbybalancer.connection.ServerAssignRegistry;
|
||||
import me.jaimemartz.lobbybalancer.utils.PlayerLocker;
|
||||
import me.jaimemartz.lobbybalancer.manager.PlayerLocker;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.event.PlayerDisconnectEvent;
|
||||
import net.md_5.bungee.api.plugin.Listener;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
@ -18,11 +19,12 @@ public class PlayerDisconnectListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onDisconnect(PlayerDisconnectEvent event) {
|
||||
PlayerLocker.unlock(event.getPlayer());
|
||||
ProxiedPlayer player = event.getPlayer();
|
||||
PlayerLocker.unlock(player);
|
||||
|
||||
//Delete this if we want to keep assigned groups even when leaving
|
||||
if (ConfigEntries.ASSIGN_TARGETS_ENABLED.get()) {
|
||||
ServerAssignRegistry.clearAsssignedServers(event.getPlayer());
|
||||
ServerAssignRegistry.clearAsssignedServers(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ import me.jaimemartz.lobbybalancer.configuration.ConfigEntries;
|
||||
import me.jaimemartz.lobbybalancer.connection.ConnectionIntent;
|
||||
import me.jaimemartz.lobbybalancer.connection.ServerAssignRegistry;
|
||||
import me.jaimemartz.lobbybalancer.section.ServerSection;
|
||||
import me.jaimemartz.lobbybalancer.utils.PlayerLocker;
|
||||
import me.jaimemartz.lobbybalancer.manager.PlayerLocker;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
|
@ -13,6 +13,7 @@ import net.md_5.bungee.config.Configuration;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
import net.md_5.bungee.event.EventPriority;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
public class ServerKickListener implements Listener {
|
||||
@ -27,63 +28,75 @@ public class ServerKickListener implements Listener {
|
||||
ProxiedPlayer player = event.getPlayer();
|
||||
ServerInfo from = event.getKickedFrom();
|
||||
|
||||
//Player is not connected to any server
|
||||
if (player.getServer() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
//Player is not connected to the server he is kicked from
|
||||
if (!player.getServer().getInfo().equals(from)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ServerSection section = plugin.getSectionManager().getByServer(from);
|
||||
if (section != null) {
|
||||
if ((ConfigEntries.RECONNECT_KICK_IGNORED_SECTIONS.get()).contains(section.getName())) {
|
||||
return;
|
||||
}
|
||||
Callable<ServerSection> task = () -> {
|
||||
if (section != null) {
|
||||
if ((ConfigEntries.RECONNECT_KICK_IGNORED_SECTIONS.get()).contains(section.getName())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Configuration rules = plugin.getConfig().getSection("settings.reconnect-kick.rules");
|
||||
String name = rules.getString(section.getName());
|
||||
ServerSection target = plugin.getSectionManager().getByName(name);
|
||||
Configuration rules = plugin.getConfig().getSection("settings.reconnect-kick.rules");
|
||||
String name = rules.getString(section.getName());
|
||||
ServerSection target = plugin.getSectionManager().getByName(name);
|
||||
|
||||
if (target == null) {
|
||||
target = section.getParent();
|
||||
if (target == null) {
|
||||
return;
|
||||
target = section.getParent();
|
||||
if (target == null) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
AtomicBoolean matches = new AtomicBoolean(false);
|
||||
String reason = TextComponent.toPlainText(event.getKickReasonComponent());
|
||||
for (String pattern : ConfigEntries.RECONNECT_KICK_REASONS.get()) {
|
||||
if (reason.matches(pattern)) {
|
||||
matches.set(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (ConfigEntries.RECONNECT_KICK_INVERTED.get()) {
|
||||
matches.set(!matches.get());
|
||||
}
|
||||
|
||||
if (matches.get()) {
|
||||
return target;
|
||||
}
|
||||
|
||||
if (ConfigEntries.RECONNECT_KICK_PRINT_INFO.get()) {
|
||||
LobbyBalancer.printStartupInfo(String.format("Kick Reason: \"%s\", Found Match: %s", TextComponent.toPlainText(event.getKickReasonComponent()), matches.get()));
|
||||
}
|
||||
} else {
|
||||
if (ConfigEntries.FALLBACK_PRINCIPAL_ENABLED.get()) {
|
||||
return plugin.getSectionManager().getPrincipal();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
AtomicBoolean matches = new AtomicBoolean(false);
|
||||
String reason = TextComponent.toPlainText(event.getKickReasonComponent());
|
||||
for (String pattern : ConfigEntries.RECONNECT_KICK_REASONS.get()) {
|
||||
if (reason.matches(pattern)) {
|
||||
matches.set(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (ConfigEntries.RECONNECT_KICK_INVERTED.get()) {
|
||||
matches.set(!matches.get());
|
||||
}
|
||||
|
||||
if (matches.get()) {
|
||||
try {
|
||||
ServerSection target = task.call();
|
||||
if (target != null) {
|
||||
new ConnectionIntent(plugin, player, target) {
|
||||
@Override
|
||||
public void connect(ServerInfo server) {
|
||||
LobbyBalancer.checkSendMessage(player, ConfigEntries.RECONNECT_KICK_MESSAGE.get()
|
||||
.replace("{from}", from.getName())
|
||||
.replace("{to}", server.getName())
|
||||
.replace("{reason}", reason)
|
||||
);
|
||||
|
||||
event.setCancelled(true);
|
||||
event.setCancelServer(server);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
if (ConfigEntries.RECONNECT_KICK_PRINT_INFO.get()) {
|
||||
LobbyBalancer.printStartupInfo(String.format("Kick Reason: \"%s\", Found Match: %s", TextComponent.toPlainText(event.getKickReasonComponent()), matches.get()));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
//Nothing to do
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package me.jaimemartz.lobbybalancer.utils;
|
||||
package me.jaimemartz.lobbybalancer.manager;
|
||||
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.config.ConfigurationAdapter;
|
@ -1,4 +1,4 @@
|
||||
package me.jaimemartz.lobbybalancer.utils;
|
||||
package me.jaimemartz.lobbybalancer.manager;
|
||||
|
||||
import com.fasterxml.jackson.databind.ext.Java7Support;
|
||||
import com.maxmind.db.CHMCache;
|
@ -1,4 +1,4 @@
|
||||
package me.jaimemartz.lobbybalancer.utils;
|
||||
package me.jaimemartz.lobbybalancer.manager;
|
||||
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.CommandSender;
|
@ -1,4 +1,4 @@
|
||||
package me.jaimemartz.lobbybalancer.utils;
|
||||
package me.jaimemartz.lobbybalancer.manager;
|
||||
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
|
@ -49,14 +49,6 @@ public class PingManager {
|
||||
tactic.ping(server, new PingCallback() {
|
||||
@Override
|
||||
public void onPong(ServerStatus status) {
|
||||
/* FIXME: 08/01/2017 Not sure if necessary
|
||||
if (status.isAccessible()) {
|
||||
if (LobbyBalancer.getPlayerCount(server) > status.getMaximumPlayers()) {
|
||||
status.setAccessible(false);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
if (ConfigEntries.SERVER_CHECK_PRINT_INFO.get()) {
|
||||
plugin.getLogger().info(String.format(
|
||||
"Tracking server %s, status: [Description: \"%s\", Online Players: %s, Maximum Players: %s, Accessible: %s]",
|
||||
|
@ -12,10 +12,10 @@ import net.md_5.bungee.api.plugin.Command;
|
||||
import java.util.List;
|
||||
|
||||
public class SectionCommand extends Command {
|
||||
private final LobbyBalancer plugin;
|
||||
private final ServerSection section;
|
||||
private transient final LobbyBalancer plugin;
|
||||
private transient final ServerSection section;
|
||||
|
||||
public SectionCommand(LobbyBalancer plugin, String name, String permission, List<String> aliases, ServerSection section) {
|
||||
SectionCommand(LobbyBalancer plugin, String name, String permission, List<String> aliases, ServerSection section) {
|
||||
super(name, permission, aliases.stream().toArray(String[]::new));
|
||||
this.plugin = plugin;
|
||||
this.section = section;
|
||||
|
@ -1,7 +1,7 @@
|
||||
package me.jaimemartz.lobbybalancer.section;
|
||||
|
||||
import me.jaimemartz.lobbybalancer.LobbyBalancer;
|
||||
import me.jaimemartz.lobbybalancer.utils.AdapterFix;
|
||||
import me.jaimemartz.lobbybalancer.manager.AdapterFix;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
import net.md_5.bungee.config.Configuration;
|
||||
|
||||
|
@ -1,9 +1,8 @@
|
||||
package me.jaimemartz.lobbybalancer.section;
|
||||
|
||||
import com.google.gson.annotations.Expose;
|
||||
import me.jaimemartz.lobbybalancer.LobbyBalancer;
|
||||
import me.jaimemartz.lobbybalancer.connection.ProviderType;
|
||||
import me.jaimemartz.lobbybalancer.utils.AdapterFix;
|
||||
import me.jaimemartz.lobbybalancer.manager.AdapterFix;
|
||||
import me.jaimemartz.lobbybalancer.utils.ConfigUtils;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
import net.md_5.bungee.config.Configuration;
|
||||
@ -16,34 +15,17 @@ import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class ServerSection {
|
||||
private final Configuration section;
|
||||
private final SectionManager manager;
|
||||
private transient final Configuration section;
|
||||
private transient final SectionManager manager;
|
||||
|
||||
@Expose
|
||||
private final String name;
|
||||
|
||||
@Expose
|
||||
private boolean principal;
|
||||
|
||||
@Expose
|
||||
private ServerSection parent;
|
||||
|
||||
@Expose
|
||||
private boolean inherit = false;
|
||||
|
||||
@Expose
|
||||
private List<ServerInfo> servers;
|
||||
|
||||
@Expose
|
||||
private ProviderType provider;
|
||||
|
||||
@Expose
|
||||
private ServerInfo server;
|
||||
|
||||
@Expose
|
||||
private SectionCommand command;
|
||||
|
||||
@Expose
|
||||
private boolean valid = false;
|
||||
|
||||
ServerSection(String name, Configuration section, SectionManager manager) {
|
||||
|
@ -0,0 +1,34 @@
|
||||
package me.jaimemartz.lobbybalancer.utils;
|
||||
|
||||
public class DigitUtils {
|
||||
public static int getDigits(String string, int digits) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
for (char character : string.toCharArray()) {
|
||||
if (Character.isDigit(character)) {
|
||||
if (builder.length() >= digits) {
|
||||
break;
|
||||
}
|
||||
builder.append(character);
|
||||
}
|
||||
}
|
||||
|
||||
while (builder.length() < digits) {
|
||||
builder.append("0");
|
||||
}
|
||||
|
||||
return Integer.parseInt(builder.toString());
|
||||
}
|
||||
|
||||
public static int getDigits(String string) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
for (char character : string.toCharArray()) {
|
||||
if (Character.isDigit(character)) {
|
||||
builder.append(character);
|
||||
}
|
||||
}
|
||||
|
||||
return Integer.parseInt(builder.toString());
|
||||
}
|
||||
}
|
@ -0,0 +1,87 @@
|
||||
package me.jaimemartz.lobbybalancer.utils;
|
||||
|
||||
public class LevenshteinDistance {
|
||||
public static String getClosestString(String input, String[] options) {
|
||||
int lowestDistance = 10;
|
||||
String lowest = "";
|
||||
|
||||
for (String string : options) {
|
||||
int distance = getLevenshteinDistance(input, string);
|
||||
if (distance < lowestDistance) {
|
||||
lowestDistance = distance;
|
||||
lowest = string;
|
||||
}
|
||||
}
|
||||
|
||||
return lowest;
|
||||
}
|
||||
|
||||
public static String getClosestString(String input, Iterable<String> options) {
|
||||
int lowestDistance = 10;
|
||||
String lowest = "";
|
||||
|
||||
for (String string : options) {
|
||||
int distance = getLevenshteinDistance(input, string);
|
||||
if (distance < lowestDistance) {
|
||||
lowestDistance = distance;
|
||||
lowest = string;
|
||||
}
|
||||
}
|
||||
|
||||
return lowest;
|
||||
}
|
||||
|
||||
private static int getLevenshteinDistance(String s, String t) {
|
||||
if (s == null || t == null) {
|
||||
return 11;
|
||||
}
|
||||
|
||||
int n = s.length();
|
||||
int m = t.length();
|
||||
|
||||
if (n == 0) {
|
||||
return m;
|
||||
} else if (m == 0) {
|
||||
return n;
|
||||
}
|
||||
|
||||
if (n > m) {
|
||||
String tmp = s;
|
||||
s = t;
|
||||
t = tmp;
|
||||
n = m;
|
||||
m = t.length();
|
||||
}
|
||||
|
||||
int p[] = new int[n + 1];
|
||||
int d[] = new int[n + 1];
|
||||
int _d[];
|
||||
|
||||
int i;
|
||||
int j;
|
||||
|
||||
char t_j;
|
||||
|
||||
int cost;
|
||||
|
||||
for (i = 0; i <= n; i++) {
|
||||
p[i] = i;
|
||||
}
|
||||
|
||||
for (j = 1; j <= m; j++) {
|
||||
t_j = t.charAt(j - 1);
|
||||
d[0] = j;
|
||||
|
||||
for (i = 1; i <= n; i++) {
|
||||
cost = s.charAt(i - 1) == t_j ? 0 : 1;
|
||||
d[i] = Math.min(Math.min(d[i - 1] + 1, p[i] + 1), p[i - 1] + cost);
|
||||
}
|
||||
|
||||
_d = p;
|
||||
p = d;
|
||||
d = _d;
|
||||
}
|
||||
|
||||
return p[n];
|
||||
}
|
||||
}
|
@ -1,5 +1,3 @@
|
||||
version: '${project.version}'
|
||||
|
||||
# Providers of this plugin
|
||||
# NONE: Returns no server
|
||||
# DIRECT: Returns the only server in the list
|
||||
@ -62,7 +60,7 @@ settings:
|
||||
rules: {}
|
||||
|
||||
# This will connect the player to a server of the parent of the section the player is currently on
|
||||
backward-command:
|
||||
regress-command:
|
||||
enabled: true
|
||||
|
||||
name: 'backward'
|
||||
@ -101,6 +99,9 @@ settings:
|
||||
# Assign a target to a player instead of looking every time for one
|
||||
assign-targets: false
|
||||
|
||||
# When a player is not in any section, the player will go to the principal section
|
||||
fallback-principal: true
|
||||
|
||||
messages:
|
||||
connecting: '&aConnecting to {server}'
|
||||
failure: '&cCould not find a server to connect to'
|
||||
@ -150,3 +151,4 @@ sections:
|
||||
name: 'practice'
|
||||
permission: ''
|
||||
aliases: ["rektnoobs"]
|
||||
version: '${project.version}'
|
||||
|
27
src/test/java/Test2.java
Normal file
27
src/test/java/Test2.java
Normal file
@ -0,0 +1,27 @@
|
||||
import com.google.gson.Gson;
|
||||
import org.junit.Test;
|
||||
|
||||
public class Test2 {
|
||||
@Test
|
||||
public void test() {
|
||||
Gson gson = new Gson();
|
||||
Class1 object = new Class1("test");
|
||||
String json = gson.toJson(object);
|
||||
System.out.println(json);
|
||||
}
|
||||
|
||||
public class Class1 extends Class2 {
|
||||
public Class1(String test) {
|
||||
super(test);
|
||||
}
|
||||
}
|
||||
|
||||
public class Class2 {
|
||||
private final String test;
|
||||
|
||||
public Class2(String test) {
|
||||
this.test = test;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user