From 29099a493f65cd00d3abd4900fea1638034c5b39 Mon Sep 17 00:00:00 2001 From: Jaime Martinez Rincon Date: Sat, 20 Jun 2020 22:23:54 +0200 Subject: [PATCH 1/5] Fix error when using regular and non dummy sections --- .../section/SectionManager.java | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/balancer/src/main/java/com/jaimemartz/playerbalancer/section/SectionManager.java b/balancer/src/main/java/com/jaimemartz/playerbalancer/section/SectionManager.java index 70c1c7b..30c5f39 100644 --- a/balancer/src/main/java/com/jaimemartz/playerbalancer/section/SectionManager.java +++ b/balancer/src/main/java/com/jaimemartz/playerbalancer/section/SectionManager.java @@ -235,22 +235,25 @@ public class SectionManager { } public void registerServer(ServerInfo server, ServerSection section) { - //Checking for duplicated server on non dummy sections - if (servers.containsKey(server) && !isDummy(section)) { - ServerSection other = servers.get(server); - throw new IllegalArgumentException(String.format( - "The server \"%s\" is already in the section \"%s\"", + if (!isDummy(section)) { + // Checking for already we already added this server to other section + // This can only happen if another non dummy section registers this server + if (servers.containsKey(server)) { + ServerSection other = servers.get(server); + throw new IllegalArgumentException(String.format( + "The server \"%s\" is already in the section \"%s\"", + server.getName(), + other.getName() + )); + } + + plugin.getLogger().info(String.format("Registering server \"%s\" to section \"%s\"", server.getName(), - other.getName() + section.getName() )); + + servers.put(server, section); } - - plugin.getLogger().info(String.format("Registering server \"%s\" to section \"%s\"", - server.getName(), - section.getName() - )); - - servers.put(server, section); } public void calculateServers(ServerSection section) { From 2d2a7d8f9eda660caf93426fe0e447d06c54a63b Mon Sep 17 00:00:00 2001 From: Jaime Martinez Rincon Date: Sat, 20 Jun 2020 22:28:24 +0200 Subject: [PATCH 2/5] Spaces at the start of line comments --- .../PlayerBalancerAddon.java | 2 +- .../PlayerBalancerPlaceholderExpansion.java | 4 +- .../PluginMessageManager.java | 2 +- .../playerbalancer/PlayerBalancer.java | 6 +-- .../connection/ConnectionIntent.java | 10 ++--- .../playerbalancer/helper/PasteHelper.java | 6 +-- .../listeners/PluginMessageListener.java | 2 +- .../listeners/ServerConnectListener.java | 2 +- .../playerbalancer/ping/PingTactic.java | 2 +- .../section/SectionManager.java | 14 +++---- .../playerbalancer/section/SectionServer.java | 2 +- .../playerbalancer/utils/AdapterWrapper.java | 2 +- .../utils/AlphanumComparator.java | 6 +-- .../utils/LevenshteinDistance.java | 20 +++++----- .../playerbalancer/utils/ServerListPing.java | 38 +++++++++---------- 15 files changed, 57 insertions(+), 61 deletions(-) diff --git a/addon/src/main/java/com/jaimemartz/playerbalanceraddon/PlayerBalancerAddon.java b/addon/src/main/java/com/jaimemartz/playerbalanceraddon/PlayerBalancerAddon.java index b81c819..c211d88 100644 --- a/addon/src/main/java/com/jaimemartz/playerbalanceraddon/PlayerBalancerAddon.java +++ b/addon/src/main/java/com/jaimemartz/playerbalanceraddon/PlayerBalancerAddon.java @@ -19,7 +19,7 @@ public class PlayerBalancerAddon extends JavaPlugin { @Override public void onDisable() { - //Nothing to do... + // Nothing to do... } public PluginMessageManager getManager() { diff --git a/addon/src/main/java/com/jaimemartz/playerbalanceraddon/PlayerBalancerPlaceholderExpansion.java b/addon/src/main/java/com/jaimemartz/playerbalanceraddon/PlayerBalancerPlaceholderExpansion.java index 96efc95..8a332a6 100644 --- a/addon/src/main/java/com/jaimemartz/playerbalanceraddon/PlayerBalancerPlaceholderExpansion.java +++ b/addon/src/main/java/com/jaimemartz/playerbalanceraddon/PlayerBalancerPlaceholderExpansion.java @@ -22,8 +22,8 @@ public class PlayerBalancerPlaceholderExpansion extends PlaceholderExpansion { if (section == null) return null; - //For the first call this placeholder will return 0 - //For the next one, the result of the previous one + // For the first call this placeholder will return 0 + // For the next one, the result of the previous one plugin.getManager().getSectionPlayerCount(section, (count) -> { sectionPlayerCounts.put(section, count); }); diff --git a/addon/src/main/java/com/jaimemartz/playerbalanceraddon/PluginMessageManager.java b/addon/src/main/java/com/jaimemartz/playerbalanceraddon/PluginMessageManager.java index 04476fb..865953d 100644 --- a/addon/src/main/java/com/jaimemartz/playerbalanceraddon/PluginMessageManager.java +++ b/addon/src/main/java/com/jaimemartz/playerbalanceraddon/PluginMessageManager.java @@ -27,7 +27,7 @@ public class PluginMessageManager implements PluginMessageListener { plugin.getServer().getMessenger().registerIncomingPluginChannel(plugin, PB_CHANNEL, this); plugin.getServer().getMessenger().registerOutgoingPluginChannel(plugin, PB_CHANNEL); - //In case we need to use BungeeCord channels + // In case we need to use BungeeCord channels plugin.getServer().getMessenger().registerIncomingPluginChannel(plugin, BC_CHANNEL, this); plugin.getServer().getMessenger().registerOutgoingPluginChannel(plugin, BC_CHANNEL); } diff --git a/balancer/src/main/java/com/jaimemartz/playerbalancer/PlayerBalancer.java b/balancer/src/main/java/com/jaimemartz/playerbalancer/PlayerBalancer.java index 4ed32e3..518bbaa 100644 --- a/balancer/src/main/java/com/jaimemartz/playerbalancer/PlayerBalancer.java +++ b/balancer/src/main/java/com/jaimemartz/playerbalancer/PlayerBalancer.java @@ -78,7 +78,7 @@ public class PlayerBalancer extends Plugin { public boolean checkUpToDate() { try { - URLConnection con = new URL("https://api.spigotmc.org/legacy/update.php?resource=10788").openConnection(); + URLConnection con = new URL("https:// api.spigotmc.org/legacy/update.php?resource=10788").openConnection(); String reply = new BufferedReader(new InputStreamReader(con.getInputStream())).readLine(); return getDescription().getVersion().equals(reply); } catch (IOException e) { @@ -89,7 +89,7 @@ public class PlayerBalancer extends Plugin { @Override public void onDisable() { - //Nothing else to do than normal stop + // Nothing else to do than normal stop this.execStop(); } @@ -198,7 +198,7 @@ public class PlayerBalancer extends Plugin { } if (settings.getGeneralProps().isEnabled()) { - //Do not try to do anything if the plugin has not loaded correctly + // Do not try to do anything if the plugin has not loaded correctly if (failed) return; if (settings.getGeneralProps().isAutoReload()) { diff --git a/balancer/src/main/java/com/jaimemartz/playerbalancer/connection/ConnectionIntent.java b/balancer/src/main/java/com/jaimemartz/playerbalancer/connection/ConnectionIntent.java index f98ee88..74390f0 100644 --- a/balancer/src/main/java/com/jaimemartz/playerbalancer/connection/ConnectionIntent.java +++ b/balancer/src/main/java/com/jaimemartz/playerbalancer/connection/ConnectionIntent.java @@ -39,14 +39,10 @@ public abstract class ConnectionIntent { .replace("{alias}", safeNull(section.getProps().getAlias())) ); + // Ensure a new copy of the section servers List servers = new ArrayList<>(section.getServers()); - //Prevents removing servers from the section - if (servers == section.getServers()) { - throw new IllegalStateException("The servers list parameter is the same reference, this cannot happen"); - } - - //Prevents connections to the same server + // Prevents connections to the same server Server current = player.getServer(); if (current != null) { servers.remove(current.getInfo()); @@ -56,7 +52,7 @@ public abstract class ConnectionIntent { ServerInfo target = this.fetchServer(player, section, section.getImplicitProvider(), servers); if (target != null) { this.connect(target, (response, throwable) -> { - if (response) { //only if the connect has been executed correctly + if (response) { // only if the connect has been executed correctly MessageUtils.send(player, plugin.getSettings().getMessagesProps().getConnectedMessage(), (str) -> str.replace("{server}", target.getName()) .replace("{section}", section.getName()) diff --git a/balancer/src/main/java/com/jaimemartz/playerbalancer/helper/PasteHelper.java b/balancer/src/main/java/com/jaimemartz/playerbalancer/helper/PasteHelper.java index b15301f..210eda1 100644 --- a/balancer/src/main/java/com/jaimemartz/playerbalancer/helper/PasteHelper.java +++ b/balancer/src/main/java/com/jaimemartz/playerbalancer/helper/PasteHelper.java @@ -37,7 +37,7 @@ public enum PasteHelper { try (FileInputStream stream = new FileInputStream(file)) { try (InputStreamReader reader = new InputStreamReader(stream, "UTF-8")) { String content = CharStreams.toString(reader); - HastebinPaste paste = new HastebinPaste("https://file.properties/paste/", content); + HastebinPaste paste = new HastebinPaste("https:// file.properties/paste/", content); return paste.paste(); } } @@ -62,7 +62,7 @@ public enum PasteHelper { try (InputStreamReader reader = new InputStreamReader(stream, StandardCharsets.UTF_8)) { String content = CharStreams.toString(reader); content = content.replaceAll("[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}", "?.?.?.?"); - HastebinPaste paste = new HastebinPaste("https://file.properties/paste/", content); + HastebinPaste paste = new HastebinPaste("https:// file.properties/paste/", content); return paste.paste(); } } @@ -86,7 +86,7 @@ public enum PasteHelper { try (FileInputStream stream = new FileInputStream(file)) { try (InputStreamReader reader = new InputStreamReader(stream, StandardCharsets.UTF_8)) { String content = CharStreams.toString(reader); - HastebinPaste paste = new HastebinPaste("https://file.properties/paste/", content); + HastebinPaste paste = new HastebinPaste("https:// file.properties/paste/", content); return paste.paste(); } } diff --git a/balancer/src/main/java/com/jaimemartz/playerbalancer/listeners/PluginMessageListener.java b/balancer/src/main/java/com/jaimemartz/playerbalancer/listeners/PluginMessageListener.java index 39fbe2c..94cccd7 100644 --- a/balancer/src/main/java/com/jaimemartz/playerbalancer/listeners/PluginMessageListener.java +++ b/balancer/src/main/java/com/jaimemartz/playerbalancer/listeners/PluginMessageListener.java @@ -31,7 +31,7 @@ public class PluginMessageListener implements Listener { this.plugin = plugin; GsonBuilder builder = new GsonBuilder(); - //Only serialize the name of ServerInfo + // Only serialize the name of ServerInfo builder.registerTypeAdapter(ServerInfo.class, (JsonSerializer) (server, type, context) -> context.serialize(server.getName()) ); diff --git a/balancer/src/main/java/com/jaimemartz/playerbalancer/listeners/ServerConnectListener.java b/balancer/src/main/java/com/jaimemartz/playerbalancer/listeners/ServerConnectListener.java index f03fdd8..0519bcf 100644 --- a/balancer/src/main/java/com/jaimemartz/playerbalancer/listeners/ServerConnectListener.java +++ b/balancer/src/main/java/com/jaimemartz/playerbalancer/listeners/ServerConnectListener.java @@ -56,7 +56,7 @@ public class ServerConnectListener implements Listener { ServerSection section = plugin.getSectionManager().getByServer(target); if (section != null) { - //Checks only for servers (not the section server) + // Checks only for servers (not the section server) if (!target.equals(section.getServer())) { if (plugin.getSectionManager().isDummy(section)) { return null; diff --git a/balancer/src/main/java/com/jaimemartz/playerbalancer/ping/PingTactic.java b/balancer/src/main/java/com/jaimemartz/playerbalancer/ping/PingTactic.java index cfdebcb..8e6c21c 100644 --- a/balancer/src/main/java/com/jaimemartz/playerbalancer/ping/PingTactic.java +++ b/balancer/src/main/java/com/jaimemartz/playerbalancer/ping/PingTactic.java @@ -37,7 +37,7 @@ public enum PingTactic { try { server.ping((ping, throwable) -> { if (ping != null) { - //using deprecated method for bungee 1.8 compatibility + // Using deprecated method for bungee 1.8 compatibility callback.done(new ServerStatus( ping.getDescription(), ping.getPlayers().getOnline(), diff --git a/balancer/src/main/java/com/jaimemartz/playerbalancer/section/SectionManager.java b/balancer/src/main/java/com/jaimemartz/playerbalancer/section/SectionManager.java index 30c5f39..f228829 100644 --- a/balancer/src/main/java/com/jaimemartz/playerbalancer/section/SectionManager.java +++ b/balancer/src/main/java/com/jaimemartz/playerbalancer/section/SectionManager.java @@ -236,8 +236,8 @@ public class SectionManager { public void registerServer(ServerInfo server, ServerSection section) { if (!isDummy(section)) { - // Checking for already we already added this server to other section - // This can only happen if another non dummy section registers this server + // Checking for already we already added this server to other section + // This can only happen if another non dummy section registers this server if (servers.containsKey(server)) { ServerSection other = servers.get(server); throw new IllegalArgumentException(String.format( @@ -259,7 +259,7 @@ public class SectionManager { public void calculateServers(ServerSection section) { Set results = new HashSet<>(); - //Searches for matches + // Searches for matches section.getProps().getServerEntries().forEach(entry -> { Pattern pattern = Pattern.compile(entry); plugin.getProxy().getServers().forEach((name, server) -> { @@ -270,7 +270,7 @@ public class SectionManager { }); }); - //Checks if there are servers previously matched that are no longer valid + // Checks if there are servers previously matched that are no longer valid section.getServers().forEach(server -> { if (!results.contains(server)) { servers.remove(server); @@ -281,7 +281,7 @@ public class SectionManager { } }); - //Add matched servers to the section + // Add matched servers to the section int addedServers = 0; for (ServerInfo server : results) { if (!section.getServers().contains(server)) { @@ -306,7 +306,7 @@ public class SectionManager { public int calculatePosition(ServerSection section) { ServerSection current = section; - //Calculate above principal + // Calculate above principal int iterations = 0; while (current != null) { if (current == principal) { @@ -317,7 +317,7 @@ public class SectionManager { iterations++; } - //Calculate below principal + // Calculate below principal if (principal != null) { iterations = 0; current = principal; diff --git a/balancer/src/main/java/com/jaimemartz/playerbalancer/section/SectionServer.java b/balancer/src/main/java/com/jaimemartz/playerbalancer/section/SectionServer.java index 289dccc..8671a15 100644 --- a/balancer/src/main/java/com/jaimemartz/playerbalancer/section/SectionServer.java +++ b/balancer/src/main/java/com/jaimemartz/playerbalancer/section/SectionServer.java @@ -47,7 +47,7 @@ public class SectionServer extends BungeeServerInfo { @Override public boolean sendData(String channel, byte[] data, boolean queue) { - //Nothing to do + // Nothing to do return true; } diff --git a/balancer/src/main/java/com/jaimemartz/playerbalancer/utils/AdapterWrapper.java b/balancer/src/main/java/com/jaimemartz/playerbalancer/utils/AdapterWrapper.java index dc99d64..ecb6b12 100644 --- a/balancer/src/main/java/com/jaimemartz/playerbalancer/utils/AdapterWrapper.java +++ b/balancer/src/main/java/com/jaimemartz/playerbalancer/utils/AdapterWrapper.java @@ -11,7 +11,7 @@ public class AdapterWrapper implements ConfigurationAdapter { private final ConfigurationAdapter wrapped; public AdapterWrapper(ConfigurationAdapter adapter) { - //Prevents memory leak + // Prevents memory leak if (adapter instanceof AdapterWrapper) { this.wrapped = ((AdapterWrapper) adapter).wrapped; } else { diff --git a/balancer/src/main/java/com/jaimemartz/playerbalancer/utils/AlphanumComparator.java b/balancer/src/main/java/com/jaimemartz/playerbalancer/utils/AlphanumComparator.java index 92bb698..010d28b 100644 --- a/balancer/src/main/java/com/jaimemartz/playerbalancer/utils/AlphanumComparator.java +++ b/balancer/src/main/java/com/jaimemartz/playerbalancer/utils/AlphanumComparator.java @@ -98,14 +98,14 @@ public class AlphanumComparator implements Comparator String thatChunk = getChunk(s2, s2Length, thatMarker); thatMarker += thatChunk.length(); - // If both chunks contain numeric characters, sort them numerically + // If both chunks contain numeric characters, sort them numerically int result = 0; if (isDigit(thisChunk.charAt(0)) && isDigit(thatChunk.charAt(0))) { - // Simple chunk comparison by length. + // Simple chunk comparison by length. int thisChunkLength = thisChunk.length(); result = thisChunkLength - thatChunk.length(); - // If equal, the first different number counts + // If equal, the first different number counts if (result == 0) { for (int i = 0; i < thisChunkLength; i++) diff --git a/balancer/src/main/java/com/jaimemartz/playerbalancer/utils/LevenshteinDistance.java b/balancer/src/main/java/com/jaimemartz/playerbalancer/utils/LevenshteinDistance.java index 7f9c70e..13273b9 100644 --- a/balancer/src/main/java/com/jaimemartz/playerbalancer/utils/LevenshteinDistance.java +++ b/balancer/src/main/java/com/jaimemartz/playerbalancer/utils/LevenshteinDistance.java @@ -20,35 +20,35 @@ public final class LevenshteinDistance { int len0 = lhs.length() + 1; int len1 = rhs.length() + 1; - // the array of distances + // the array of distances int[] cost = new int[len0]; int[] newcost = new int[len0]; - // initial cost of skipping prefix in String s0 + // initial cost of skipping prefix in String s0 for (int i = 0; i < len0; i++) cost[i] = i; - // dynamically computing the array of distances + // dynamically computing the array of distances - // transformation cost for each letter in s1 + // transformation cost for each letter in s1 for (int j = 1; j < len1; j++) { - // initial cost of skipping prefix in String s1 + // initial cost of skipping prefix in String s1 newcost[0] = j; - // transformation cost for each letter in s0 + // transformation cost for each letter in s0 for (int i = 1; i < len0; i++) { - // matching current letters in both strings + // matching current letters in both strings int match = (lhs.charAt(i - 1) == rhs.charAt(j - 1)) ? 0 : 1; - // computing cost for each transformation + // computing cost for each transformation int cost_replace = cost[i - 1] + match; int cost_insert = cost[i] + 1; int cost_delete = newcost[i - 1] + 1; - // keep minimum cost + // keep minimum cost newcost[i] = Math.min(Math.min(cost_insert, cost_delete), cost_replace); } - // swap cost/newcost arrays + // swap cost/newcost arrays int[] swap = cost; cost = newcost; newcost = swap; diff --git a/balancer/src/main/java/com/jaimemartz/playerbalancer/utils/ServerListPing.java b/balancer/src/main/java/com/jaimemartz/playerbalancer/utils/ServerListPing.java index ab2e12e..9390d0e 100644 --- a/balancer/src/main/java/com/jaimemartz/playerbalancer/utils/ServerListPing.java +++ b/balancer/src/main/java/com/jaimemartz/playerbalancer/utils/ServerListPing.java @@ -56,31 +56,31 @@ public final class ServerListPing { DataInputStream dataInputStream = new DataInputStream(socket.getInputStream())) { ByteArrayOutputStream b = new ByteArrayOutputStream(); DataOutputStream handshake = new DataOutputStream(b); - handshake.writeByte(0x00); //packet id for handshake - writeVarInt(handshake, 4); //protocol version - writeVarInt(handshake, host.getHostString().length()); //host length - handshake.writeBytes(host.getHostString()); //host string - handshake.writeShort(host.getPort()); //port - writeVarInt(handshake, 1); //state (1 for handshake) + handshake.writeByte(0x00); // packet id for handshake + writeVarInt(handshake, 4); // protocol version + writeVarInt(handshake, host.getHostString().length()); // host length + handshake.writeBytes(host.getHostString()); // host string + handshake.writeShort(host.getPort()); // port + writeVarInt(handshake, 1); // state (1 for handshake) - writeVarInt(dataOutputStream, b.size()); //prepend size - dataOutputStream.write(b.toByteArray()); //write handshake packet + writeVarInt(dataOutputStream, b.size()); // prepend size + dataOutputStream.write(b.toByteArray()); // write handshake packet - dataOutputStream.writeByte(0x01); //size is only 1 - dataOutputStream.writeByte(0x00); //packet id for ping - int size = readVarInt(dataInputStream); //size of packet - int id = readVarInt(dataInputStream); //packet id + dataOutputStream.writeByte(0x01); // size is only 1 + dataOutputStream.writeByte(0x00); // packet id for ping + int size = readVarInt(dataInputStream); // size of packet + int id = readVarInt(dataInputStream); // packet id if (id == -1) { throw new IOException("Premature end of stream."); } - if (id != 0x00) { //we want a status response + if (id != 0x00) { // we want a status response throw new IOException("Invalid packetID"); } - int length = readVarInt(dataInputStream); //length of json string + int length = readVarInt(dataInputStream); // length of json string if (length == -1) { throw new IOException("Premature end of stream."); } @@ -90,14 +90,14 @@ public final class ServerListPing { } byte[] in = new byte[length]; - dataInputStream.readFully(in); //read json string + dataInputStream.readFully(in); // read json string String json = new String(in); long now = System.currentTimeMillis(); - dataOutputStream.writeByte(0x09); //size of packet - dataOutputStream.writeByte(0x01); //0x01 for ping - dataOutputStream.writeLong(now); //time!? + dataOutputStream.writeByte(0x09); // size of packet + dataOutputStream.writeByte(0x01); // 0x01 for ping + dataOutputStream.writeLong(now); // time!? readVarInt(dataInputStream); id = readVarInt(dataInputStream); @@ -109,7 +109,7 @@ public final class ServerListPing { throw new IOException("Invalid packetID"); } - long pingTime = dataInputStream.readLong(); //read response + long pingTime = dataInputStream.readLong(); // read response StatusResponse response = gson.fromJson(json, StatusResponse.class); response.time = (int) (now - pingTime); return response; From 9c448b8a8624ab286d124c2b27d865232f99b1ce Mon Sep 17 00:00:00 2001 From: Jaime Martinez Rincon Date: Sat, 20 Jun 2020 22:36:49 +0200 Subject: [PATCH 3/5] Remove support for RedisBungee --- 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 | 25 ------------------- .../settings/props/GeneralProps.java | 3 --- balancer/src/main/resources/default.conf | 3 --- 10 files changed, 5 insertions(+), 50 deletions(-) delete mode 100644 balancer/src/main/java/com/jaimemartz/playerbalancer/helper/NetworkManager.java diff --git a/balancer/pom.xml b/balancer/pom.xml index 310cec1..279a2ed 100644 --- a/balancer/pom.xml +++ b/balancer/pom.xml @@ -66,12 +66,6 @@ jar provided - - com.imaginarycode.minecraft - RedisBungee - 0.3.8-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 518bbaa..6df0b48 100644 --- a/balancer/src/main/java/com/jaimemartz/playerbalancer/PlayerBalancer.java +++ b/balancer/src/main/java/com/jaimemartz/playerbalancer/PlayerBalancer.java @@ -5,7 +5,6 @@ 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.*; @@ -34,7 +33,6 @@ public class PlayerBalancer extends Plugin { private StatusManager statusManager; private SettingsHolder settings; private SectionManager sectionManager; - private NetworkManager networkManager; private ConfigurationLoader loader; private FallbackCommand fallbackCommand; @@ -128,8 +126,6 @@ public class PlayerBalancer extends Plugin { getProxy().getPluginManager().registerListener(this, reloadListener); } - networkManager = new NetworkManager(this); - sectionManager = new SectionManager(this); sectionManager.load(); @@ -284,10 +280,6 @@ public class PlayerBalancer extends Plugin { return statusManager; } - public NetworkManager getNetworkManager() { - return networkManager; - } - public FallbackCommand getFallbackCommand() { return fallbackCommand; } 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 ca06e93..057452f 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 = plugin.getNetworkManager().getPlayers(server); + int count = server.getPlayers().size(); 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 30fc042..0e7f29f 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 = plugin.getNetworkManager().getPlayers(server); + int count = server.getPlayers().size(); 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 5329989..6dc99c4 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 (plugin.getNetworkManager().getPlayers(server) < status.getMaximum()) { + if (server.getPlayers().size() < 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 d68178e..53374be 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 = plugin.getNetworkManager().getPlayers(server); + int count = server.getPlayers().size(); 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 cd9f593..2ec8ed4 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 = plugin.getNetworkManager().getPlayers(server); + int count = server.getPlayers().size(); 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 deleted file mode 100644 index 44cb45a..0000000 --- a/balancer/src/main/java/com/jaimemartz/playerbalancer/helper/NetworkManager.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.jaimemartz.playerbalancer.helper; - -import com.imaginarycode.minecraft.redisbungee.RedisBungee; -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 RedisBungee.getApi().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 ce33895..af10050 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 @@ -16,9 +16,6 @@ public class GeneralProps { @Setting(value = "auto-reload") private boolean autoReload; - @Setting(value = "redis-bungee") - private boolean redisBungee; - @Setting(value = "plugin-messaging") private boolean pluginMessaging; diff --git a/balancer/src/main/resources/default.conf b/balancer/src/main/resources/default.conf index f83268f..81c0e9d 100644 --- a/balancer/src/main/resources/default.conf +++ b/balancer/src/main/resources/default.conf @@ -11,9 +11,6 @@ general { # When true, the plugin will reload when you execute /greload auto-reload=true - # When true, the plugin will get player counts from RedisBungee - redis-bungee=false - # When true, this plugin will print less messages when loading silent=false From f3ea23e6b00db69b79294d4d5c63375197ea708d Mon Sep 17 00:00:00 2001 From: Jaime Martinez Rincon Date: Sat, 20 Jun 2020 22:42:31 +0200 Subject: [PATCH 4/5] Bump version to 2.2 --- addon/pom.xml | 2 +- balancer/pom.xml | 2 +- pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/addon/pom.xml b/addon/pom.xml index 222be4b..63754eb 100644 --- a/addon/pom.xml +++ b/addon/pom.xml @@ -6,7 +6,7 @@ com.jaimemartz - 2.1.6.2-SNAPSHOT + 2.2-SNAPSHOT playerbalancer-parent diff --git a/balancer/pom.xml b/balancer/pom.xml index 279a2ed..ebd71e6 100644 --- a/balancer/pom.xml +++ b/balancer/pom.xml @@ -6,7 +6,7 @@ com.jaimemartz - 2.1.6.2-SNAPSHOT + 2.2-SNAPSHOT playerbalancer-parent diff --git a/pom.xml b/pom.xml index 372dbba..7ed35cb 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.jaimemartz playerbalancer-parent - 2.1.6.2-SNAPSHOT + 2.2-SNAPSHOT pom From a4294a8c56282d69b9a003a0a83889f5d4d842b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Mart=C3=ADnez=20Rinc=C3=B3n?= Date: Sun, 21 Jun 2020 00:33:44 +0200 Subject: [PATCH 5/5] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index dfe7086..15ed83b 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # PlayerBalancer -[Spigot Resource](https://www.spigotmc.org/resources/10788/) +[Spigot Resource](https://www.spigotmc.org/resources/playerbalancer.55011/) ### Build * Clone this repository