mirror of
https://github.com/BGHDDevelopment/PlayerBalancer.git
synced 2024-11-23 11:15:30 +01:00
Merge branch 'master' of github.com:jamezrin/PlayerBalancer
This commit is contained in:
commit
eea1bb42cd
@ -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
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
<parent>
|
||||
<groupId>com.jaimemartz</groupId>
|
||||
<version>2.1.6.2-SNAPSHOT</version>
|
||||
<version>2.2-SNAPSHOT</version>
|
||||
<artifactId>playerbalancer-parent</artifactId>
|
||||
</parent>
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
<parent>
|
||||
<groupId>com.jaimemartz</groupId>
|
||||
<version>2.1.6.2-SNAPSHOT</version>
|
||||
<version>2.2-SNAPSHOT</version>
|
||||
<artifactId>playerbalancer-parent</artifactId>
|
||||
</parent>
|
||||
|
||||
@ -66,12 +66,6 @@
|
||||
<type>jar</type>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.imaginarycode.minecraft</groupId>
|
||||
<artifactId>RedisBungee</artifactId>
|
||||
<version>0.3.8-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ninja.leaping.configurate</groupId>
|
||||
<artifactId>configurate-hocon</artifactId>
|
||||
|
@ -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<CommentedConfigurationNode> 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;
|
||||
}
|
||||
|
@ -39,13 +39,9 @@ public abstract class ConnectionIntent {
|
||||
.replace("{alias}", safeNull(section.getProps().getAlias()))
|
||||
);
|
||||
|
||||
// Ensure a new copy of the section servers
|
||||
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
|
||||
Server current = player.getServer();
|
||||
if (current != null) {
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -14,7 +14,7 @@ public class ProgressiveProvider extends AbstractProvider {
|
||||
public ServerInfo requestTarget(PlayerBalancer plugin, ServerSection section, List<ServerInfo> 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;
|
||||
}
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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) {
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
@ -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(),
|
||||
|
@ -235,8 +235,10 @@ public class SectionManager {
|
||||
}
|
||||
|
||||
public void registerServer(ServerInfo server, ServerSection section) {
|
||||
//Checking for duplicated server on non dummy sections
|
||||
if (servers.containsKey(server) && !isDummy(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
|
||||
if (servers.containsKey(server)) {
|
||||
ServerSection other = servers.get(server);
|
||||
throw new IllegalArgumentException(String.format(
|
||||
"The server \"%s\" is already in the section \"%s\"",
|
||||
@ -252,6 +254,7 @@ public class SectionManager {
|
||||
|
||||
servers.put(server, section);
|
||||
}
|
||||
}
|
||||
|
||||
public void calculateServers(ServerSection section) {
|
||||
Set<ServerInfo> results = new HashSet<>();
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user