mirror of
https://github.com/BGHDDevelopment/PlayerBalancer.git
synced 2024-11-23 11:15:30 +01:00
Version 2.0.4
Fixed section servers Made the messages able to be disabled Fixed double messages (double connection) Config is backwards compatible
This commit is contained in:
parent
872863c5e5
commit
a8e87aab93
@ -1,2 +1,3 @@
|
||||
# LobbyBalancer
|
||||
[Spigot](https://www.spigotmc.org/resources/10788/)
|
||||
[Faucet](https://github.com/jaime29010/Faucet)
|
4
pom.xml
4
pom.xml
@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>me.jaimemartz</groupId>
|
||||
<artifactId>lobbybalancer</artifactId>
|
||||
<version>2.0.3</version>
|
||||
<version>2.0.4</version>
|
||||
<name>LobbyBalancer</name>
|
||||
|
||||
<repositories>
|
||||
@ -81,7 +81,7 @@
|
||||
<dependency>
|
||||
<groupId>me.jaimemartz</groupId>
|
||||
<artifactId>faucet-bungee</artifactId>
|
||||
<version>1.1</version>
|
||||
<version>LATEST</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
|
@ -8,14 +8,11 @@ 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.manager.AdapterFix;
|
||||
import me.jaimemartz.lobbybalancer.manager.GeolocationManager;
|
||||
import me.jaimemartz.lobbybalancer.manager.PlayerLocker;
|
||||
import me.jaimemartz.lobbybalancer.ping.PingManager;
|
||||
import me.jaimemartz.lobbybalancer.section.SectionManager;
|
||||
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;
|
||||
import net.md_5.bungee.api.plugin.Command;
|
||||
import net.md_5.bungee.api.plugin.Listener;
|
||||
@ -24,6 +21,7 @@ import net.md_5.bungee.config.Configuration;
|
||||
import org.inventivetalent.update.bungee.BungeeUpdater;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class LobbyBalancer extends Plugin {
|
||||
public static final String USER_ID = "%%__USER__%%";
|
||||
@ -68,6 +66,10 @@ public class LobbyBalancer extends Plugin {
|
||||
}
|
||||
|
||||
if (ConfigEntries.PLUGIN_ENABLED.get()) {
|
||||
if (ConfigEntries.SILENT_STARTUP.get()) {
|
||||
getLogger().setLevel(Level.WARNING);
|
||||
}
|
||||
|
||||
if (ConfigEntries.AUTO_RELOAD_ENABLED.get()) {
|
||||
reloadListener = new ProxyReloadListener(this);
|
||||
getProxy().getPluginManager().registerListener(this, reloadListener);
|
||||
@ -112,7 +114,7 @@ public class LobbyBalancer extends Plugin {
|
||||
}
|
||||
|
||||
if (ConfigEntries.GEOLOCATION_ENABLED.get()) {
|
||||
printStartupInfo("The geolocation feature has not been tested in depth");
|
||||
getLogger().warning("The geolocation feature has not been tested in depth");
|
||||
try {
|
||||
geolocationManager = new GeolocationManager(this);
|
||||
} catch (IOException e) {
|
||||
@ -170,7 +172,6 @@ public class LobbyBalancer extends Plugin {
|
||||
}
|
||||
|
||||
sectionManager.flush();
|
||||
AdapterFix.getFakeServers().clear();
|
||||
|
||||
if (ConfigEntries.ASSIGN_TARGETS_ENABLED.get()) {
|
||||
ServerAssignRegistry.getTable().clear();
|
||||
@ -181,14 +182,14 @@ public class LobbyBalancer extends Plugin {
|
||||
}
|
||||
|
||||
public void reloadPlugin() {
|
||||
printStartupInfo("Reloading the plugin...");
|
||||
getLogger().info("Reloading the plugin...");
|
||||
long starting = System.currentTimeMillis();
|
||||
|
||||
this.disable();
|
||||
this.enable();
|
||||
|
||||
long ending = System.currentTimeMillis() - starting;
|
||||
printStartupInfo("The plugin has been reloaded, took %sms", ending);
|
||||
getLogger().info(String.format("The plugin has been reloaded, took %sms", ending));
|
||||
}
|
||||
|
||||
public static int getPlayerCount(ServerInfo server) {
|
||||
@ -202,21 +203,6 @@ public class LobbyBalancer extends Plugin {
|
||||
return server.getPlayers().size();
|
||||
}
|
||||
|
||||
public static void checkSendMessage(CommandSender sender, String message) {
|
||||
if (message != null) {
|
||||
sender.sendMessage(TextComponent.fromLegacyText(message));
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean printStartupInfo(String format, Object... args) {
|
||||
if (ConfigEntries.SILENT_STARTUP.get()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
instance.getLogger().info(String.format(format, args));
|
||||
return true;
|
||||
}
|
||||
|
||||
public Gson getGson() {
|
||||
return gson;
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ import net.md_5.bungee.api.plugin.Command;
|
||||
import net.md_5.bungee.config.Configuration;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class FallbackCommand extends Command {
|
||||
private final LobbyBalancer plugin;
|
||||
@ -37,8 +38,6 @@ public class FallbackCommand extends Command {
|
||||
msgr.send(ConfigEntries.UNAVAILABLE_MESSAGE.get());
|
||||
}
|
||||
|
||||
PlayerLocker.lock(player);
|
||||
|
||||
if (ConfigEntries.FALLBACK_COMMAND_ARGUMENTS.get() && args.length == 1) {
|
||||
ServerSection target = plugin.getSectionManager().getByName(args[0]);
|
||||
|
||||
@ -69,18 +68,22 @@ public class FallbackCommand extends Command {
|
||||
try {
|
||||
ServerSection target = callable.call();
|
||||
if (target != null) {
|
||||
PlayerLocker.lock(player);
|
||||
new ConnectionIntent(plugin, player, target) {
|
||||
@Override
|
||||
public void connect(ServerInfo server) {
|
||||
player.connect(server);
|
||||
plugin.getProxy().getScheduler().schedule(plugin, () -> {
|
||||
PlayerLocker.unlock(player);
|
||||
}, 2, TimeUnit.SECONDS);
|
||||
}
|
||||
};
|
||||
} else {
|
||||
msgr.send(ConfigEntries.UNAVAILABLE_MESSAGE.get());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
msgr.send(ConfigEntries.UNAVAILABLE_MESSAGE.get());
|
||||
e.printStackTrace();
|
||||
msgr.send(ConfigEntries.FAILURE_MESSAGE.get());
|
||||
}
|
||||
} else {
|
||||
msgr.send(ChatColor.RED + "This command can only be executed by a player");
|
||||
|
@ -41,10 +41,10 @@ public class ConfigEntries implements ConfigEntryHolder {
|
||||
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> CONNECTING_MESSAGE = new ConfigEntry<>(0, "settings.messages.connecting", null);
|
||||
public static final ConfigEntry<String> FAILURE_MESSAGE = new ConfigEntry<>(0, "settings.messages.failure", null);
|
||||
public static final ConfigEntry<String> UNAVAILABLE_MESSAGE = new ConfigEntry<>(0, "settings.messages.unavailable", null);
|
||||
public static final ConfigEntry<String> UNKNOWN_SECTION_MESSAGE = new ConfigEntry<>(0, "settings.messages.unknown", null);
|
||||
|
||||
public static final ConfigEntry<String> CONFIG_VERSION = new ConfigEntry<>(0, "version", null);
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package me.jaimemartz.lobbybalancer.connection;
|
||||
|
||||
import me.jaimemartz.faucet.Messager;
|
||||
import me.jaimemartz.faucet.Replacement;
|
||||
import me.jaimemartz.lobbybalancer.LobbyBalancer;
|
||||
import me.jaimemartz.lobbybalancer.configuration.ConfigEntries;
|
||||
import me.jaimemartz.lobbybalancer.ping.ServerStatus;
|
||||
@ -12,12 +13,13 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class ConnectionIntent {
|
||||
|
||||
protected ConnectionIntent(LobbyBalancer plugin, ProxiedPlayer player, ServerSection section) {
|
||||
ServerInfo target = this.findTarget(plugin, player, section);
|
||||
Messager msgr = new Messager(player);
|
||||
|
||||
if (target != null) {
|
||||
msgr.send((ConfigEntries.CONNECTING_MESSAGE.get()).replace("{server}", target.getName()));
|
||||
msgr.send(ConfigEntries.CONNECTING_MESSAGE.get(), new Replacement("{server}", target.getName()));
|
||||
this.connect(target);
|
||||
} else {
|
||||
msgr.send(ConfigEntries.FAILURE_MESSAGE.get());
|
||||
|
@ -4,6 +4,7 @@ import com.google.common.io.ByteArrayDataInput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import me.jaimemartz.lobbybalancer.LobbyBalancer;
|
||||
import me.jaimemartz.lobbybalancer.connection.ConnectionIntent;
|
||||
import me.jaimemartz.lobbybalancer.manager.PlayerLocker;
|
||||
import me.jaimemartz.lobbybalancer.section.ServerSection;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
@ -15,6 +16,7 @@ import net.md_5.bungee.event.EventHandler;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class PluginMessageListener implements Listener {
|
||||
private final LobbyBalancer plugin;
|
||||
@ -43,6 +45,9 @@ public class PluginMessageListener implements Listener {
|
||||
@Override
|
||||
public void connect(ServerInfo server) {
|
||||
player.connect(server);
|
||||
plugin.getProxy().getScheduler().schedule(plugin, () -> {
|
||||
PlayerLocker.unlock(player);
|
||||
}, 2, TimeUnit.SECONDS);
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -64,6 +69,9 @@ public class PluginMessageListener implements Listener {
|
||||
@Override
|
||||
public void connect(ServerInfo server) {
|
||||
player.connect(server);
|
||||
plugin.getProxy().getScheduler().schedule(plugin, () -> {
|
||||
PlayerLocker.unlock(player);
|
||||
}, 2, TimeUnit.SECONDS);
|
||||
}
|
||||
};
|
||||
break;
|
||||
|
@ -33,11 +33,11 @@ public class ServerConnectListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
if (section.getServers().contains(target)) {
|
||||
if (PlayerLocker.isLocked(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (section.getServers().contains(target)) {
|
||||
if (player.hasPermission("lobbybalancer.bypass")) {
|
||||
msgr.send(ChatColor.RED + "You have not been moved because you have the lobbybalancer.bypass permission");
|
||||
return;
|
||||
|
@ -1,5 +1,7 @@
|
||||
package me.jaimemartz.lobbybalancer.listener;
|
||||
|
||||
import me.jaimemartz.faucet.Messager;
|
||||
import me.jaimemartz.faucet.Replacement;
|
||||
import me.jaimemartz.lobbybalancer.LobbyBalancer;
|
||||
import me.jaimemartz.lobbybalancer.configuration.ConfigEntries;
|
||||
import me.jaimemartz.lobbybalancer.connection.ConnectionIntent;
|
||||
@ -16,9 +18,6 @@ import net.md_5.bungee.event.EventPriority;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import static me.jaimemartz.lobbybalancer.LobbyBalancer.checkSendMessage;
|
||||
import static me.jaimemartz.lobbybalancer.LobbyBalancer.printStartupInfo;
|
||||
|
||||
public class ServerKickListener implements Listener {
|
||||
private final LobbyBalancer plugin;
|
||||
|
||||
@ -72,7 +71,7 @@ public class ServerKickListener implements Listener {
|
||||
}
|
||||
|
||||
if (ConfigEntries.RECONNECT_KICK_PRINT_INFO.get()) {
|
||||
printStartupInfo(String.format("Kick Reason: \"%s\", Found Match: %s", TextComponent.toPlainText(event.getKickReasonComponent()), matches));
|
||||
plugin.getLogger().info(String.format("Kick Reason: \"%s\", Found Match: %s", TextComponent.toPlainText(event.getKickReasonComponent()), matches));
|
||||
}
|
||||
|
||||
if (matches.get()) {
|
||||
@ -92,7 +91,11 @@ public class ServerKickListener implements Listener {
|
||||
new ConnectionIntent(plugin, player, target) {
|
||||
@Override
|
||||
public void connect(ServerInfo server) {
|
||||
checkSendMessage(player, ConfigEntries.RECONNECT_KICK_MESSAGE.get().replace("{from}", from.getName()).replace("{to}", server.getName()).replace("{reason}", TextComponent.toPlainText(event.getKickReasonComponent())));
|
||||
Messager msgr = new Messager(player);
|
||||
msgr.send(ConfigEntries.RECONNECT_KICK_MESSAGE.get(),
|
||||
new Replacement("{from}", from.getName()),
|
||||
new Replacement("{to}", server.getName()),
|
||||
new Replacement("{reason}", TextComponent.toPlainText(event.getKickReasonComponent())));
|
||||
event.setCancelled(true);
|
||||
event.setCancelServer(server);
|
||||
}
|
||||
|
@ -1,86 +0,0 @@
|
||||
package me.jaimemartz.lobbybalancer.manager;
|
||||
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.config.ConfigurationAdapter;
|
||||
import net.md_5.bungee.api.config.ListenerInfo;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class AdapterFix implements ConfigurationAdapter {
|
||||
private static final Map<String, ServerInfo> fakeServers = new HashMap<>();
|
||||
private static AdapterFix instance = null;
|
||||
private final ConfigurationAdapter adapter;
|
||||
|
||||
public AdapterFix(ConfigurationAdapter adapter) {
|
||||
this.adapter = adapter;
|
||||
}
|
||||
|
||||
public static void inject(ProxyServer server) {
|
||||
if (instance == null) {
|
||||
instance = new AdapterFix(server.getConfigurationAdapter());
|
||||
}
|
||||
server.setConfigurationAdapter(instance);
|
||||
}
|
||||
|
||||
public static void addFakeServer(ServerInfo server) {
|
||||
fakeServers.put(server.getName(), server);
|
||||
}
|
||||
|
||||
public static void removeFakeServer(ServerInfo server) {
|
||||
fakeServers.remove(server.getName());
|
||||
}
|
||||
|
||||
public static Map<String, ServerInfo> getFakeServers() {
|
||||
return fakeServers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
adapter.load();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInt(String path, int def) {
|
||||
return adapter.getInt(path, def);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getString(String path, String def) {
|
||||
return adapter.getString(path, def);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getBoolean(String path, boolean def) {
|
||||
return adapter.getBoolean(path, def);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<?> getList(String path, Collection<?> def) {
|
||||
return adapter.getList(path, def);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, ServerInfo> getServers() {
|
||||
Map<String, ServerInfo> res = adapter.getServers();
|
||||
res.putAll(fakeServers);
|
||||
return res;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ListenerInfo> getListeners() {
|
||||
return adapter.getListeners();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> getGroups(String player) {
|
||||
return adapter.getGroups(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> getPermissions(String group) {
|
||||
return adapter.getPermissions(group);
|
||||
}
|
||||
}
|
@ -16,8 +16,6 @@ import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
import static me.jaimemartz.lobbybalancer.LobbyBalancer.printStartupInfo;
|
||||
|
||||
public class GeolocationManager {
|
||||
private final DatabaseReader reader;
|
||||
|
||||
@ -33,7 +31,7 @@ public class GeolocationManager {
|
||||
File database = new File(dir, "GeoLite2-Country.mmdb");
|
||||
|
||||
if (!database.exists()) {
|
||||
printStartupInfo("Downloading database");
|
||||
plugin.getLogger().info("Downloading database");
|
||||
URL url = new URL("http://geolite.maxmind.com/download/geoip/database/GeoLite2-Country.mmdb.gz");
|
||||
try (ReadableByteChannel rbc = Channels.newChannel(url.openStream())) {
|
||||
try (FileOutputStream fos = new FileOutputStream(packed)) {
|
||||
@ -41,7 +39,7 @@ public class GeolocationManager {
|
||||
}
|
||||
}
|
||||
|
||||
printStartupInfo("Unpacking database");
|
||||
plugin.getLogger().info("Unpacking database");
|
||||
byte[] buffer = new byte[1024];
|
||||
try (GZIPInputStream in = new GZIPInputStream(new FileInputStream(packed))) {
|
||||
try (FileOutputStream out = new FileOutputStream(database)) {
|
||||
@ -52,12 +50,12 @@ public class GeolocationManager {
|
||||
}
|
||||
}
|
||||
|
||||
printStartupInfo("Deleting packed archive, success: " + (packed.delete() ? "yes" : "no"));
|
||||
plugin.getLogger().info("Deleting packed archive, success: " + (packed.delete() ? "yes" : "no"));
|
||||
} else {
|
||||
printStartupInfo("Database exists, no need to download again");
|
||||
plugin.getLogger().info("Database exists, no need to download again");
|
||||
}
|
||||
|
||||
printStartupInfo("Initializing database");
|
||||
plugin.getLogger().info("Initializing database");
|
||||
reader = new DatabaseReader.Builder(database).withCache(new CHMCache()).build();
|
||||
}
|
||||
|
||||
|
@ -9,8 +9,6 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static me.jaimemartz.lobbybalancer.LobbyBalancer.printStartupInfo;
|
||||
|
||||
public class PingManager {
|
||||
private final LobbyBalancer plugin;
|
||||
private boolean stopped = true;
|
||||
@ -28,7 +26,7 @@ public class PingManager {
|
||||
}
|
||||
stopped = false;
|
||||
tactic = PingTacticType.valueOf((ConfigEntries.SERVER_CHECK_MODE.get()).toUpperCase());
|
||||
printStartupInfo(String.format("Starting the ping task, the interval is %s", ConfigEntries.SERVER_CHECK_INTERVAL.get()));
|
||||
plugin.getLogger().info(String.format("Starting the ping task, the interval is %s", ConfigEntries.SERVER_CHECK_INTERVAL.get()));
|
||||
task = plugin.getProxy().getScheduler().schedule(plugin, () -> {
|
||||
for (ServerInfo server : plugin.getProxy().getServers().values()) {
|
||||
if (stopped) break;
|
||||
@ -63,10 +61,10 @@ public class PingManager {
|
||||
}
|
||||
|
||||
public ServerStatus getStatus(ServerInfo server) {
|
||||
if (stopped) {
|
||||
return new ServerStatus(server.getMotd(), server.getPlayers().size(), Integer.MAX_VALUE);
|
||||
} else {
|
||||
return storage.get(server);
|
||||
ServerStatus status = storage.get(server);
|
||||
if (status == null) {
|
||||
status = new ServerStatus(server.getMotd(), server.getPlayers().size(), Integer.MAX_VALUE);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package me.jaimemartz.lobbybalancer.section;
|
||||
import me.jaimemartz.faucet.Messager;
|
||||
import me.jaimemartz.lobbybalancer.LobbyBalancer;
|
||||
import me.jaimemartz.lobbybalancer.connection.ConnectionIntent;
|
||||
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;
|
||||
@ -10,6 +11,7 @@ import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.plugin.Command;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class SectionCommand extends Command {
|
||||
private transient final LobbyBalancer plugin;
|
||||
@ -27,10 +29,14 @@ public class SectionCommand extends Command {
|
||||
Messager msgr = new Messager(sender);
|
||||
if (sender instanceof ProxiedPlayer) {
|
||||
ProxiedPlayer player = (ProxiedPlayer) sender;
|
||||
PlayerLocker.lock(player);
|
||||
new ConnectionIntent(plugin, player, section) {
|
||||
@Override
|
||||
public void connect(ServerInfo server) {
|
||||
player.connect(server);
|
||||
plugin.getProxy().getScheduler().schedule(plugin, () -> {
|
||||
PlayerLocker.unlock(player);
|
||||
}, 2, TimeUnit.SECONDS);
|
||||
}
|
||||
};
|
||||
} else {
|
||||
|
@ -1,7 +1,6 @@
|
||||
package me.jaimemartz.lobbybalancer.section;
|
||||
|
||||
import me.jaimemartz.lobbybalancer.LobbyBalancer;
|
||||
import me.jaimemartz.lobbybalancer.manager.AdapterFix;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
import net.md_5.bungee.config.Configuration;
|
||||
|
||||
@ -9,8 +8,6 @@ import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import static me.jaimemartz.lobbybalancer.LobbyBalancer.printStartupInfo;
|
||||
|
||||
public class SectionManager {
|
||||
private ServerSection principal;
|
||||
private final LobbyBalancer plugin;
|
||||
@ -22,40 +19,38 @@ public class SectionManager {
|
||||
}
|
||||
|
||||
public void load() throws RuntimeException {
|
||||
printStartupInfo("Loading sections from the config, this may take a while...");
|
||||
plugin.getLogger().info("Loading sections from the config, this may take a while...");
|
||||
long starting = System.currentTimeMillis();
|
||||
|
||||
Configuration sections = plugin.getConfig().getSection("sections");
|
||||
sections.getKeys().forEach(name -> {
|
||||
printStartupInfo("Construction of section with name \"%s\"", name);
|
||||
plugin.getLogger().info(String.format("Construction of section with name \"%s\"", name));
|
||||
Configuration section = sections.getSection(name);
|
||||
ServerSection object = new ServerSection(name, section, this);
|
||||
sectionStorage.put(name, object);
|
||||
});
|
||||
|
||||
sectionStorage.forEach((name, section) -> {
|
||||
printStartupInfo("Pre-Initialization of section with name \"%s\"", name);
|
||||
plugin.getLogger().info(String.format("Pre-Initialization of section with name \"%s\"", name));
|
||||
section.preInit(plugin);
|
||||
});
|
||||
|
||||
sectionStorage.forEach((name, section) -> {
|
||||
printStartupInfo("Initialization of section with name \"%s\"", name);
|
||||
plugin.getLogger().info(String.format("Initialization of section with name \"%s\"", name));
|
||||
section.load(plugin);
|
||||
});
|
||||
|
||||
sectionStorage.forEach((name, section) -> {
|
||||
printStartupInfo("Post-Initialization of section with name \"%s\"", name);
|
||||
plugin.getLogger().info(String.format("Post-Initialization of section with name \"%s\"", name));
|
||||
section.postInit(plugin);
|
||||
});
|
||||
|
||||
AdapterFix.inject(plugin.getProxy());
|
||||
|
||||
long ending = System.currentTimeMillis() - starting;
|
||||
printStartupInfo("A total of %s section(s) have been loaded in %sms", sectionStorage.size(), ending);
|
||||
plugin.getLogger().info(String.format("A total of %s section(s) have been loaded in %sms", sectionStorage.size(), ending));
|
||||
}
|
||||
|
||||
public void flush() {
|
||||
printStartupInfo("Flushing section storage because of plugin shutdown");
|
||||
plugin.getLogger().info("Flushing section storage because of plugin shutdown");
|
||||
sectionStorage.forEach((key, value) -> {
|
||||
value.setValid(false);
|
||||
|
||||
@ -65,10 +60,12 @@ public class SectionManager {
|
||||
}
|
||||
|
||||
if (value.hasServer()) {
|
||||
AdapterFix.removeFakeServer(value.getServer());
|
||||
ServerInfo server = value.getServer();
|
||||
plugin.getProxy().getServers().remove(server.getName());
|
||||
}
|
||||
});
|
||||
|
||||
principal = null;
|
||||
sectionStorage.clear();
|
||||
sectionServers.clear();
|
||||
}
|
||||
@ -79,7 +76,7 @@ public class SectionManager {
|
||||
throw new IllegalArgumentException(String.format("The server \"%s\" is already in the section \"%s\"", server.getName(), other.getName()));
|
||||
}
|
||||
|
||||
printStartupInfo("Registering server \"%s\" to section \"%s\"", server.getName(), section.getName());
|
||||
plugin.getLogger().info(String.format("Registering server \"%s\" to section \"%s\"", server.getName(), section.getName()));
|
||||
sectionServers.put(server, section);
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,6 @@ package me.jaimemartz.lobbybalancer.section;
|
||||
|
||||
import me.jaimemartz.lobbybalancer.LobbyBalancer;
|
||||
import me.jaimemartz.lobbybalancer.connection.ProviderType;
|
||||
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;
|
||||
@ -14,8 +13,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static me.jaimemartz.lobbybalancer.LobbyBalancer.printStartupInfo;
|
||||
|
||||
public class ServerSection {
|
||||
private transient final Configuration section;
|
||||
private transient final SectionManager manager;
|
||||
@ -69,7 +66,7 @@ public class ServerSection {
|
||||
plugin.getProxy().getServers().forEach((key, value) -> {
|
||||
Matcher matcher = pattern.matcher(key);
|
||||
if (matcher.matches()) {
|
||||
printStartupInfo("Found a match with \"%s\" for entry \"%s\"", key, entry);
|
||||
plugin.getLogger().info(String.format("Found a match with \"%s\" for entry \"%s\"", key, entry));
|
||||
servers.add(value);
|
||||
manager.register(value, this);
|
||||
matches.set(true);
|
||||
@ -81,7 +78,7 @@ public class ServerSection {
|
||||
}
|
||||
});
|
||||
|
||||
printStartupInfo("Recognized %s server(s) out of %s entries", servers.size(), section.getStringList("servers").size());
|
||||
plugin.getLogger().info(String.format("Recognized %s server(s) out of %s entries on the section \"%s\"", servers.size(), section.getStringList("servers").size(), this.name));
|
||||
} else {
|
||||
throw new IllegalArgumentException(String.format("The section \"%s\" does not have any servers set", name));
|
||||
}
|
||||
@ -119,7 +116,7 @@ public class ServerSection {
|
||||
sect = sect.parent;
|
||||
}
|
||||
|
||||
printStartupInfo("The section \"%s\" inherits the provider from the section \"%s\"", this.name, sect.name);
|
||||
plugin.getLogger().info(String.format("The section \"%s\" inherits the provider from the section \"%s\"", this.name, sect.name));
|
||||
provider = sect.provider;
|
||||
inherit = true;
|
||||
}
|
||||
@ -132,7 +129,7 @@ public class ServerSection {
|
||||
int port = (int) Math.floor(Math.random() * (0xFFFF + 1));
|
||||
server = plugin.getProxy().constructServerInfo("@" + section.getString("section-server"), new InetSocketAddress("0.0.0.0", port), String.format("Server of Section %s", name), false);
|
||||
plugin.getSectionManager().register(server, this);
|
||||
AdapterFix.addFakeServer(server);
|
||||
plugin.getProxy().getServers().put(server.getName(), server);
|
||||
}
|
||||
|
||||
if (ConfigUtils.isSet(section, "section-command")) {
|
||||
|
@ -120,6 +120,7 @@ settings:
|
||||
# This affects both the fallback command and reconnect kick features
|
||||
fallback-principal: true
|
||||
|
||||
# Comment a message to disable it
|
||||
messages:
|
||||
connecting: '&aConnecting to {server}'
|
||||
failure: '&cCould not find a server to connect to'
|
||||
|
Loading…
Reference in New Issue
Block a user