mirror of
https://github.com/BGHDDevelopment/PlayerBalancer.git
synced 2024-11-27 05:05:19 +01:00
Implemented more subchannels
This commit is contained in:
parent
6cea42767b
commit
a71e2ae842
@ -11,7 +11,7 @@
|
||||
|
||||
<name>PlayerBalancer Plugin</name>
|
||||
<artifactId>playerbalancer-plugin</artifactId>
|
||||
<version>2.1.2.2</version>
|
||||
<version>2.1.3</version>
|
||||
|
||||
<build>
|
||||
<finalName>PlayerBalancer</finalName>
|
||||
|
@ -25,6 +25,7 @@ public class StatusManager implements Listener {
|
||||
private ScheduledTask task;
|
||||
|
||||
private final Map<ServerInfo, ServerStatus> storage = new HashMap<>();
|
||||
private final Map<ServerInfo, Boolean> 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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,7 @@
|
||||
|
||||
<name>PlayerBalancer Addon</name>
|
||||
<artifactId>playerbalancer-addon</artifactId>
|
||||
<version>1.1 for 2.1.2.0+</version>
|
||||
<version>1.2 for 2.1.2.0+</version>
|
||||
|
||||
<build>
|
||||
<finalName>PlayerBalancerAddon</finalName>
|
||||
|
@ -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 <server> [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 <section> <status: false|true>");
|
||||
}
|
||||
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 <server>");
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -90,15 +158,11 @@ public class MainCommand implements CommandExecutor {
|
||||
sender.sendMessage(ChatColor.GRAY + "Available commands:");
|
||||
sender.sendMessage(ChatColor.AQUA + "/spb connect <section> [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 <server> [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 <server> <status>" + ChatColor.GRAY + " - " + ChatColor.RED + "Overrides the accessible status of a specific server, over anything else");
|
||||
sender.sendMessage(ChatColor.AQUA + "/spb overridestatus <server> <status: false|true>" + ChatColor.GRAY + " - " + ChatColor.RED + "Overrides the accessible status of a specific server, over anything else");
|
||||
sender.sendMessage(ChatColor.AQUA + "/spb clearoverride <server>" + ChatColor.GRAY + " - " + ChatColor.RED + "Clears the overridden status of a specific server");
|
||||
*/
|
||||
|
||||
sender.sendMessage(ChatColor.STRIKETHROUGH + ChatColor.GRAY.toString() + Strings.repeat("-", 53));
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user