diff --git a/src/main/java/com/jaimemartz/playerbalancer/commands/FallbackCommand.java b/src/main/java/com/jaimemartz/playerbalancer/commands/FallbackCommand.java index 95747b7..36152eb 100644 --- a/src/main/java/com/jaimemartz/playerbalancer/commands/FallbackCommand.java +++ b/src/main/java/com/jaimemartz/playerbalancer/commands/FallbackCommand.java @@ -85,15 +85,7 @@ public class FallbackCommand extends Command { MessageUtils.send(player, ConfigEntries.INVALID_INPUT_MESSAGE.get()); } } else { - //TODO instead of checking if the sections are the same, we have to check if the section the player is - //TODO currently going to contains the server the player is connected to - //TODO this should be done in ConnectionIntent instead of here - ServerSection current = plugin.getSectionManager().getByPlayer(player); - if (current != target) { - ConnectionIntent.simple(plugin, player, target); - } else { - MessageUtils.send(player, ConfigEntries.SAME_SECTION.get()); - } + ConnectionIntent.simple(plugin, player, target); } } } catch (Exception e) { diff --git a/src/main/java/com/jaimemartz/playerbalancer/connection/ConnectionIntent.java b/src/main/java/com/jaimemartz/playerbalancer/connection/ConnectionIntent.java index adc234e..ef1f5d7 100644 --- a/src/main/java/com/jaimemartz/playerbalancer/connection/ConnectionIntent.java +++ b/src/main/java/com/jaimemartz/playerbalancer/connection/ConnectionIntent.java @@ -9,6 +9,7 @@ import com.jaimemartz.playerbalancer.utils.MessageUtils; import net.md_5.bungee.api.Callback; import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.api.connection.ProxiedPlayer; +import net.md_5.bungee.api.connection.Server; import java.util.ArrayList; import java.util.List; @@ -30,7 +31,15 @@ public abstract class ConnectionIntent { ); if (servers == section.getServers()) { - throw new IllegalStateException("The servers list parameter is the same object as the section servers list, this cannot happen"); + throw new IllegalStateException("The servers list parameter is the same reference, this cannot happen"); + } + + Server current = player.getServer(); + if (current != null) { + if (section.getServers().contains(current.getInfo())) { + MessageUtils.send(player, ConfigEntries.SAME_SECTION.get()); + return; + } } if (section.getProvider() != ProviderType.NONE) { diff --git a/src/main/java/com/jaimemartz/playerbalancer/connection/types/DirectionConnection.java b/src/main/java/com/jaimemartz/playerbalancer/connection/types/DirectionConnection.java deleted file mode 100644 index 35f83f2..0000000 --- a/src/main/java/com/jaimemartz/playerbalancer/connection/types/DirectionConnection.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.jaimemartz.playerbalancer.connection.types; - -public class DirectionConnection { - // TODO: 09/08/2017 -} diff --git a/src/main/java/com/jaimemartz/playerbalancer/listener/ServerConnectListener.java b/src/main/java/com/jaimemartz/playerbalancer/listener/ServerConnectListener.java index c51668e..15faab5 100644 --- a/src/main/java/com/jaimemartz/playerbalancer/listener/ServerConnectListener.java +++ b/src/main/java/com/jaimemartz/playerbalancer/listener/ServerConnectListener.java @@ -7,6 +7,7 @@ import com.jaimemartz.playerbalancer.connection.ServerAssignRegistry; import com.jaimemartz.playerbalancer.manager.PlayerLocker; import com.jaimemartz.playerbalancer.section.ServerSection; import com.jaimemartz.playerbalancer.utils.MessageUtils; +import net.md_5.bungee.api.Callback; import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.event.ServerConnectEvent; @@ -64,12 +65,13 @@ public class ServerConnectListener implements Listener { if (section != null) { new ConnectionIntent(plugin, player, section) { @Override - public void connect(ServerInfo server) { + public void connect(ServerInfo server, Callback callback) { if (ConfigEntries.ASSIGN_TARGETS_ENABLED.get()) { ServerAssignRegistry.assignTarget(player, section, server); } event.setTarget(server); + callback.done(true, null); } }; } diff --git a/src/main/java/com/jaimemartz/playerbalancer/listener/ServerKickListener.java b/src/main/java/com/jaimemartz/playerbalancer/listener/ServerKickListener.java index ac1946c..5742c01 100644 --- a/src/main/java/com/jaimemartz/playerbalancer/listener/ServerKickListener.java +++ b/src/main/java/com/jaimemartz/playerbalancer/listener/ServerKickListener.java @@ -6,6 +6,7 @@ import com.jaimemartz.playerbalancer.connection.ConnectionIntent; import com.jaimemartz.playerbalancer.manager.PlayerLocker; import com.jaimemartz.playerbalancer.section.ServerSection; import com.jaimemartz.playerbalancer.utils.MessageUtils; +import net.md_5.bungee.api.Callback; import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.api.connection.ProxiedPlayer; @@ -110,7 +111,7 @@ public class ServerKickListener implements Listener { new ConnectionIntent(plugin, player, section, servers) { @Override - public void connect(ServerInfo server) { + public void connect(ServerInfo server, Callback callback) { PlayerLocker.lock(player); MessageUtils.send(player, ConfigEntries.KICK_MESSAGE.get(), (str) -> str.replace("{from}", from.getName()) @@ -121,6 +122,7 @@ public class ServerKickListener implements Listener { plugin.getProxy().getScheduler().schedule(plugin, () -> { PlayerLocker.unlock(player); }, 5, TimeUnit.SECONDS); + callback.done(true, null); } }; } diff --git a/src/main/java/com/jaimemartz/playerbalancer/section/SectionManager.java b/src/main/java/com/jaimemartz/playerbalancer/section/SectionManager.java index 887bf15..283ee00 100644 --- a/src/main/java/com/jaimemartz/playerbalancer/section/SectionManager.java +++ b/src/main/java/com/jaimemartz/playerbalancer/section/SectionManager.java @@ -56,6 +56,7 @@ public class SectionManager { section.postInit(); }); + //todo unify loading code with SectionManager if (ConfigEntries.SERVERS_UPDATE.get()) { updateTask = plugin.getProxy().getScheduler().schedule(plugin, () -> { this.sections.forEach((name, section) -> { diff --git a/src/main/java/com/jaimemartz/playerbalancer/utils/AlphanumComparator.java b/src/main/java/com/jaimemartz/playerbalancer/utils/AlphanumComparator.java index 6093679..16db5e8 100644 --- a/src/main/java/com/jaimemartz/playerbalancer/utils/AlphanumComparator.java +++ b/src/main/java/com/jaimemartz/playerbalancer/utils/AlphanumComparator.java @@ -39,7 +39,7 @@ import java.util.Comparator; * Use the static "sort" method from the java.util.Collections class: * Collections.sort(your list, new AlphanumComparator()); */ -public class AlphanumComparator implements Comparator +public final class AlphanumComparator implements Comparator { private final boolean isDigit(char ch) { diff --git a/src/main/java/com/jaimemartz/playerbalancer/utils/DigitUtils.java b/src/main/java/com/jaimemartz/playerbalancer/utils/DigitUtils.java index e083a8c..613ffe3 100644 --- a/src/main/java/com/jaimemartz/playerbalancer/utils/DigitUtils.java +++ b/src/main/java/com/jaimemartz/playerbalancer/utils/DigitUtils.java @@ -1,6 +1,6 @@ package com.jaimemartz.playerbalancer.utils; -public class DigitUtils { +public final class DigitUtils { public static int getDigits(String string, int digits) { StringBuilder builder = new StringBuilder(); diff --git a/src/main/java/com/jaimemartz/playerbalancer/utils/FixedAdapter.java b/src/main/java/com/jaimemartz/playerbalancer/utils/FixedAdapter.java index 03f8320..3bb9a58 100644 --- a/src/main/java/com/jaimemartz/playerbalancer/utils/FixedAdapter.java +++ b/src/main/java/com/jaimemartz/playerbalancer/utils/FixedAdapter.java @@ -7,7 +7,7 @@ import net.md_5.bungee.api.config.ServerInfo; import java.util.HashMap; import java.util.Map; -public class FixedAdapter extends AdapterWrapper { +public final class FixedAdapter extends AdapterWrapper { private static final Map fakeServers = new HashMap<>(); static { diff --git a/src/main/java/com/jaimemartz/playerbalancer/utils/GuestPaste.java b/src/main/java/com/jaimemartz/playerbalancer/utils/GuestPaste.java index 68ddfcc..fa8467a 100644 --- a/src/main/java/com/jaimemartz/playerbalancer/utils/GuestPaste.java +++ b/src/main/java/com/jaimemartz/playerbalancer/utils/GuestPaste.java @@ -15,7 +15,7 @@ import java.util.LinkedList; import java.util.List; @Data -public class GuestPaste { +public final class GuestPaste { private final String key; private final String code; diff --git a/src/main/java/com/jaimemartz/playerbalancer/utils/LevenshteinDistance.java b/src/main/java/com/jaimemartz/playerbalancer/utils/LevenshteinDistance.java index 90e383d..7f9c70e 100644 --- a/src/main/java/com/jaimemartz/playerbalancer/utils/LevenshteinDistance.java +++ b/src/main/java/com/jaimemartz/playerbalancer/utils/LevenshteinDistance.java @@ -1,6 +1,6 @@ package com.jaimemartz.playerbalancer.utils; -public class LevenshteinDistance { +public final class LevenshteinDistance { public static T closest(Iterable collection, T target) { int distance = Integer.MAX_VALUE; T closest = null; diff --git a/src/main/java/com/jaimemartz/playerbalancer/utils/MessageUtils.java b/src/main/java/com/jaimemartz/playerbalancer/utils/MessageUtils.java index 4424a81..7afce35 100644 --- a/src/main/java/com/jaimemartz/playerbalancer/utils/MessageUtils.java +++ b/src/main/java/com/jaimemartz/playerbalancer/utils/MessageUtils.java @@ -7,7 +7,7 @@ import net.md_5.bungee.api.chat.TextComponent; import java.util.function.Function; -public class MessageUtils { +public final class MessageUtils { public static void send(CommandSender sender, String text) { if (text != null) { text = ChatColor.translateAlternateColorCodes('&', text); diff --git a/src/main/java/com/jaimemartz/playerbalancer/utils/ServerListPing.java b/src/main/java/com/jaimemartz/playerbalancer/utils/ServerListPing.java index 74b9686..6f9ea34 100644 --- a/src/main/java/com/jaimemartz/playerbalancer/utils/ServerListPing.java +++ b/src/main/java/com/jaimemartz/playerbalancer/utils/ServerListPing.java @@ -16,7 +16,7 @@ import java.net.InetSocketAddress; import java.net.Socket; import java.util.List; -public class ServerListPing { +public final class ServerListPing { private int timeout = 7000; private static Gson gson = new GsonBuilder() .registerTypeAdapter(BaseComponent.class, new ComponentSerializer())