mirror of
https://github.com/BGHDDevelopment/PlayerBalancer.git
synced 2024-11-09 04:20:32 +01:00
Fixed a NPE when querying status from the StatusManager when disabled
This commit is contained in:
parent
f248134192
commit
55d1ff22ee
@ -8,7 +8,7 @@ import me.jaimemartz.lobbybalancer.configuration.ConfigEntries;
|
||||
import me.jaimemartz.lobbybalancer.connection.ServerAssignRegistry;
|
||||
import me.jaimemartz.lobbybalancer.listener.*;
|
||||
import me.jaimemartz.lobbybalancer.manager.PlayerLocker;
|
||||
import me.jaimemartz.lobbybalancer.ping.PingManager;
|
||||
import me.jaimemartz.lobbybalancer.ping.StatusManager;
|
||||
import me.jaimemartz.lobbybalancer.section.SectionManager;
|
||||
import me.jaimemartz.lobbybalancer.utils.DigitUtils;
|
||||
import net.md_5.bungee.api.plugin.Command;
|
||||
@ -20,7 +20,6 @@ import org.inventivetalent.update.bungee.BungeeUpdater;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class LobbyBalancer extends Plugin {
|
||||
public static final String USER_ID = "%%__USER__%%";
|
||||
@ -31,7 +30,7 @@ public class LobbyBalancer extends Plugin {
|
||||
private boolean failed = false;
|
||||
|
||||
private ConfigFactory factory;
|
||||
private PingManager pingManager;
|
||||
private StatusManager statusManager;
|
||||
private SectionManager sectionManager;
|
||||
private Command fallbackCommand, mainCommand, manageCommand;
|
||||
private Listener connectListener, kickListener, messageListener, reloadListener;
|
||||
@ -92,8 +91,9 @@ public class LobbyBalancer extends Plugin {
|
||||
try {
|
||||
sectionManager.load();
|
||||
|
||||
statusManager = new StatusManager();
|
||||
if (ConfigEntries.SERVER_CHECK_ENABLED.get()) {
|
||||
pingManager = new PingManager(this);
|
||||
statusManager.start(this);
|
||||
}
|
||||
|
||||
if (ConfigEntries.FALLBACK_COMMAND_ENABLED.get()) {
|
||||
@ -149,8 +149,7 @@ public class LobbyBalancer extends Plugin {
|
||||
}
|
||||
|
||||
if (ConfigEntries.SERVER_CHECK_ENABLED.get()) {
|
||||
pingManager.stop();
|
||||
pingManager = null;
|
||||
statusManager.stop();
|
||||
}
|
||||
|
||||
if (ConfigEntries.FALLBACK_COMMAND_ENABLED.get()) {
|
||||
@ -193,8 +192,8 @@ public class LobbyBalancer extends Plugin {
|
||||
getLogger().info(String.format("The plugin has been reloaded, took %sms", ending));
|
||||
}
|
||||
|
||||
public PingManager getPingManager() {
|
||||
return pingManager;
|
||||
public StatusManager getStatusManager() {
|
||||
return statusManager;
|
||||
}
|
||||
|
||||
public SectionManager getSectionManager() {
|
||||
|
@ -6,7 +6,7 @@ import me.jaimemartz.faucet.StringCombiner;
|
||||
import me.jaimemartz.lobbybalancer.LobbyBalancer;
|
||||
import me.jaimemartz.lobbybalancer.configuration.ConfigEntries;
|
||||
import me.jaimemartz.lobbybalancer.connection.ConnectionIntent;
|
||||
import me.jaimemartz.lobbybalancer.ping.PingStatus;
|
||||
import me.jaimemartz.lobbybalancer.ping.StatusInfo;
|
||||
import me.jaimemartz.lobbybalancer.section.ServerSection;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
@ -117,7 +117,7 @@ public class ManageCommand extends Command {
|
||||
if (!section.getServers().isEmpty()) {
|
||||
msgr.send("&7Section Servers: ");
|
||||
section.getServers().forEach(server -> {
|
||||
PingStatus status = plugin.getPingManager().getStatus(server);
|
||||
StatusInfo status = plugin.getStatusManager().getStatus(server);
|
||||
msgr.send("&7> Server &b{name} &c({connected}/{maximum}) &7({status}&7)",
|
||||
new Replacement("{name}", server.getName()),
|
||||
new Replacement("{connected}", String.valueOf(status.getOnlinePlayers())),
|
||||
|
@ -5,7 +5,7 @@ import me.jaimemartz.faucet.Replacement;
|
||||
import me.jaimemartz.lobbybalancer.LobbyBalancer;
|
||||
import me.jaimemartz.lobbybalancer.configuration.ConfigEntries;
|
||||
import me.jaimemartz.lobbybalancer.manager.PlayerLocker;
|
||||
import me.jaimemartz.lobbybalancer.ping.PingStatus;
|
||||
import me.jaimemartz.lobbybalancer.ping.StatusInfo;
|
||||
import me.jaimemartz.lobbybalancer.section.ServerSection;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
@ -57,7 +57,7 @@ public abstract class ConnectionIntent {
|
||||
if (ConfigEntries.ASSIGN_TARGETS_ENABLED.get()) {
|
||||
if (ServerAssignRegistry.hasAssignedServer(player, section)) {
|
||||
ServerInfo target = ServerAssignRegistry.getAssignedServer(player, section);
|
||||
PingStatus status = plugin.getPingManager().getStatus(target);
|
||||
StatusInfo status = plugin.getStatusManager().getStatus(target);
|
||||
if (status.isAccessible()) {
|
||||
return target;
|
||||
} else {
|
||||
@ -74,7 +74,7 @@ public abstract class ConnectionIntent {
|
||||
ServerInfo target = provider.requestTarget(plugin, section, servers, player);
|
||||
if (target == null) continue;
|
||||
|
||||
PingStatus status = plugin.getPingManager().getStatus(target);
|
||||
StatusInfo status = plugin.getStatusManager().getStatus(target);
|
||||
if (status.isAccessible()) {
|
||||
return target;
|
||||
} else {
|
||||
|
@ -3,7 +3,7 @@ package me.jaimemartz.lobbybalancer.connection;
|
||||
import com.google.common.collect.Iterables;
|
||||
import me.jaimemartz.lobbybalancer.LobbyBalancer;
|
||||
import me.jaimemartz.lobbybalancer.manager.NetworkManager;
|
||||
import me.jaimemartz.lobbybalancer.ping.PingStatus;
|
||||
import me.jaimemartz.lobbybalancer.ping.StatusInfo;
|
||||
import me.jaimemartz.lobbybalancer.section.ServerSection;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
@ -56,7 +56,7 @@ public enum ProviderType {
|
||||
@Override
|
||||
public ServerInfo requestTarget(LobbyBalancer plugin, ServerSection section, List<ServerInfo> list, ProxiedPlayer player) {
|
||||
for (ServerInfo server : list) {
|
||||
PingStatus status = plugin.getPingManager().getStatus(server);
|
||||
StatusInfo status = plugin.getStatusManager().getStatus(server);
|
||||
if (NetworkManager.getPlayers(server).size() < status.getMaximumPlayers()) {
|
||||
return server;
|
||||
}
|
||||
@ -73,7 +73,7 @@ public enum ProviderType {
|
||||
ServerInfo target = null;
|
||||
|
||||
for (ServerInfo server : list) {
|
||||
PingStatus status = plugin.getPingManager().getStatus(server);
|
||||
StatusInfo status = plugin.getStatusManager().getStatus(server);
|
||||
int count = NetworkManager.getPlayers(server).size();
|
||||
|
||||
if (count > max && count <= status.getMaximumPlayers()) {
|
||||
|
@ -14,12 +14,12 @@ public enum PingTactic {
|
||||
ServerListPing utility = new ServerListPing();
|
||||
|
||||
@Override
|
||||
public void ping(ServerInfo server, Callback<PingStatus> callback, LobbyBalancer plugin) {
|
||||
public void ping(ServerInfo server, Callback<StatusInfo> callback, LobbyBalancer plugin) {
|
||||
utility.setTimeout(ConfigEntries.SERVER_CHECK_TIMEOUT.get());
|
||||
plugin.getProxy().getScheduler().runAsync(plugin, () -> {
|
||||
try {
|
||||
StatusResponse response = utility.ping(server.getAddress());
|
||||
callback.done(new PingStatus(
|
||||
callback.done(new StatusInfo(
|
||||
response.getDescription().toLegacyText(),
|
||||
response.getPlayers().getOnline(),
|
||||
response.getPlayers().getMax()),
|
||||
@ -33,11 +33,11 @@ public enum PingTactic {
|
||||
|
||||
GENERIC {
|
||||
@Override
|
||||
public void ping(ServerInfo server, Callback<PingStatus> callback, LobbyBalancer plugin) {
|
||||
public void ping(ServerInfo server, Callback<StatusInfo> callback, LobbyBalancer plugin) {
|
||||
try {
|
||||
server.ping((ping, throwable) -> {
|
||||
if (ping != null) {
|
||||
callback.done(new PingStatus(
|
||||
callback.done(new StatusInfo(
|
||||
ping.getDescription(),
|
||||
ping.getPlayers().getOnline(),
|
||||
ping.getPlayers().getMax()
|
||||
@ -52,5 +52,5 @@ public enum PingTactic {
|
||||
}
|
||||
};
|
||||
|
||||
public abstract void ping(ServerInfo server, Callback<PingStatus> callback, LobbyBalancer plugin);
|
||||
public abstract void ping(ServerInfo server, Callback<StatusInfo> callback, LobbyBalancer plugin);
|
||||
}
|
||||
|
@ -3,20 +3,20 @@ package me.jaimemartz.lobbybalancer.ping;
|
||||
import me.jaimemartz.lobbybalancer.configuration.ConfigEntries;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
|
||||
public final class PingStatus {
|
||||
public final class StatusInfo {
|
||||
private final String description;
|
||||
private final int online, maximum;
|
||||
private boolean outdated = true;
|
||||
|
||||
public PingStatus() {
|
||||
public StatusInfo() {
|
||||
this("Server Unreachable", 0, 0);
|
||||
}
|
||||
|
||||
public PingStatus(ServerInfo server) {
|
||||
public StatusInfo(ServerInfo server) {
|
||||
this(server.getMotd(), server.getPlayers().size(), Integer.MAX_VALUE);
|
||||
}
|
||||
|
||||
public PingStatus(String description, int online, int maximum) {
|
||||
public StatusInfo(String description, int online, int maximum) {
|
||||
this.description = description;
|
||||
this.online = online;
|
||||
this.maximum = maximum;
|
@ -10,13 +10,13 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class PingManager {
|
||||
public class StatusManager {
|
||||
private boolean stopped = true;
|
||||
private PingTactic tactic;
|
||||
private ScheduledTask task;
|
||||
private final Map<ServerInfo, PingStatus> storage = new HashMap<>();
|
||||
private final Map<ServerInfo, StatusInfo> storage = new HashMap<>();
|
||||
|
||||
public PingManager(LobbyBalancer plugin) {
|
||||
public void start(LobbyBalancer plugin) {
|
||||
if (task != null) {
|
||||
stop();
|
||||
}
|
||||
@ -54,7 +54,7 @@ public class PingManager {
|
||||
private void update(LobbyBalancer plugin, ServerInfo server) {
|
||||
tactic.ping(server, (status, throwable) -> {
|
||||
if (status == null) {
|
||||
status = new PingStatus();
|
||||
status = new StatusInfo();
|
||||
}
|
||||
|
||||
status.setOutdated(false);
|
||||
@ -62,11 +62,11 @@ public class PingManager {
|
||||
}, plugin);
|
||||
}
|
||||
|
||||
public PingStatus getStatus(ServerInfo server) {
|
||||
PingStatus status = storage.get(server);
|
||||
public StatusInfo getStatus(ServerInfo server) {
|
||||
StatusInfo status = storage.get(server);
|
||||
|
||||
if (status == null) {
|
||||
return new PingStatus(server);
|
||||
return new StatusInfo(server);
|
||||
} else {
|
||||
return status;
|
||||
}
|
@ -7,12 +7,13 @@ import net.md_5.bungee.api.config.ServerInfo;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
public class WrappedAdapter implements ConfigurationAdapter {
|
||||
public class AdapterWrapper implements ConfigurationAdapter {
|
||||
private final ConfigurationAdapter wrapped;
|
||||
|
||||
public WrappedAdapter(ConfigurationAdapter adapter) {
|
||||
if (adapter instanceof WrappedAdapter) {
|
||||
this.wrapped = ((WrappedAdapter) adapter).wrapped;
|
||||
public AdapterWrapper(ConfigurationAdapter adapter) {
|
||||
//Prevents memory leak
|
||||
if (adapter instanceof AdapterWrapper) {
|
||||
this.wrapped = ((AdapterWrapper) adapter).wrapped;
|
||||
} else {
|
||||
this.wrapped = adapter;
|
||||
}
|
@ -7,7 +7,7 @@ import net.md_5.bungee.api.config.ServerInfo;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class FixedAdapter extends WrappedAdapter {
|
||||
public class FixedAdapter extends AdapterWrapper {
|
||||
private static final Map<String, ServerInfo> fakeServers = new HashMap<>();
|
||||
|
||||
static {
|
||||
|
Loading…
Reference in New Issue
Block a user