mirror of
https://github.com/BGHDDevelopment/PlayerBalancer.git
synced 2024-11-17 08:15:11 +01:00
Merge pull request #24 from BGHDDevelopment/master
RedisBungee Fork Support
This commit is contained in:
commit
2ba6f83696
@ -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>
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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) {
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user