Fixed unfinished RedisBungee setup causing NPE

This commit is contained in:
Risto Lahtela 2020-03-28 13:27:32 +02:00
parent c96b6c0733
commit 4beea6c50f
2 changed files with 12 additions and 3 deletions

View File

@ -28,10 +28,12 @@ import java.util.function.IntSupplier;
public class BungeeSensor implements ServerSensor<Object> {
private final IntSupplier onlinePlayerCountSupplier;
private final IntSupplier onlinePlayerCountBungee;
@Inject
public BungeeSensor(PlanBungee plugin) {
onlinePlayerCountSupplier = RedisCheck.isClassAvailable() ? new RedisPlayersOnlineSupplier() : plugin.getProxy()::getOnlineCount;
onlinePlayerCountBungee = plugin.getProxy()::getOnlineCount;
onlinePlayerCountSupplier = RedisCheck.isClassAvailable() ? new RedisPlayersOnlineSupplier() : onlinePlayerCountBungee;
}
@Override
@ -41,6 +43,7 @@ public class BungeeSensor implements ServerSensor<Object> {
@Override
public int getOnlinePlayerCount() {
return onlinePlayerCountSupplier.getAsInt();
int count = onlinePlayerCountSupplier.getAsInt();
return count != -1 ? count : onlinePlayerCountBungee.getAsInt();
}
}

View File

@ -17,6 +17,7 @@
package com.djrapitops.plan.identification.properties;
import com.imaginarycode.minecraft.redisbungee.RedisBungee;
import com.imaginarycode.minecraft.redisbungee.RedisBungeeAPI;
import java.util.function.IntSupplier;
@ -29,6 +30,11 @@ public class RedisPlayersOnlineSupplier implements IntSupplier {
@Override
public int getAsInt() {
return RedisBungee.getApi().getPlayerCount();
RedisBungeeAPI api = RedisBungee.getApi();
try {
return api != null ? api.getPlayerCount() : -1;
} catch (NullPointerException e) {
return -1;
}
}
}