null checks
This commit is contained in:
@@ -49,6 +49,9 @@ public class Main extends Plugin implements Listener {
|
||||
public void onEnable() {
|
||||
plugin = this;
|
||||
|
||||
config = new BungeeConfig(this);
|
||||
checkConfig();
|
||||
|
||||
LinkedHashMap<String, String> d = new LinkedHashMap<>();
|
||||
|
||||
|
||||
@@ -110,9 +113,6 @@ public class Main extends Plugin implements Listener {
|
||||
msgs = BungeeMessages.getInstance(this, d);
|
||||
//msgs = BungeeMessages.getInstance(this);
|
||||
|
||||
config = new BungeeConfig(this);
|
||||
checkConfig();
|
||||
|
||||
aliases = new AliasManager(this);
|
||||
|
||||
moveCommand = new MoveCommand(this);
|
||||
@@ -144,6 +144,9 @@ public class Main extends Plugin implements Listener {
|
||||
|
||||
|
||||
public void checkConfig() {
|
||||
if(config == null) {
|
||||
getLogger().warning("Config is null!");
|
||||
}
|
||||
List<String> svs = getConfig().getStringList("queue-servers");
|
||||
for(String s : svs) {
|
||||
if(!s.contains(":")) {
|
||||
|
||||
@@ -185,10 +185,14 @@ public class Manager {
|
||||
* Also creates/edits server groups
|
||||
*/
|
||||
public void reloadServers() {
|
||||
if(pl.config == null) {
|
||||
pl.getLogger().warning("[MAN] Config is null");
|
||||
}
|
||||
Map<String, ServerInfo> svs = ProxyServer.getInstance().getServers();
|
||||
for(String name : svs.keySet()) {
|
||||
if(findServer(name) != null) continue;
|
||||
ServerInfo info = svs.get(name);
|
||||
//pl.getLogger().info("Adding server "+name);
|
||||
servers.add(new QueueServer(name, info));
|
||||
}
|
||||
|
||||
@@ -362,10 +366,12 @@ public class Manager {
|
||||
for(QueueServer s : servers) {
|
||||
int ot = s.getOfflineTime();
|
||||
List<ProxiedPlayer> plys = s.getQueue();
|
||||
for(ProxiedPlayer ply : plys) {
|
||||
Iterator<ProxiedPlayer> it = plys.iterator();
|
||||
while(it.hasNext()) {
|
||||
ProxiedPlayer ply = it.next();
|
||||
int pos = plys.indexOf(ply)+1;
|
||||
if(pos == 0) {
|
||||
plys.remove(ply);
|
||||
it.remove();
|
||||
continue;
|
||||
}
|
||||
int len = plys.size();
|
||||
@@ -389,6 +395,8 @@ public class Manager {
|
||||
status = msgs.get("status.offline.paused");
|
||||
}
|
||||
|
||||
if(status.isEmpty()) return;
|
||||
|
||||
ply.sendMessage(Main.formatMessage(
|
||||
msgs.get("status.offline.base")
|
||||
.replaceAll("\\{STATUS\\}", status)
|
||||
@@ -397,6 +405,7 @@ public class Manager {
|
||||
.replaceAll("\\{SERVER\\}", pl.aliases.getAlias(s.getName()))
|
||||
));
|
||||
} else {
|
||||
if(msgs.get("spigot.actionbar.offline").isEmpty()) return;
|
||||
int time = (int) Math.round(pos*pl.timeBetweenPlayers);
|
||||
int min = (int) Math.floor((time) / (60));
|
||||
int sec = (int) Math.floor((time % (60)));
|
||||
@@ -430,6 +439,7 @@ public class Manager {
|
||||
*/
|
||||
public QueueServer findServer(String name) {
|
||||
for(QueueServer server : servers) {
|
||||
if(server == null) continue;
|
||||
if(server.getName().equals(name)) {
|
||||
return server;
|
||||
}
|
||||
|
||||
@@ -18,20 +18,15 @@ public class QueueServer {
|
||||
List<ServerInfo> servers;
|
||||
|
||||
public QueueServer(String name, ServerInfo info) {
|
||||
if(Manager.getInstance() == null || Manager.getInstance().pl.config == null) {
|
||||
ProxyServer.getInstance().getLogger()
|
||||
.warning("[ajQueue] Something tried to load a QueueServer too early! The plugin hasnt fully loaded yet!");
|
||||
return;
|
||||
}
|
||||
this.name = name;
|
||||
this.servers = Arrays.asList(info);
|
||||
update();
|
||||
init(name, Arrays.asList(info));
|
||||
}
|
||||
public QueueServer(String name, List<ServerInfo> infos) {
|
||||
if(Manager.getInstance() == null || Manager.getInstance().pl.config == null) {
|
||||
init(name, infos);
|
||||
}
|
||||
private void init(String name, List<ServerInfo> infos) {
|
||||
if(Manager.getInstance() == null || Main.plugin.getConfig() == null) {
|
||||
ProxyServer.getInstance().getLogger()
|
||||
.warning("[ajQueue] Something tried to load a QueueServer too early! The plugin hasnt fully loaded yet!");
|
||||
return;
|
||||
.warning("[ajQueue] Something is loading a QueueServer too early! The plugin hasnt fully loaded yet!");
|
||||
}
|
||||
this.name = name;
|
||||
this.servers = infos;
|
||||
@@ -61,13 +56,13 @@ public class QueueServer {
|
||||
info.ping(new Callback<ServerPing>() {
|
||||
@Override
|
||||
public void done(ServerPing result, Throwable error) {
|
||||
if(Manager.getInstance() == null || Manager.getInstance().pl.config == null) {
|
||||
if(Manager.getInstance() == null || Main.plugin.getConfig() == null) {
|
||||
ProxyServer.getInstance().getLogger()
|
||||
.warning("[ajQueue] Something used update() too early! The plugin hasnt fully loaded yet!");
|
||||
return;
|
||||
}
|
||||
boolean online = error == null;
|
||||
BungeeConfig config = Manager.getInstance().pl.config;
|
||||
BungeeConfig config = Main.plugin.getConfig();
|
||||
|
||||
if(config.getBoolean("pinger-debug")) {
|
||||
if(error != null) {
|
||||
@@ -125,7 +120,7 @@ public class QueueServer {
|
||||
}
|
||||
long lastOffline = 0;
|
||||
public boolean isOnline() {
|
||||
BungeeConfig config = Manager.getInstance().pl.config;
|
||||
BungeeConfig config = Main.plugin.getConfig();
|
||||
if(System.currentTimeMillis()-lastOffline <= (config.getInt("wait-after-online")*1000) && online) {
|
||||
return false;
|
||||
}
|
||||
@@ -136,7 +131,7 @@ public class QueueServer {
|
||||
}
|
||||
|
||||
public boolean justWentOnline() {
|
||||
BungeeConfig config = Manager.getInstance().pl.config;
|
||||
BungeeConfig config = Main.plugin.getConfig();
|
||||
return System.currentTimeMillis()-lastOffline <= (config.getDouble("wait-time")) && online;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user