From b9824a1f8162c07df2b719893c6e69a470891adb Mon Sep 17 00:00:00 2001 From: Jaime Martinez Rincon Date: Tue, 28 Mar 2017 22:31:05 +0200 Subject: [PATCH] Implemented server position argument (replacing old section argument) --- .../commands/FallbackCommand.java | 29 ++++++++++++------- .../lobbybalancer/commands/ManageCommand.java | 4 +-- .../configuration/ConfigEntries.java | 1 - .../connection/ConnectionIntent.java | 15 ++++------ .../listener/ServerConnectListener.java | 2 +- .../listener/ServerKickListener.java | 2 +- .../lobbybalancer/section/SectionCommand.java | 4 +-- src/main/resources/config.yml | 9 ++---- 8 files changed, 32 insertions(+), 34 deletions(-) diff --git a/src/main/java/me/jaimemartz/lobbybalancer/commands/FallbackCommand.java b/src/main/java/me/jaimemartz/lobbybalancer/commands/FallbackCommand.java index 82d9b13..81aeb48 100644 --- a/src/main/java/me/jaimemartz/lobbybalancer/commands/FallbackCommand.java +++ b/src/main/java/me/jaimemartz/lobbybalancer/commands/FallbackCommand.java @@ -7,6 +7,7 @@ import me.jaimemartz.lobbybalancer.connection.ConnectionIntent; import me.jaimemartz.lobbybalancer.section.ServerSection; import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.CommandSender; +import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.plugin.Command; import net.md_5.bungee.config.Configuration; @@ -36,16 +37,6 @@ public class FallbackCommand extends Command { return null; } - if (ConfigEntries.FALLBACK_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; - } - Configuration rules = plugin.getConfig().getSection("settings.fallback-command.rules"); String bind = rules.getString(section.getName()); ServerSection target = plugin.getSectionManager().getByName(bind); @@ -79,7 +70,23 @@ public class FallbackCommand extends Command { try { ServerSection section = callable.call(); if (section != null) { - ConnectionIntent.simple(plugin, player, section); + if (args.length == 1) { + try { + int number = Integer.parseInt(args[0]); + if (number <= 0) { + msgr.send(ConfigEntries.INVALID_INPUT_MESSAGE.get()); + } else if (number > section.getServers().size()) { + msgr.send(ConfigEntries.FAILURE_MESSAGE.get()); + } else { + ServerInfo server = section.getSortedServers().get(number - 1); + ConnectionIntent.direct(plugin, player, server); + } + } catch (NumberFormatException e) { + msgr.send(ConfigEntries.INVALID_INPUT_MESSAGE.get()); + } + } else { + ConnectionIntent.simple(plugin, player, section); + } } } catch (Exception e) { //Nothing to do diff --git a/src/main/java/me/jaimemartz/lobbybalancer/commands/ManageCommand.java b/src/main/java/me/jaimemartz/lobbybalancer/commands/ManageCommand.java index bc2c1e3..7a4bc32 100644 --- a/src/main/java/me/jaimemartz/lobbybalancer/commands/ManageCommand.java +++ b/src/main/java/me/jaimemartz/lobbybalancer/commands/ManageCommand.java @@ -35,7 +35,7 @@ public class ManageCommand extends Command { if (sender.hasPermission("lobbybalancer.admin")) { if (args.length != 0) { switch (args[0].toLowerCase()) { - case "simple": { + case "connect": { if (args.length >= 2) { String input = args[1]; ServerSection section = plugin.getSectionManager().getByName(input); @@ -191,7 +191,7 @@ public class ManageCommand extends Command { "&7Available commands:", "&3/section list &7- &cTells you which sections are configured in the plugin", "&3/section info
&7- &cTells you info about the section", - "&3/section simple
[player] &7- &cConnects you or the specified player to that section", + "&3/section connect
[player] &7- &cConnects you or the specified player to that section", "&7&m-----------------------------------------------------" ); } diff --git a/src/main/java/me/jaimemartz/lobbybalancer/configuration/ConfigEntries.java b/src/main/java/me/jaimemartz/lobbybalancer/configuration/ConfigEntries.java index 945b76a..0afcbca 100644 --- a/src/main/java/me/jaimemartz/lobbybalancer/configuration/ConfigEntries.java +++ b/src/main/java/me/jaimemartz/lobbybalancer/configuration/ConfigEntries.java @@ -37,7 +37,6 @@ public class ConfigEntries implements ConfigEntryHolder { public static final ConfigEntry FALLBACK_COMMAND_PERMISSION = new ConfigEntry<>(0, "settings.fallback-command.permission", ""); public static final ConfigEntry> FALLBACK_COMMAND_IGNORED_SECTIONS = new ConfigEntry<>(0, "settings.fallback-command.ignored", Collections.emptyList()); public static final ConfigEntry FALLBACK_COMMAND_RESTRICTED = new ConfigEntry<>(0, "settings.fallback-command.restricted", true); - public static final ConfigEntry FALLBACK_COMMAND_ARGUMENTS = new ConfigEntry<>(0, "settings.fallback-command.arguments", true); public static final ConfigEntry AUTO_RELOAD_ENABLED = new ConfigEntry<>(0, "settings.auto-reload", true); public static final ConfigEntry REDIS_BUNGEE_ENABLED = new ConfigEntry<>(0, "settings.redis-bungee", false); diff --git a/src/main/java/me/jaimemartz/lobbybalancer/connection/ConnectionIntent.java b/src/main/java/me/jaimemartz/lobbybalancer/connection/ConnectionIntent.java index 2c361ad..5099acc 100644 --- a/src/main/java/me/jaimemartz/lobbybalancer/connection/ConnectionIntent.java +++ b/src/main/java/me/jaimemartz/lobbybalancer/connection/ConnectionIntent.java @@ -31,11 +31,12 @@ public abstract class ConnectionIntent { if (section.getProvider() != ProviderType.NONE) { ServerInfo target = this.fetchServer(plugin, player, section, provider, servers); if (target != null) { - new Messager(player).send(ConfigEntries.CONNECTING_MESSAGE.get(), new Replacement("{server}", target.getName())); - this.simple(target); + new Messager(player).send(ConfigEntries.CONNECTING_MESSAGE.get(), + new Replacement("{server}", target.getName()) + ); + this.connect(target); } else { new Messager(player).send(ConfigEntries.FAILURE_MESSAGE.get()); - this.failure(); } } } @@ -84,16 +85,12 @@ public abstract class ConnectionIntent { return null; } - public abstract void simple(ServerInfo server); - - public void failure() { - //Nothing to do - } + public abstract void connect(ServerInfo server); public static void simple(LobbyBalancer plugin, ProxiedPlayer player, ServerSection section) { new ConnectionIntent(plugin, player, section) { @Override - public void simple(ServerInfo server) { + public void connect(ServerInfo server) { direct(plugin, player, server); } }; diff --git a/src/main/java/me/jaimemartz/lobbybalancer/listener/ServerConnectListener.java b/src/main/java/me/jaimemartz/lobbybalancer/listener/ServerConnectListener.java index eb9232b..09bcf19 100644 --- a/src/main/java/me/jaimemartz/lobbybalancer/listener/ServerConnectListener.java +++ b/src/main/java/me/jaimemartz/lobbybalancer/listener/ServerConnectListener.java @@ -65,7 +65,7 @@ public class ServerConnectListener implements Listener { if (section != null) { new ConnectionIntent(plugin, player, section) { @Override - public void simple(ServerInfo server) { + public void connect(ServerInfo server) { if (ConfigEntries.ASSIGN_TARGETS_ENABLED.get()) { ServerAssignRegistry.assignTarget(player, section, server); } diff --git a/src/main/java/me/jaimemartz/lobbybalancer/listener/ServerKickListener.java b/src/main/java/me/jaimemartz/lobbybalancer/listener/ServerKickListener.java index 68ddbc3..9f2b288 100644 --- a/src/main/java/me/jaimemartz/lobbybalancer/listener/ServerKickListener.java +++ b/src/main/java/me/jaimemartz/lobbybalancer/listener/ServerKickListener.java @@ -115,7 +115,7 @@ public class ServerKickListener implements Listener { new ConnectionIntent(plugin, player, section, servers) { @Override - public void simple(ServerInfo server) { + public void connect(ServerInfo server) { PlayerLocker.lock(player); msgr.send(ConfigEntries.KICK_MESSAGE.get(), new Replacement("{from}", from.getName()), diff --git a/src/main/java/me/jaimemartz/lobbybalancer/section/SectionCommand.java b/src/main/java/me/jaimemartz/lobbybalancer/section/SectionCommand.java index c88a3fa..bd73f8e 100644 --- a/src/main/java/me/jaimemartz/lobbybalancer/section/SectionCommand.java +++ b/src/main/java/me/jaimemartz/lobbybalancer/section/SectionCommand.java @@ -28,17 +28,15 @@ public class SectionCommand extends Command { Messager msgr = new Messager(sender); if (sender instanceof ProxiedPlayer) { ProxiedPlayer player = (ProxiedPlayer) sender; - if (args.length == 1) { try { int number = Integer.parseInt(args[0]); - if (number <= 0) { msgr.send(ConfigEntries.INVALID_INPUT_MESSAGE.get()); } else if (number > section.getServers().size()) { msgr.send(ConfigEntries.FAILURE_MESSAGE.get()); } else { - ServerInfo server = section.getSortedServers().get(number); + ServerInfo server = section.getSortedServers().get(number - 1); ConnectionIntent.direct(plugin, player, server); } } catch (NumberFormatException e) { diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 5bfb2c0..4aecd58 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -13,7 +13,7 @@ settings: # Pings to the servers to see if they can be accessed or not server-check: - # If this is disabled the players will simple to the first server available + # If this is disabled the players will connect to the first server available enabled: true # Use either CUSTOM or GENERIC, the first one generally works the best @@ -34,7 +34,7 @@ settings: # The descriptions that mark a server as non accessible marker-descs: ["Server is not accessible", "Gamemode has already started"] - # This will simple the player to a server of the parent of the section the player is kicked from + # This will connect the player to a server of the parent of the section the player is kicked from reconnect-kick: # If this is enabled the kick reasons must still match for this to work enabled: true @@ -66,7 +66,7 @@ settings: rules: 'section-from': 'section-to' - # This will simple the player to a server of the parent of the section the player is currently on + # This will connect the player to a server of the parent of the section the player is currently on fallback-command: # If this is disabled the command will not be registered enabled: true @@ -86,9 +86,6 @@ settings: # 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 - # You can override the behavior with rules, overriding the parent section # This will set the section to go when you come from the section specified rules: