Merge branch 'master' of github.com:jamezrin/PlayerBalancer

This commit is contained in:
Jaime Martínez Rincón 2020-07-12 20:16:13 +02:00
commit eea1bb42cd
No known key found for this signature in database
GPG Key ID: D7F007B5BBA8E142
27 changed files with 80 additions and 126 deletions

View File

@ -1,5 +1,5 @@
# PlayerBalancer # PlayerBalancer
[Spigot Resource](https://www.spigotmc.org/resources/10788/) [Spigot Resource](https://www.spigotmc.org/resources/playerbalancer.55011/)
### Build ### Build
* Clone this repository * Clone this repository

View File

@ -6,7 +6,7 @@
<parent> <parent>
<groupId>com.jaimemartz</groupId> <groupId>com.jaimemartz</groupId>
<version>2.1.6.2-SNAPSHOT</version> <version>2.2-SNAPSHOT</version>
<artifactId>playerbalancer-parent</artifactId> <artifactId>playerbalancer-parent</artifactId>
</parent> </parent>

View File

@ -6,7 +6,7 @@
<parent> <parent>
<groupId>com.jaimemartz</groupId> <groupId>com.jaimemartz</groupId>
<version>2.1.6.2-SNAPSHOT</version> <version>2.2-SNAPSHOT</version>
<artifactId>playerbalancer-parent</artifactId> <artifactId>playerbalancer-parent</artifactId>
</parent> </parent>
@ -66,12 +66,6 @@
<type>jar</type> <type>jar</type>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>com.imaginarycode.minecraft</groupId>
<artifactId>RedisBungee</artifactId>
<version>0.3.8-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency> <dependency>
<groupId>ninja.leaping.configurate</groupId> <groupId>ninja.leaping.configurate</groupId>
<artifactId>configurate-hocon</artifactId> <artifactId>configurate-hocon</artifactId>

View File

@ -5,7 +5,6 @@ import com.jaimemartz.playerbalancer.commands.FallbackCommand;
import com.jaimemartz.playerbalancer.commands.MainCommand; import com.jaimemartz.playerbalancer.commands.MainCommand;
import com.jaimemartz.playerbalancer.commands.ManageCommand; import com.jaimemartz.playerbalancer.commands.ManageCommand;
import com.jaimemartz.playerbalancer.connection.ServerAssignRegistry; import com.jaimemartz.playerbalancer.connection.ServerAssignRegistry;
import com.jaimemartz.playerbalancer.helper.NetworkManager;
import com.jaimemartz.playerbalancer.helper.PasteHelper; import com.jaimemartz.playerbalancer.helper.PasteHelper;
import com.jaimemartz.playerbalancer.helper.PlayerLocker; import com.jaimemartz.playerbalancer.helper.PlayerLocker;
import com.jaimemartz.playerbalancer.listeners.*; import com.jaimemartz.playerbalancer.listeners.*;
@ -34,7 +33,6 @@ public class PlayerBalancer extends Plugin {
private StatusManager statusManager; private StatusManager statusManager;
private SettingsHolder settings; private SettingsHolder settings;
private SectionManager sectionManager; private SectionManager sectionManager;
private NetworkManager networkManager;
private ConfigurationLoader<CommentedConfigurationNode> loader; private ConfigurationLoader<CommentedConfigurationNode> loader;
private FallbackCommand fallbackCommand; private FallbackCommand fallbackCommand;
@ -128,8 +126,6 @@ public class PlayerBalancer extends Plugin {
getProxy().getPluginManager().registerListener(this, reloadListener); getProxy().getPluginManager().registerListener(this, reloadListener);
} }
networkManager = new NetworkManager(this);
sectionManager = new SectionManager(this); sectionManager = new SectionManager(this);
sectionManager.load(); sectionManager.load();
@ -284,10 +280,6 @@ public class PlayerBalancer extends Plugin {
return statusManager; return statusManager;
} }
public NetworkManager getNetworkManager() {
return networkManager;
}
public FallbackCommand getFallbackCommand() { public FallbackCommand getFallbackCommand() {
return fallbackCommand; return fallbackCommand;
} }

View File

@ -39,13 +39,9 @@ public abstract class ConnectionIntent {
.replace("{alias}", safeNull(section.getProps().getAlias())) .replace("{alias}", safeNull(section.getProps().getAlias()))
); );
// Ensure a new copy of the section servers
List<ServerInfo> servers = new ArrayList<>(section.getServers()); List<ServerInfo> 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(); Server current = player.getServer();
if (current != null) { if (current != null) {

View File

@ -17,7 +17,7 @@ public class ProgressiveFillerProvider extends AbstractProvider {
for (ServerInfo server : servers) { for (ServerInfo server : servers) {
ServerStatus status = plugin.getStatusManager().getStatus(server); ServerStatus status = plugin.getStatusManager().getStatus(server);
int count = plugin.getNetworkManager().getPlayers(server); int count = server.getPlayers().size();
if (count > max && count <= status.getMaximum()) { if (count > max && count <= status.getMaximum()) {
max = count; max = count;

View File

@ -15,7 +15,7 @@ public class ProgressiveLowestProvider extends AbstractProvider {
ServerInfo target = null; ServerInfo target = null;
for (ServerInfo server : servers) { for (ServerInfo server : servers) {
int count = plugin.getNetworkManager().getPlayers(server); int count = server.getPlayers().size();
if (count < min) { if (count < min) {
min = count; min = count;

View File

@ -14,7 +14,7 @@ public class ProgressiveProvider extends AbstractProvider {
public ServerInfo requestTarget(PlayerBalancer plugin, ServerSection section, List<ServerInfo> servers, ProxiedPlayer player) { public ServerInfo requestTarget(PlayerBalancer plugin, ServerSection section, List<ServerInfo> servers, ProxiedPlayer player) {
for (ServerInfo server : servers) { for (ServerInfo server : servers) {
ServerStatus status = plugin.getStatusManager().getStatus(server); ServerStatus status = plugin.getStatusManager().getStatus(server);
if (plugin.getNetworkManager().getPlayers(server) < status.getMaximum()) { if (server.getPlayers().size() < status.getMaximum()) {
return server; return server;
} }
} }

View File

@ -18,7 +18,7 @@ public class RandomFillerProvider extends AbstractProvider {
int max = Integer.MIN_VALUE; int max = Integer.MIN_VALUE;
for (ServerInfo server : servers) { for (ServerInfo server : servers) {
int count = plugin.getNetworkManager().getPlayers(server); int count = server.getPlayers().size();
if (count >= max) { if (count >= max) {
if (count > max) { if (count > max) {

View File

@ -18,7 +18,7 @@ public class RandomLowestProvider extends AbstractProvider {
int min = Integer.MAX_VALUE; int min = Integer.MAX_VALUE;
for (ServerInfo server : servers) { for (ServerInfo server : servers) {
int count = plugin.getNetworkManager().getPlayers(server); int count = server.getPlayers().size();
if (count <= min) { if (count <= min) {
if (count < min) { if (count < min) {

View File

@ -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();
}
}

View File

@ -37,7 +37,7 @@ public enum PingTactic {
try { try {
server.ping((ping, throwable) -> { server.ping((ping, throwable) -> {
if (ping != null) { if (ping != null) {
//using deprecated method for bungee 1.8 compatibility // Using deprecated method for bungee 1.8 compatibility
callback.done(new ServerStatus( callback.done(new ServerStatus(
ping.getDescription(), ping.getDescription(),
ping.getPlayers().getOnline(), ping.getPlayers().getOnline(),

View File

@ -235,8 +235,10 @@ public class SectionManager {
} }
public void registerServer(ServerInfo server, ServerSection section) { public void registerServer(ServerInfo server, ServerSection section) {
//Checking for duplicated server on non dummy sections if (!isDummy(section)) {
if (servers.containsKey(server) && !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); ServerSection other = servers.get(server);
throw new IllegalArgumentException(String.format( throw new IllegalArgumentException(String.format(
"The server \"%s\" is already in the section \"%s\"", "The server \"%s\" is already in the section \"%s\"",
@ -252,6 +254,7 @@ public class SectionManager {
servers.put(server, section); servers.put(server, section);
} }
}
public void calculateServers(ServerSection section) { public void calculateServers(ServerSection section) {
Set<ServerInfo> results = new HashSet<>(); Set<ServerInfo> results = new HashSet<>();

View File

@ -16,9 +16,6 @@ public class GeneralProps {
@Setting(value = "auto-reload") @Setting(value = "auto-reload")
private boolean autoReload; private boolean autoReload;
@Setting(value = "redis-bungee")
private boolean redisBungee;
@Setting(value = "plugin-messaging") @Setting(value = "plugin-messaging")
private boolean pluginMessaging; private boolean pluginMessaging;

View File

@ -11,9 +11,6 @@ general {
# When true, the plugin will reload when you execute /greload # When true, the plugin will reload when you execute /greload
auto-reload=true 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 # When true, this plugin will print less messages when loading
silent=false silent=false

View File

@ -6,7 +6,7 @@
<groupId>com.jaimemartz</groupId> <groupId>com.jaimemartz</groupId>
<artifactId>playerbalancer-parent</artifactId> <artifactId>playerbalancer-parent</artifactId>
<version>2.1.6.2-SNAPSHOT</version> <version>2.2-SNAPSHOT</version>
<packaging>pom</packaging> <packaging>pom</packaging>
<modules> <modules>