From ab5e84baab40f01c225372f8fc4224200acad46b Mon Sep 17 00:00:00 2001 From: BGHDDevelopment Date: Fri, 27 Aug 2021 19:33:05 -0700 Subject: [PATCH] Added back support for the new version of RedisBungee; https://www.spigotmc.org/resources/87700/ --- balancer/pom.xml | 6 +++++ .../playerbalancer/PlayerBalancer.java | 8 ++++++ .../ProgressiveFillerProvider.java | 2 +- .../ProgressiveLowestProvider.java | 2 +- .../progressive/ProgressiveProvider.java | 2 +- .../types/random/RandomFillerProvider.java | 2 +- .../types/random/RandomLowestProvider.java | 2 +- .../playerbalancer/helper/NetworkManager.java | 26 +++++++++++++++++++ .../settings/props/GeneralProps.java | 3 +++ balancer/src/main/resources/default.conf | 3 +++ 10 files changed, 51 insertions(+), 5 deletions(-) create mode 100644 balancer/src/main/java/com/jaimemartz/playerbalancer/helper/NetworkManager.java diff --git a/balancer/pom.xml b/balancer/pom.xml index 4f08b1d..4e63b81 100644 --- a/balancer/pom.xml +++ b/balancer/pom.xml @@ -66,6 +66,12 @@ jar provided + + com.imaginarycode.minecraft + RedisBungee + 0.6.5-SNAPSHOT + provided + ninja.leaping.configurate configurate-hocon diff --git a/balancer/src/main/java/com/jaimemartz/playerbalancer/PlayerBalancer.java b/balancer/src/main/java/com/jaimemartz/playerbalancer/PlayerBalancer.java index 43657db..d792c13 100644 --- a/balancer/src/main/java/com/jaimemartz/playerbalancer/PlayerBalancer.java +++ b/balancer/src/main/java/com/jaimemartz/playerbalancer/PlayerBalancer.java @@ -5,6 +5,7 @@ import com.jaimemartz.playerbalancer.commands.FallbackCommand; import com.jaimemartz.playerbalancer.commands.MainCommand; import com.jaimemartz.playerbalancer.commands.ManageCommand; import com.jaimemartz.playerbalancer.connection.ServerAssignRegistry; +import com.jaimemartz.playerbalancer.helper.NetworkManager; import com.jaimemartz.playerbalancer.helper.PasteHelper; import com.jaimemartz.playerbalancer.helper.PlayerLocker; import com.jaimemartz.playerbalancer.listeners.*; @@ -33,6 +34,7 @@ public class PlayerBalancer extends Plugin { private StatusManager statusManager; private SettingsHolder settings; private SectionManager sectionManager; + private NetworkManager networkManager; private ConfigurationLoader loader; private FallbackCommand fallbackCommand; @@ -126,6 +128,8 @@ public class PlayerBalancer extends Plugin { getProxy().getPluginManager().registerListener(this, reloadListener); } + networkManager = new NetworkManager(this); + sectionManager = new SectionManager(this); sectionManager.load(); @@ -283,4 +287,8 @@ public class PlayerBalancer extends Plugin { public FallbackCommand getFallbackCommand() { return fallbackCommand; } + + public NetworkManager getNetworkManager() { + return networkManager; + } } diff --git a/balancer/src/main/java/com/jaimemartz/playerbalancer/connection/provider/types/progressive/ProgressiveFillerProvider.java b/balancer/src/main/java/com/jaimemartz/playerbalancer/connection/provider/types/progressive/ProgressiveFillerProvider.java index 057452f..ca06e93 100644 --- a/balancer/src/main/java/com/jaimemartz/playerbalancer/connection/provider/types/progressive/ProgressiveFillerProvider.java +++ b/balancer/src/main/java/com/jaimemartz/playerbalancer/connection/provider/types/progressive/ProgressiveFillerProvider.java @@ -17,7 +17,7 @@ public class ProgressiveFillerProvider extends AbstractProvider { for (ServerInfo server : servers) { ServerStatus status = plugin.getStatusManager().getStatus(server); - int count = server.getPlayers().size(); + int count = plugin.getNetworkManager().getPlayers(server); if (count > max && count <= status.getMaximum()) { max = count; diff --git a/balancer/src/main/java/com/jaimemartz/playerbalancer/connection/provider/types/progressive/ProgressiveLowestProvider.java b/balancer/src/main/java/com/jaimemartz/playerbalancer/connection/provider/types/progressive/ProgressiveLowestProvider.java index 0e7f29f..30fc042 100644 --- a/balancer/src/main/java/com/jaimemartz/playerbalancer/connection/provider/types/progressive/ProgressiveLowestProvider.java +++ b/balancer/src/main/java/com/jaimemartz/playerbalancer/connection/provider/types/progressive/ProgressiveLowestProvider.java @@ -15,7 +15,7 @@ public class ProgressiveLowestProvider extends AbstractProvider { ServerInfo target = null; for (ServerInfo server : servers) { - int count = server.getPlayers().size(); + int count = plugin.getNetworkManager().getPlayers(server); if (count < min) { min = count; diff --git a/balancer/src/main/java/com/jaimemartz/playerbalancer/connection/provider/types/progressive/ProgressiveProvider.java b/balancer/src/main/java/com/jaimemartz/playerbalancer/connection/provider/types/progressive/ProgressiveProvider.java index 6dc99c4..5329989 100644 --- a/balancer/src/main/java/com/jaimemartz/playerbalancer/connection/provider/types/progressive/ProgressiveProvider.java +++ b/balancer/src/main/java/com/jaimemartz/playerbalancer/connection/provider/types/progressive/ProgressiveProvider.java @@ -14,7 +14,7 @@ public class ProgressiveProvider extends AbstractProvider { public ServerInfo requestTarget(PlayerBalancer plugin, ServerSection section, List servers, ProxiedPlayer player) { for (ServerInfo server : servers) { ServerStatus status = plugin.getStatusManager().getStatus(server); - if (server.getPlayers().size() < status.getMaximum()) { + if (plugin.getNetworkManager().getPlayers(server) < status.getMaximum()) { return server; } } diff --git a/balancer/src/main/java/com/jaimemartz/playerbalancer/connection/provider/types/random/RandomFillerProvider.java b/balancer/src/main/java/com/jaimemartz/playerbalancer/connection/provider/types/random/RandomFillerProvider.java index 53374be..d68178e 100644 --- a/balancer/src/main/java/com/jaimemartz/playerbalancer/connection/provider/types/random/RandomFillerProvider.java +++ b/balancer/src/main/java/com/jaimemartz/playerbalancer/connection/provider/types/random/RandomFillerProvider.java @@ -18,7 +18,7 @@ public class RandomFillerProvider extends AbstractProvider { int max = Integer.MIN_VALUE; for (ServerInfo server : servers) { - int count = server.getPlayers().size(); + int count = plugin.getNetworkManager().getPlayers(server); if (count >= max) { if (count > max) { diff --git a/balancer/src/main/java/com/jaimemartz/playerbalancer/connection/provider/types/random/RandomLowestProvider.java b/balancer/src/main/java/com/jaimemartz/playerbalancer/connection/provider/types/random/RandomLowestProvider.java index 2ec8ed4..cd9f593 100644 --- a/balancer/src/main/java/com/jaimemartz/playerbalancer/connection/provider/types/random/RandomLowestProvider.java +++ b/balancer/src/main/java/com/jaimemartz/playerbalancer/connection/provider/types/random/RandomLowestProvider.java @@ -18,7 +18,7 @@ public class RandomLowestProvider extends AbstractProvider { int min = Integer.MAX_VALUE; for (ServerInfo server : servers) { - int count = server.getPlayers().size(); + int count = plugin.getNetworkManager().getPlayers(server); if (count <= min) { if (count < min) { diff --git a/balancer/src/main/java/com/jaimemartz/playerbalancer/helper/NetworkManager.java b/balancer/src/main/java/com/jaimemartz/playerbalancer/helper/NetworkManager.java new file mode 100644 index 0000000..59334a7 --- /dev/null +++ b/balancer/src/main/java/com/jaimemartz/playerbalancer/helper/NetworkManager.java @@ -0,0 +1,26 @@ +package com.jaimemartz.playerbalancer.helper; + +import com.imaginarycode.minecraft.redisbungee.RedisBungeeAPI; +import com.jaimemartz.playerbalancer.PlayerBalancer; +import net.md_5.bungee.api.config.ServerInfo; + +public class NetworkManager { + + private final PlayerBalancer plugin; + + public NetworkManager(PlayerBalancer plugin) { + this.plugin = plugin; + } + + public int getPlayers(ServerInfo server) { + if (plugin.getSettings().getGeneralProps().isRedisBungee()) { + try { + return RedisBungeeAPI.getRedisBungeeApi().getPlayersOnServer(server.getName()).size(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + return server.getPlayers().size(); + } +} diff --git a/balancer/src/main/java/com/jaimemartz/playerbalancer/settings/props/GeneralProps.java b/balancer/src/main/java/com/jaimemartz/playerbalancer/settings/props/GeneralProps.java index af10050..669ab83 100644 --- a/balancer/src/main/java/com/jaimemartz/playerbalancer/settings/props/GeneralProps.java +++ b/balancer/src/main/java/com/jaimemartz/playerbalancer/settings/props/GeneralProps.java @@ -19,6 +19,9 @@ public class GeneralProps { @Setting(value = "plugin-messaging") private boolean pluginMessaging; + @Setting(value = "redis-bungee") + private boolean redisBungee; + @Setting private String version; } diff --git a/balancer/src/main/resources/default.conf b/balancer/src/main/resources/default.conf index 81c0e9d..939a295 100644 --- a/balancer/src/main/resources/default.conf +++ b/balancer/src/main/resources/default.conf @@ -11,6 +11,9 @@ general { # When true, the plugin will reload when you execute /greload auto-reload=true + # When true, the plugin will get player counts from RedisBungee (Limework Fork: https://www.spigotmc.org/resources/87700/) + redis-bungee=false + # When true, this plugin will print less messages when loading silent=false