Merge pull request #24 from BGHDDevelopment/master

RedisBungee Fork Support
This commit is contained in:
Jaime Martínez Rincón 2021-08-28 16:24:22 +02:00 committed by GitHub
commit 2ba6f83696
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 51 additions and 5 deletions

View File

@ -66,6 +66,12 @@
<type>jar</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.imaginarycode.minecraft</groupId>
<artifactId>RedisBungee</artifactId>
<version>0.6.5-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>ninja.leaping.configurate</groupId>
<artifactId>configurate-hocon</artifactId>

View File

@ -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<CommentedConfigurationNode> 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;
}
}

View File

@ -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;

View File

@ -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;

View File

@ -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 (server.getPlayers().size() < status.getMaximum()) {
if (plugin.getNetworkManager().getPlayers(server) < status.getMaximum()) {
return server;
}
}

View File

@ -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) {

View File

@ -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) {

View File

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

View File

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

View File

@ -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