From b29254fd7b9fa59f1d55485914366c67024dd311 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Mart=C3=ADnez=20Rinc=C3=B3n?= Date: Thu, 11 Jan 2018 15:54:21 +0100 Subject: [PATCH] Made the section router work on all connection types --- Main Plugin/pom.xml | 2 +- .../connection/ConnectionIntent.java | 31 ++++++++++++++++--- .../listeners/ServerConnectListener.java | 29 ----------------- 3 files changed, 28 insertions(+), 34 deletions(-) diff --git a/Main Plugin/pom.xml b/Main Plugin/pom.xml index 94fbc4f..269e527 100644 --- a/Main Plugin/pom.xml +++ b/Main Plugin/pom.xml @@ -11,7 +11,7 @@ PlayerBalancer Plugin playerbalancer-plugin - 2.1.5.1 + 2.1.5.2 PlayerBalancer diff --git a/Main Plugin/src/main/java/com/jaimemartz/playerbalancer/connection/ConnectionIntent.java b/Main Plugin/src/main/java/com/jaimemartz/playerbalancer/connection/ConnectionIntent.java index 97e7f18..6dc2419 100644 --- a/Main Plugin/src/main/java/com/jaimemartz/playerbalancer/connection/ConnectionIntent.java +++ b/Main Plugin/src/main/java/com/jaimemartz/playerbalancer/connection/ConnectionIntent.java @@ -11,11 +11,11 @@ import net.md_5.bungee.api.connection.Server; import java.util.ArrayList; import java.util.List; +import java.util.Map; import java.util.concurrent.TimeUnit; import static com.jaimemartz.playerbalancer.utils.MessageUtils.safeNull; -//TODO I don't like this, improve it public abstract class ConnectionIntent { protected final PlayerBalancer plugin; protected final ProxiedPlayer player; @@ -24,7 +24,7 @@ public abstract class ConnectionIntent { public ConnectionIntent(PlayerBalancer plugin, ProxiedPlayer player, ProviderType provider, ServerSection section, List servers) { this.plugin = plugin; this.player = player; - this.section = section; + this.section = tryRoute(player, section); MessageUtils.send(player, plugin.getSettings().getMessagesProps().getConnectingMessage(), (str) -> str.replace("{section}", section.getName()) @@ -101,9 +101,33 @@ public abstract class ConnectionIntent { return null; } + private ServerSection tryRoute(ProxiedPlayer player, ServerSection section) { + if (plugin.getSettings().getFeaturesProps().getPermissionRouterProps().isEnabled()) { + Map routes = plugin.getSettings().getFeaturesProps().getPermissionRouterProps().getRules().get(section.getName()); + + if (routes != null) { + for (Map.Entry route : routes.entrySet()) { + if (player.hasPermission(route.getKey())) { + ServerSection bind = plugin.getSectionManager().getByName(route.getValue()); + ServerSection current = plugin.getSectionManager().getByPlayer(player); + + if (bind != null) { + if (current == bind) + break; + + return bind; + } + + break; + } + } + } + } + return section; + } + public abstract void connect(ServerInfo server, Callback callback); - //TODO Create this as a type public static void simple(PlayerBalancer plugin, ProxiedPlayer player, ServerSection section) { new ConnectionIntent(plugin, player, section) { @Override @@ -113,7 +137,6 @@ public abstract class ConnectionIntent { }; } - //TODO Create this as a type public static void direct(PlayerBalancer plugin, ProxiedPlayer player, ServerInfo server, Callback callback) { PlayerLocker.lock(player); player.connect(server, (result, throwable) -> { diff --git a/Main Plugin/src/main/java/com/jaimemartz/playerbalancer/listeners/ServerConnectListener.java b/Main Plugin/src/main/java/com/jaimemartz/playerbalancer/listeners/ServerConnectListener.java index ceedb65..b44e293 100644 --- a/Main Plugin/src/main/java/com/jaimemartz/playerbalancer/listeners/ServerConnectListener.java +++ b/Main Plugin/src/main/java/com/jaimemartz/playerbalancer/listeners/ServerConnectListener.java @@ -5,7 +5,6 @@ import com.jaimemartz.playerbalancer.connection.ConnectionIntent; import com.jaimemartz.playerbalancer.connection.ServerAssignRegistry; import com.jaimemartz.playerbalancer.helper.PlayerLocker; import com.jaimemartz.playerbalancer.section.ServerSection; -import com.jaimemartz.playerbalancer.settings.props.features.PermissionRouterProps; import com.jaimemartz.playerbalancer.utils.MessageUtils; import net.md_5.bungee.api.Callback; import net.md_5.bungee.api.config.ServerInfo; @@ -15,17 +14,11 @@ import net.md_5.bungee.api.plugin.Listener; import net.md_5.bungee.event.EventHandler; import net.md_5.bungee.event.EventPriority; -import java.util.Map; - public class ServerConnectListener implements Listener { private final PlayerBalancer plugin; - private final PermissionRouterProps permissionRouterProps; - public ServerConnectListener(PlayerBalancer plugin) { this.plugin = plugin; - - this.permissionRouterProps = plugin.getSettings().getFeaturesProps().getPermissionRouterProps(); } @EventHandler(priority = EventPriority.HIGHEST) @@ -63,28 +56,6 @@ public class ServerConnectListener implements Listener { ServerSection section = plugin.getSectionManager().getByServer(target); if (section != null) { - if (permissionRouterProps.isEnabled()) { - Map routes = permissionRouterProps.getRules().get(section.getName()); - - if (routes != null) { - for (Map.Entry route : routes.entrySet()) { - if (player.hasPermission(route.getKey())) { - ServerSection bind = plugin.getSectionManager().getByName(route.getValue()); - ServerSection current = plugin.getSectionManager().getByPlayer(player); - - if (bind != null) { - if (current == bind) - break; - - return bind; - } - - break; - } - } - } - } - //Checks only for servers (not the section server) if (!target.equals(section.getServer())) { if (plugin.getSectionManager().isDummy(section)) {