mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-30 16:19:56 +08:00
Fixed unfinished RedisBungee setup causing NPE
This commit is contained in:
parent
c96b6c0733
commit
4beea6c50f
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user