From 25d70548c9a7572cad174e42c9b6cd1850404104 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Mart=C3=ADnez=20Rinc=C3=B3n?= Date: Mon, 15 Jan 2018 20:06:53 +0100 Subject: [PATCH] Fixed issues with the router --- Main Plugin/pom.xml | 2 +- .../connection/ConnectionIntent.java | 42 ++++++++++--------- .../listeners/ServerConnectListener.java | 2 +- .../listeners/ServerKickListener.java | 11 ++--- Main Plugin/src/main/resources/default.conf | 2 +- 5 files changed, 29 insertions(+), 30 deletions(-) diff --git a/Main Plugin/pom.xml b/Main Plugin/pom.xml index 269e527..277f528 100644 --- a/Main Plugin/pom.xml +++ b/Main Plugin/pom.xml @@ -11,7 +11,7 @@ PlayerBalancer Plugin playerbalancer-plugin - 2.1.5.2 + 2.1.5.3 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 6dc2419..cc7482b 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 @@ -17,20 +17,30 @@ import java.util.concurrent.TimeUnit; import static com.jaimemartz.playerbalancer.utils.MessageUtils.safeNull; public abstract class ConnectionIntent { - protected final PlayerBalancer plugin; - protected final ProxiedPlayer player; - protected final ServerSection section; + private final PlayerBalancer plugin; + private final ProxiedPlayer player; + private final ServerSection section; + private final List exclusions; - public ConnectionIntent(PlayerBalancer plugin, ProxiedPlayer player, ProviderType provider, ServerSection section, List servers) { + public ConnectionIntent(PlayerBalancer plugin, ProxiedPlayer player, ServerSection section) { this.plugin = plugin; this.player = player; this.section = tryRoute(player, section); + this.exclusions = new ArrayList<>(); + } + public List getExclusions() { + return exclusions; + } + + public boolean execute() { MessageUtils.send(player, plugin.getSettings().getMessagesProps().getConnectingMessage(), (str) -> str.replace("{section}", section.getName()) .replace("{alias}", safeNull(section.getProps().getAlias())) ); + List servers = new ArrayList<>(section.getServers()); + //Prevents removing servers from the section if (servers == section.getServers()) { throw new IllegalStateException("The servers list parameter is the same reference, this cannot happen"); @@ -43,7 +53,7 @@ public abstract class ConnectionIntent { } if (section.getImplicitProvider() != ProviderType.NONE) { - ServerInfo target = this.fetchServer(player, section, provider, servers); + ServerInfo target = this.fetchServer(player, section, section.getImplicitProvider(), servers); if (target != null) { this.connect(target, (response, throwable) -> { if (response) { //only if the connect has been executed correctly @@ -58,18 +68,8 @@ public abstract class ConnectionIntent { MessageUtils.send(player, plugin.getSettings().getMessagesProps().getFailureMessage()); } } - } - public ConnectionIntent(PlayerBalancer plugin, ProxiedPlayer player, ServerSection section) { - this(plugin, player, section.getImplicitProvider(), section); - } - - public ConnectionIntent(PlayerBalancer plugin, ProxiedPlayer player, ProviderType type, ServerSection section) { - this(plugin, player, type, section, new ArrayList<>(section.getServers())); - } - - public ConnectionIntent(PlayerBalancer plugin, ProxiedPlayer player, ServerSection section, List servers) { - this(plugin, player, section.getImplicitProvider(), section, servers); + return false; } private ServerInfo fetchServer(ProxiedPlayer player, ServerSection section, ProviderType provider, List servers) { @@ -104,16 +104,17 @@ public abstract class ConnectionIntent { private ServerSection tryRoute(ProxiedPlayer player, ServerSection section) { if (plugin.getSettings().getFeaturesProps().getPermissionRouterProps().isEnabled()) { Map routes = plugin.getSettings().getFeaturesProps().getPermissionRouterProps().getRules().get(section.getName()); + ServerSection current = plugin.getSectionManager().getByPlayer(player); 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) + if (current == bind) { break; + } return bind; } @@ -123,6 +124,7 @@ public abstract class ConnectionIntent { } } } + return section; } @@ -134,7 +136,7 @@ public abstract class ConnectionIntent { public void connect(ServerInfo server, Callback callback) { ConnectionIntent.direct(plugin, player, server, callback); } - }; + }.execute(); } public static void direct(PlayerBalancer plugin, ProxiedPlayer player, ServerInfo server, Callback callback) { @@ -148,4 +150,4 @@ public abstract class ConnectionIntent { callback.done(result, throwable); }); } -} \ No newline at end of file +} 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 b44e293..f03fdd8 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 @@ -49,7 +49,7 @@ public class ServerConnectListener implements Listener { event.setTarget(server); callback.done(true, null); } - }; + }.execute(); } private ServerSection getSection(ProxiedPlayer player, ServerInfo target) { diff --git a/Main Plugin/src/main/java/com/jaimemartz/playerbalancer/listeners/ServerKickListener.java b/Main Plugin/src/main/java/com/jaimemartz/playerbalancer/listeners/ServerKickListener.java index 34aeda7..507e9bb 100644 --- a/Main Plugin/src/main/java/com/jaimemartz/playerbalancer/listeners/ServerKickListener.java +++ b/Main Plugin/src/main/java/com/jaimemartz/playerbalancer/listeners/ServerKickListener.java @@ -16,8 +16,6 @@ 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.ArrayList; -import java.util.List; import java.util.concurrent.TimeUnit; public class ServerKickListener implements Listener { @@ -67,11 +65,7 @@ public class ServerKickListener implements Listener { if (section == null) return; - List servers = new ArrayList<>(); - servers.addAll(section.getServers()); - servers.remove(from); - - new ConnectionIntent(plugin, player, section, servers) { + ConnectionIntent intent = new ConnectionIntent(plugin, player, section) { @Override public void connect(ServerInfo server, Callback callback) { PlayerLocker.lock(player); @@ -87,6 +81,9 @@ public class ServerKickListener implements Listener { callback.done(true, null); } }; + + intent.getExclusions().add(from); + intent.execute(); } private ServerSection getSection(ProxiedPlayer player, ServerInfo from) { diff --git a/Main Plugin/src/main/resources/default.conf b/Main Plugin/src/main/resources/default.conf index 5f99437..f83268f 100644 --- a/Main Plugin/src/main/resources/default.conf +++ b/Main Plugin/src/main/resources/default.conf @@ -229,7 +229,7 @@ features { rules { general-lobbies { - special.permission=other-lobby-section + "special.permission"=other-lobby-section } } }