From a71e2ae84219fe497fd450752d16a3ac9da8199d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Mart=C3=ADnez=20Rinc=C3=B3n?= Date: Fri, 1 Dec 2017 23:46:23 +0100 Subject: [PATCH] Implemented more subchannels --- Main Plugin/pom.xml | 2 +- .../playerbalancer/ping/StatusManager.java | 8 +- .../services/MessagingService.java | 34 ++++++++ Spigot Addon/pom.xml | 2 +- .../playerbalanceraddon/MainCommand.java | 84 ++++++++++++++++--- .../PluginMessageManager.java | 36 ++++---- 6 files changed, 134 insertions(+), 32 deletions(-) diff --git a/Main Plugin/pom.xml b/Main Plugin/pom.xml index bb7148c..f6de4e2 100644 --- a/Main Plugin/pom.xml +++ b/Main Plugin/pom.xml @@ -11,7 +11,7 @@ PlayerBalancer Plugin playerbalancer-plugin - 2.1.2.2 + 2.1.3 PlayerBalancer diff --git a/Main Plugin/src/main/java/com/jaimemartz/playerbalancer/ping/StatusManager.java b/Main Plugin/src/main/java/com/jaimemartz/playerbalancer/ping/StatusManager.java index 0c426d9..c2da8f2 100644 --- a/Main Plugin/src/main/java/com/jaimemartz/playerbalancer/ping/StatusManager.java +++ b/Main Plugin/src/main/java/com/jaimemartz/playerbalancer/ping/StatusManager.java @@ -25,6 +25,7 @@ public class StatusManager implements Listener { private ScheduledTask task; private final Map storage = new HashMap<>(); + private final Map overriders = new HashMap<>(); public StatusManager(PlayerBalancer plugin) { this.props = plugin.getSettings().getServerCheckerProps(); @@ -96,6 +97,9 @@ public class StatusManager implements Listener { } public boolean isAccessible(ServerInfo server) { + if (overriders.containsKey(server)) + return overriders.get(server); + ServerStatus status = getStatus(server); for (String pattern : props.getMarkerDescs()) { @@ -121,7 +125,7 @@ public class StatusManager implements Listener { if (server == null) break; - //REMOVE OVERRIDE + overriders.remove(server); break; } @@ -131,7 +135,7 @@ public class StatusManager implements Listener { if (server == null) break; - //ADD OVERRIDE + overriders.put(server, in.readBoolean()); break; } } diff --git a/Main Plugin/src/main/java/com/jaimemartz/playerbalancer/services/MessagingService.java b/Main Plugin/src/main/java/com/jaimemartz/playerbalancer/services/MessagingService.java index 02e756e..cbfb98d 100644 --- a/Main Plugin/src/main/java/com/jaimemartz/playerbalancer/services/MessagingService.java +++ b/Main Plugin/src/main/java/com/jaimemartz/playerbalancer/services/MessagingService.java @@ -7,6 +7,7 @@ import com.google.gson.GsonBuilder; import com.google.gson.JsonSerializer; import com.jaimemartz.playerbalancer.PlayerBalancer; import com.jaimemartz.playerbalancer.connection.ConnectionIntent; +import com.jaimemartz.playerbalancer.manager.PlayerLocker; import com.jaimemartz.playerbalancer.ping.ServerStatus; import com.jaimemartz.playerbalancer.section.ServerSection; import net.md_5.bungee.api.config.ServerInfo; @@ -19,6 +20,7 @@ import net.md_5.bungee.event.EventHandler; import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; import java.io.IOException; +import java.util.concurrent.TimeUnit; public class MessagingService implements Listener { private final PlayerBalancer plugin; @@ -185,6 +187,38 @@ public class MessagingService implements Listener { sender.sendData("PlayerBalancer", stream.toByteArray()); } + + case "ClearPlayerBypass": { + if (event.getReceiver() instanceof ProxiedPlayer) { + ProxiedPlayer player = (ProxiedPlayer) event.getReceiver(); + PlayerLocker.unlock(player); + } + break; + } + + case "SetPlayerBypass": { + if (event.getReceiver() instanceof ProxiedPlayer) { + ProxiedPlayer player = (ProxiedPlayer) event.getReceiver(); + PlayerLocker.lock(player); + } + break; + } + + case "BypassConnect": { + if (event.getReceiver() instanceof ProxiedPlayer) { + ProxiedPlayer player = (ProxiedPlayer) event.getReceiver(); + + ServerInfo server = plugin.getProxy().getServerInfo(in.readUTF()); + if (server == null) + break; + + PlayerLocker.lock(player); + plugin.getProxy().getScheduler().schedule(plugin, () -> { + PlayerLocker.unlock(player); + }, 5, TimeUnit.SECONDS); + } + break; + } } } } diff --git a/Spigot Addon/pom.xml b/Spigot Addon/pom.xml index 465f553..9401be5 100644 --- a/Spigot Addon/pom.xml +++ b/Spigot Addon/pom.xml @@ -11,7 +11,7 @@ PlayerBalancer Addon playerbalancer-addon - 1.1 for 2.1.2.0+ + 1.2 for 2.1.2.0+ PlayerBalancerAddon 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 6deb15d..9b54e51 100644 --- a/Spigot Addon/src/main/java/com/jaimemartz/playerbalanceraddon/MainCommand.java +++ b/Spigot Addon/src/main/java/com/jaimemartz/playerbalanceraddon/MainCommand.java @@ -26,12 +26,14 @@ public class MainCommand implements CommandExecutor { Player player = plugin.getServer().getPlayer(args[2]); if (player != null) { plugin.getManager().connectPlayer(player, input); + sender.sendMessage(ChatColor.GREEN + "Successfully sent request to the plugin"); } else { sender.sendMessage(ChatColor.RED + "There is no player with that name connected to this server"); } } else { if (sender instanceof Player) { plugin.getManager().connectPlayer((Player) sender, input); + sender.sendMessage(ChatColor.GREEN + "Successfully sent request to the plugin"); } else { sender.sendMessage(ChatColor.RED + "This command variant can only be executed by a player"); } @@ -47,12 +49,14 @@ public class MainCommand implements CommandExecutor { Player player = plugin.getServer().getPlayer(args[1]); if (player != null) { plugin.getManager().fallbackPlayer((Player) sender); + sender.sendMessage(ChatColor.GREEN + "Successfully sent request to the plugin"); } else { sender.sendMessage(ChatColor.RED + "There is no player with that name connected to this server"); } } else { if (sender instanceof Player) { plugin.getManager().fallbackPlayer((Player) sender); + sender.sendMessage(ChatColor.GREEN + "Successfully sent request to the plugin"); } else { sender.sendMessage(ChatColor.RED + "This command variant can only be executed by a player"); } @@ -61,27 +65,91 @@ public class MainCommand implements CommandExecutor { } case "bypassconnect": { - sender.sendMessage(ChatColor.RED + "This command variant is not implemented yet"); + if (args.length >= 2) { + String input = args[1]; + if (args.length >= 3) { + Player player = plugin.getServer().getPlayer(args[2]); + if (player != null) { + plugin.getManager().bypassConnect(player, input); + sender.sendMessage(ChatColor.GREEN + "Successfully sent request to the plugin"); + } else { + sender.sendMessage(ChatColor.RED + "There is no player with that name connected to this server"); + } + } else { + if (sender instanceof Player) { + plugin.getManager().bypassConnect((Player) sender, input); + sender.sendMessage(ChatColor.GREEN + "Successfully sent request to the plugin"); + } else { + sender.sendMessage(ChatColor.RED + "This command variant can only be executed by a player"); + } + } + } else { + sender.sendMessage(ChatColor.RED + "Usage: /section bypassconnect [player]"); + } break; } case "setbypass": { - sender.sendMessage(ChatColor.RED + "This command variant is not implemented yet"); + if (args.length >= 2) { + Player player = plugin.getServer().getPlayer(args[1]); + if (player != null) { + plugin.getManager().setPlayerBypass(player); + sender.sendMessage(ChatColor.GREEN + "Successfully sent request to the plugin"); + } else { + sender.sendMessage(ChatColor.RED + "There is no player with that name connected to this server"); + } + } else { + if (sender instanceof Player) { + plugin.getManager().setPlayerBypass((Player) sender); + sender.sendMessage(ChatColor.GREEN + "Successfully sent request to the plugin"); + } else { + sender.sendMessage(ChatColor.RED + "This command variant can only be executed by a player"); + } + } break; } case "clearbypass": { - sender.sendMessage(ChatColor.RED + "This command variant is not implemented yet"); + if (args.length >= 2) { + Player player = plugin.getServer().getPlayer(args[1]); + if (player != null) { + plugin.getManager().clearPlayerBypass((Player) sender); + sender.sendMessage(ChatColor.GREEN + "Successfully sent request to the plugin"); + } else { + sender.sendMessage(ChatColor.RED + "There is no player with that name connected to this server"); + } + } else { + if (sender instanceof Player) { + plugin.getManager().clearPlayerBypass((Player) sender); + sender.sendMessage(ChatColor.GREEN + "Successfully sent request to the plugin"); + } else { + sender.sendMessage(ChatColor.RED + "This command variant can only be executed by a player"); + } + } break; } case "overridestatus": { - sender.sendMessage(ChatColor.RED + "This command variant is not implemented yet"); + if (args.length >= 3) { + if (args[2].equals("false") || args[2].equals("true")) { + plugin.getManager().setStatusOverride(args[1], Boolean.valueOf(args[2])); + sender.sendMessage(ChatColor.GREEN + "Successfully sent request to the plugin"); + } else { + sender.sendMessage(ChatColor.RED + "The status parameter of this command variant has to be a boolean type, either false or true"); + } + } else { + sender.sendMessage(ChatColor.RED + "Usage: /section overridestatus
"); + } break; } case "clearoverride": { - sender.sendMessage(ChatColor.RED + "This command variant is not implemented yet"); + if (args.length >= 2) { + plugin.getManager().clearStatusOverride(args[1]); + sender.sendMessage(ChatColor.GREEN + "Successfully sent request to the plugin"); + } else { + sender.sendMessage(ChatColor.RED + "Usage: /section clearoverride "); + } break; } } @@ -90,15 +158,11 @@ 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 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)); } } diff --git a/Spigot Addon/src/main/java/com/jaimemartz/playerbalanceraddon/PluginMessageManager.java b/Spigot Addon/src/main/java/com/jaimemartz/playerbalanceraddon/PluginMessageManager.java index df7afe5..b18b4e5 100644 --- a/Spigot Addon/src/main/java/com/jaimemartz/playerbalanceraddon/PluginMessageManager.java +++ b/Spigot Addon/src/main/java/com/jaimemartz/playerbalanceraddon/PluginMessageManager.java @@ -153,6 +153,24 @@ public class PluginMessageManager implements PluginMessageListener { return true; } + public void clearPlayerBypass(Player player) { + ByteArrayDataOutput out = ByteStreams.newDataOutput(); + out.writeUTF("ClearPlayerBypass"); + player.sendPluginMessage(plugin, "PlayerBalancer", out.toByteArray()); + } + + public void setPlayerBypass(Player player) { + ByteArrayDataOutput out = ByteStreams.newDataOutput(); + out.writeUTF("SetPlayerBypass"); + player.sendPluginMessage(plugin, "PlayerBalancer", out.toByteArray()); + } + + public void bypassConnect(Player player, String server) { + ByteArrayDataOutput out = ByteStreams.newDataOutput(); + out.writeUTF("BypassConnect"); + player.sendPluginMessage(plugin, "PlayerBalancer", out.toByteArray()); + } + public boolean clearStatusOverride(String server) { Player player = Iterables.getFirst(plugin.getServer().getOnlinePlayers(), null); if (player == null) { @@ -182,24 +200,6 @@ public class PluginMessageManager implements PluginMessageListener { return true; } - public void clearPlayerBypass(Player player) { - ByteArrayDataOutput out = ByteStreams.newDataOutput(); - out.writeUTF("ClearPlayerBypass"); - player.sendPluginMessage(plugin, "PlayerBalancer", out.toByteArray()); - } - - public void setPlayerBypass(Player player) { - ByteArrayDataOutput out = ByteStreams.newDataOutput(); - out.writeUTF("SetPlayerBypass"); - player.sendPluginMessage(plugin, "PlayerBalancer", out.toByteArray()); - } - - public void bypassConnect(Player player, String server) { - ByteArrayDataOutput out = ByteStreams.newDataOutput(); - out.writeUTF("BypassConnect"); - player.sendPluginMessage(plugin, "PlayerBalancer", out.toByteArray()); - } - private final class MessageContext { private final String channel; private final String subchannel;