diff --git a/README.md b/README.md index 36bc1b8..4df9dea 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ - [x] Get dummy sections able to have already registered servers on other sections - [x] Add a new message for when a player gets connected to a server and repurpose the connecting one - [ ] Add support for wildcards, contains, equalsIgnoreCase and regex at the same time +- [ ] Add option to force joining a specific section - [x] Add tooltip when you hover over a server in /section info - [ ] Stop using inventivetalent's deprecated bungee-update - [ ] Create a spigot addon that adds connector signs and placeholders diff --git a/src/main/java/com/jaimemartz/playerbalancer/commands/FallbackCommand.java b/src/main/java/com/jaimemartz/playerbalancer/commands/FallbackCommand.java index f80cb6d..95747b7 100644 --- a/src/main/java/com/jaimemartz/playerbalancer/commands/FallbackCommand.java +++ b/src/main/java/com/jaimemartz/playerbalancer/commands/FallbackCommand.java @@ -79,7 +79,7 @@ public class FallbackCommand extends Command { MessageUtils.send(player, ConfigEntries.FAILURE_MESSAGE.get()); } else { ServerInfo server = target.getSortedServers().get(number - 1); - ConnectionIntent.direct(plugin, player, server); + ConnectionIntent.direct(plugin, player, server, (response, throwable) -> {}); } } catch (NumberFormatException e) { MessageUtils.send(player, ConfigEntries.INVALID_INPUT_MESSAGE.get()); diff --git a/src/main/java/com/jaimemartz/playerbalancer/commands/ManageCommand.java b/src/main/java/com/jaimemartz/playerbalancer/commands/ManageCommand.java index c59a550..06a4c0b 100644 --- a/src/main/java/com/jaimemartz/playerbalancer/commands/ManageCommand.java +++ b/src/main/java/com/jaimemartz/playerbalancer/commands/ManageCommand.java @@ -167,7 +167,7 @@ public class ManageCommand extends Command { .append(server.getName()) .color(ChatColor.AQUA) .event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, - new ComponentBuilder("This is a test\nThis is a test").create())) + new ComponentBuilder("This is a test\nThis is a test").create())) //todo implement this .append(String.format(" (%d/%d) ", status.getOnline(), status.getMaximum())) diff --git a/src/main/java/com/jaimemartz/playerbalancer/connection/ConnectionIntent.java b/src/main/java/com/jaimemartz/playerbalancer/connection/ConnectionIntent.java index 8e7fd4e..adc234e 100644 --- a/src/main/java/com/jaimemartz/playerbalancer/connection/ConnectionIntent.java +++ b/src/main/java/com/jaimemartz/playerbalancer/connection/ConnectionIntent.java @@ -6,12 +6,14 @@ import com.jaimemartz.playerbalancer.manager.PlayerLocker; import com.jaimemartz.playerbalancer.ping.ServerStatus; 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 java.util.ArrayList; import java.util.List; import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; public abstract class ConnectionIntent { protected final PlayerBalancer plugin; @@ -34,12 +36,13 @@ public abstract class ConnectionIntent { if (section.getProvider() != ProviderType.NONE) { ServerInfo target = this.fetchServer(plugin, player, section, provider, servers); if (target != null) { - this.connect(target); - - //todo only send this if the above method returns true - MessageUtils.send(player, ConfigEntries.CONNECTED_MESSAGE.get(), - (str) -> str.replace("{server}", target.getName()) - ); + this.connect(target, (response, throwable) -> { + if (response) { //only if the connect has been executed correctly + MessageUtils.send(player, ConfigEntries.CONNECTED_MESSAGE.get(), + (str) -> str.replace("{server}", target.getName()) + ); + } + }); } else { MessageUtils.send(player, ConfigEntries.FAILURE_MESSAGE.get()); } @@ -74,7 +77,6 @@ public abstract class ConnectionIntent { int intents = ConfigEntries.SERVER_CHECK_ATTEMPTS.get(); for (int intent = 1; intent <= intents; intent++) { if (servers.size() == 0) return null; - if (servers.size() == 1) return servers.get(0); ServerInfo target = provider.requestTarget(plugin, section, servers, player); if (target == null) continue; @@ -90,23 +92,26 @@ public abstract class ConnectionIntent { return null; } - public abstract void connect(ServerInfo server); + 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 - public void connect(ServerInfo server) { - direct(plugin, player, server); + public void connect(ServerInfo server, Callback callback) { + ConnectionIntent.direct(plugin, player, server, callback); } }; } - //todo make this return true or false depending if the player really got moved or not - public static void direct(PlayerBalancer plugin, ProxiedPlayer player, ServerInfo server) { + //todo create this as a type + public static void direct(PlayerBalancer plugin, ProxiedPlayer player, ServerInfo server, Callback callback) { PlayerLocker.lock(player); - player.connect(server); - plugin.getProxy().getScheduler().schedule(plugin, () -> { - PlayerLocker.unlock(player); - }, 5, TimeUnit.SECONDS); + player.connect(server, (result, throwable) -> { + plugin.getProxy().getScheduler().schedule(plugin, () -> { + PlayerLocker.unlock(player); + }, 5, TimeUnit.SECONDS); + callback.done(result, throwable); + }); } } \ No newline at end of file diff --git a/src/main/java/com/jaimemartz/playerbalancer/connection/types/DirectionConnection.java b/src/main/java/com/jaimemartz/playerbalancer/connection/types/DirectionConnection.java new file mode 100644 index 0000000..35f83f2 --- /dev/null +++ b/src/main/java/com/jaimemartz/playerbalancer/connection/types/DirectionConnection.java @@ -0,0 +1,5 @@ +package com.jaimemartz.playerbalancer.connection.types; + +public class DirectionConnection { + // TODO: 09/08/2017 +} diff --git a/src/main/java/com/jaimemartz/playerbalancer/section/SectionCommand.java b/src/main/java/com/jaimemartz/playerbalancer/section/SectionCommand.java index 5cd337b..1ff324c 100644 --- a/src/main/java/com/jaimemartz/playerbalancer/section/SectionCommand.java +++ b/src/main/java/com/jaimemartz/playerbalancer/section/SectionCommand.java @@ -38,7 +38,7 @@ public class SectionCommand extends Command { MessageUtils.send(sender, ConfigEntries.FAILURE_MESSAGE.get()); } else { ServerInfo server = section.getSortedServers().get(number - 1); - ConnectionIntent.direct(plugin, player, server); + ConnectionIntent.direct(plugin, player, server, (response, throwable) -> {}); } } catch (NumberFormatException e) { MessageUtils.send(sender, ConfigEntries.INVALID_INPUT_MESSAGE.get());