From 6cea42767b09c6925b60a674da8502c3f116e71d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Mart=C3=ADnez=20Rinc=C3=B3n?= Date: Wed, 29 Nov 2017 18:52:21 +0100 Subject: [PATCH] Last commit for version 2.1.2.2 --- Main Plugin/pom.xml | 2 +- .../listeners/ServerConnectListener.java | 33 ++++++------- .../listeners/ServerKickListener.java | 48 ++++++++++--------- .../playerbalancer/manager/PlayerLocker.java | 1 - .../playerbalanceraddon/MainCommand.java | 4 ++ 5 files changed, 47 insertions(+), 41 deletions(-) diff --git a/Main Plugin/pom.xml b/Main Plugin/pom.xml index f6de4e2..bb7148c 100644 --- a/Main Plugin/pom.xml +++ b/Main Plugin/pom.xml @@ -11,7 +11,7 @@ PlayerBalancer Plugin playerbalancer-plugin - 2.1.3 + 2.1.2.2 PlayerBalancer 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 c415b0a..50ade35 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 @@ -28,24 +28,25 @@ public class ServerConnectListener implements Listener { ServerSection section = getSection(player, target); - if (section != null) { - if (target.equals(section.getServer())) { - event.setCancelled(true); - } + if (section == null) + return; - new ConnectionIntent(plugin, player, section) { - @Override - public void connect(ServerInfo server, Callback callback) { - if (plugin.getSectionManager().isReiterative(section)) { - ServerAssignRegistry.assignTarget(player, section, server); - } - - event.setCancelled(false); - event.setTarget(server); - callback.done(true, null); - } - }; + if (target.equals(section.getServer())) { + event.setCancelled(true); } + + new ConnectionIntent(plugin, player, section) { + @Override + public void connect(ServerInfo server, Callback callback) { + if (plugin.getSectionManager().isReiterative(section)) { + ServerAssignRegistry.assignTarget(player, section, server); + } + + event.setCancelled(false); + event.setTarget(server); + callback.done(true, null); + } + }; } 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 1da8065..18ec00c 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 @@ -59,32 +59,34 @@ public class ServerKickListener implements Listener { )); } - if (matches) { - ServerSection section = getSection(player, from); + if (!matches) + return; - if (section != null) { - List servers = new ArrayList<>(); - servers.addAll(section.getServers()); - servers.remove(from); + ServerSection section = getSection(player, from); - new ConnectionIntent(plugin, player, section, servers) { - @Override - public void connect(ServerInfo server, Callback callback) { - PlayerLocker.lock(player); - event.setCancelled(true); - event.setCancelServer(server); - MessageUtils.send(player, messages.getKickMessage(), (str) -> str - .replace("{reason}", event.getKickReason()) - .replace("{from}", from.getName()) - .replace("{to}", server.getName())); - plugin.getProxy().getScheduler().schedule(plugin, () -> { - PlayerLocker.unlock(player); - }, 5, TimeUnit.SECONDS); - callback.done(true, null); - } - }; + if (section == null) + return; + + List servers = new ArrayList<>(); + servers.addAll(section.getServers()); + servers.remove(from); + + new ConnectionIntent(plugin, player, section, servers) { + @Override + public void connect(ServerInfo server, Callback callback) { + PlayerLocker.lock(player); + event.setCancelled(true); + event.setCancelServer(server); + MessageUtils.send(player, messages.getKickMessage(), (str) -> str + .replace("{reason}", event.getKickReason()) + .replace("{from}", from.getName()) + .replace("{to}", server.getName())); + plugin.getProxy().getScheduler().schedule(plugin, () -> { + PlayerLocker.unlock(player); + }, 5, TimeUnit.SECONDS); + callback.done(true, null); } - } + }; } private ServerSection getSection(ProxiedPlayer player, ServerInfo from) { diff --git a/Main Plugin/src/main/java/com/jaimemartz/playerbalancer/manager/PlayerLocker.java b/Main Plugin/src/main/java/com/jaimemartz/playerbalancer/manager/PlayerLocker.java index c9add2f..413bfa7 100644 --- a/Main Plugin/src/main/java/com/jaimemartz/playerbalancer/manager/PlayerLocker.java +++ b/Main Plugin/src/main/java/com/jaimemartz/playerbalancer/manager/PlayerLocker.java @@ -7,7 +7,6 @@ import java.util.HashSet; import java.util.Set; import java.util.UUID; -//TODO improve this public class PlayerLocker { private static final Set storage = Collections.synchronizedSet(new HashSet()); diff --git a/Spigot Addon/src/main/java/com/jaimemartz/playerbalanceraddon/MainCommand.java b/Spigot Addon/src/main/java/com/jaimemartz/playerbalanceraddon/MainCommand.java index f8321b5..6deb15d 100644 --- a/Spigot Addon/src/main/java/com/jaimemartz/playerbalanceraddon/MainCommand.java +++ b/Spigot Addon/src/main/java/com/jaimemartz/playerbalanceraddon/MainCommand.java @@ -90,11 +90,15 @@ public class MainCommand implements CommandExecutor { sender.sendMessage(ChatColor.GRAY + "Available commands:"); sender.sendMessage(ChatColor.AQUA + "/spb connect
[player]" + ChatColor.GRAY + " - " + ChatColor.RED + "Connects you or the specified player to that section"); sender.sendMessage(ChatColor.AQUA + "/spb fallback [player]" + ChatColor.GRAY + " - " + ChatColor.RED + "Connects you or the specified player to the parent of the current section"); + + /* TODO For version 2.1.3 of the main plugin sender.sendMessage(ChatColor.AQUA + "/spb bypassconnect [player]" + ChatColor.GRAY + " - " + ChatColor.RED + "Connects you or the specified player to a specific server without balancing"); sender.sendMessage(ChatColor.AQUA + "/spb setbypass [player]" + ChatColor.GRAY + " - " + ChatColor.RED + "Sets a bypass for you or the specified player"); sender.sendMessage(ChatColor.AQUA + "/spb clearbypass [player]" + ChatColor.GRAY + " - " + ChatColor.RED + "Clears the bypass for you or the specified player"); sender.sendMessage(ChatColor.AQUA + "/spb overridestatus " + ChatColor.GRAY + " - " + ChatColor.RED + "Overrides the accessible status of a specific server, over anything else"); sender.sendMessage(ChatColor.AQUA + "/spb clearoverride " + ChatColor.GRAY + " - " + ChatColor.RED + "Clears the overridden status of a specific server"); + */ + sender.sendMessage(ChatColor.STRIKETHROUGH + ChatColor.GRAY.toString() + Strings.repeat("-", 53)); } }