mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-23 17:47:38 +01:00
Added RedisBungee online count #642, split ServerProperties to 3 classes
This commit is contained in:
parent
20994b07d9
commit
8da9dc643b
@ -145,6 +145,10 @@
|
||||
<id>sponge-repo</id>
|
||||
<url>https://repo.spongepowered.org/maven</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>md_5-releases</id>
|
||||
<url>http://repo.md-5.net/content/repositories/releases/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
@ -347,6 +351,12 @@
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.imaginarycode.minecraft</groupId>
|
||||
<artifactId>RedisBungee</artifactId>
|
||||
<version>RELEASE</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
|
13
Plan/pom.xml
13
Plan/pom.xml
@ -24,6 +24,11 @@
|
||||
<id>sponge-repo</id>
|
||||
<url>https://repo.spongepowered.org/maven</url>
|
||||
</repository>
|
||||
<!-- RedisBungee Repository -->
|
||||
<repository>
|
||||
<id>md_5-releases</id>
|
||||
<url>http://repo.md-5.net/content/repositories/releases/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
@ -77,6 +82,14 @@
|
||||
<type>jar</type>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- RedisBungee -->
|
||||
<dependency>
|
||||
<groupId>com.imaginarycode.minecraft</groupId>
|
||||
<artifactId>RedisBungee</artifactId>
|
||||
<version>RELEASE</version>
|
||||
<type>jar</type>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- String Replacer -->
|
||||
<dependency>
|
||||
|
@ -13,7 +13,7 @@ import com.djrapitops.plan.data.store.mutators.health.HealthInformation;
|
||||
import com.djrapitops.plan.data.time.WorldTimes;
|
||||
import com.djrapitops.plan.system.database.databases.Database;
|
||||
import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||
import com.djrapitops.plan.system.info.server.ServerProperties;
|
||||
import com.djrapitops.plan.system.info.server.properties.ServerProperties;
|
||||
import com.djrapitops.plan.system.settings.Settings;
|
||||
import com.djrapitops.plan.system.settings.theme.Theme;
|
||||
import com.djrapitops.plan.system.settings.theme.ThemeVal;
|
||||
|
@ -9,6 +9,8 @@ import com.djrapitops.plan.api.exceptions.EnableException;
|
||||
import com.djrapitops.plan.api.exceptions.database.DBOpException;
|
||||
import com.djrapitops.plan.system.database.databases.Database;
|
||||
import com.djrapitops.plan.system.file.FileSystem;
|
||||
import com.djrapitops.plan.system.info.server.properties.BukkitServerProperties;
|
||||
import com.djrapitops.plan.system.info.server.properties.ServerProperties;
|
||||
import com.djrapitops.plan.system.settings.Settings;
|
||||
import com.djrapitops.plan.system.webserver.WebServerSystem;
|
||||
|
||||
@ -29,7 +31,7 @@ public class BukkitServerInfo extends ServerInfo {
|
||||
private Database database;
|
||||
|
||||
public BukkitServerInfo(Plan plugin) {
|
||||
this(new ServerProperties(plugin.getServer()));
|
||||
this(new BukkitServerProperties(plugin.getServer()));
|
||||
}
|
||||
|
||||
public BukkitServerInfo(ServerProperties serverProperties) {
|
||||
|
@ -8,6 +8,8 @@ import com.djrapitops.plan.PlanBungee;
|
||||
import com.djrapitops.plan.api.exceptions.EnableException;
|
||||
import com.djrapitops.plan.api.exceptions.database.DBOpException;
|
||||
import com.djrapitops.plan.system.database.databases.Database;
|
||||
import com.djrapitops.plan.system.info.server.properties.BungeeServerProperties;
|
||||
import com.djrapitops.plan.system.info.server.properties.ServerProperties;
|
||||
import com.djrapitops.plan.system.webserver.WebServerSystem;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
|
||||
@ -22,7 +24,7 @@ import java.util.UUID;
|
||||
public class BungeeServerInfo extends ServerInfo {
|
||||
|
||||
public BungeeServerInfo(PlanBungee plugin) {
|
||||
super(new ServerProperties(plugin.getProxy()));
|
||||
super(new BungeeServerProperties(plugin.getProxy()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -7,6 +7,7 @@ package com.djrapitops.plan.system.info.server;
|
||||
import com.djrapitops.plan.api.exceptions.EnableException;
|
||||
import com.djrapitops.plan.system.PlanSystem;
|
||||
import com.djrapitops.plan.system.SubSystem;
|
||||
import com.djrapitops.plan.system.info.server.properties.ServerProperties;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
|
||||
import java.util.UUID;
|
||||
|
@ -1,10 +1,11 @@
|
||||
package com.djrapitops.plan.system.info.server;
|
||||
|
||||
import com.djrapitops.plan.system.info.server.properties.SpongeServerProperties;
|
||||
import org.spongepowered.api.Sponge;
|
||||
|
||||
public class SpongeServerInfo extends BukkitServerInfo {
|
||||
|
||||
public SpongeServerInfo() {
|
||||
super(new ServerProperties(Sponge.getGame()));
|
||||
super(new SpongeServerProperties(Sponge.getGame()));
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,25 @@
|
||||
package com.djrapitops.plan.system.info.server.properties;
|
||||
|
||||
import org.bukkit.Server;
|
||||
|
||||
/**
|
||||
* ServerProperties for Bukkit.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class BukkitServerProperties extends ServerProperties {
|
||||
|
||||
public BukkitServerProperties(Server server) {
|
||||
super(
|
||||
server.getServerId(),
|
||||
server.getName(),
|
||||
server.getPort(),
|
||||
server.getVersion(),
|
||||
server.getBukkitVersion(),
|
||||
server::getIp,
|
||||
server.getMaxPlayers(),
|
||||
() -> server.getOnlinePlayers().size()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package com.djrapitops.plan.system.info.server.properties;
|
||||
|
||||
import com.djrapitops.plan.system.settings.Settings;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
|
||||
/**
|
||||
* ServerProperties for Bungee.
|
||||
* <p>
|
||||
* Supports RedisBungee for Players online getting.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class BungeeServerProperties extends ServerProperties {
|
||||
|
||||
public BungeeServerProperties(ProxyServer server) {
|
||||
super(
|
||||
server.getServers().toString(),
|
||||
"BungeeCord",
|
||||
-1,
|
||||
server.getVersion(),
|
||||
server.getVersion(),
|
||||
Settings.BUNGEE_IP::toString,
|
||||
server.getConfig().getPlayerLimit(),
|
||||
RedisCheck.isClassAvailable() ? new RedisPlayersOnlineSupplier() : server::getOnlineCount
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package com.djrapitops.plan.system.info.server.properties;
|
||||
|
||||
/**
|
||||
* Utility class for checking if RedisBungee API is available.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class RedisCheck {
|
||||
|
||||
public static boolean isClassAvailable() {
|
||||
try {
|
||||
Class.forName("com.imaginarycode.minecraft.redisbungee.RedisBungeeAPI");
|
||||
return true;
|
||||
} catch (ClassNotFoundException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.djrapitops.plan.system.info.server.properties;
|
||||
|
||||
import com.imaginarycode.minecraft.redisbungee.RedisBungee;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* Players online supplier when using RedisBungee.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class RedisPlayersOnlineSupplier implements Supplier<Integer> {
|
||||
|
||||
@Override
|
||||
public Integer get() {
|
||||
return RedisBungee.getApi().getPlayerCount();
|
||||
}
|
||||
}
|
@ -1,8 +1,5 @@
|
||||
package com.djrapitops.plan.system.info.server;
|
||||
package com.djrapitops.plan.system.info.server.properties;
|
||||
|
||||
import com.djrapitops.plan.system.settings.Settings;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import org.bukkit.Server;
|
||||
import org.spongepowered.api.Game;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
@ -15,7 +12,7 @@ import java.util.function.Supplier;
|
||||
* @author Rsl1122
|
||||
* @since 3.4.1
|
||||
*/
|
||||
public class ServerProperties {
|
||||
public abstract class ServerProperties {
|
||||
|
||||
private final String id;
|
||||
private final String name;
|
||||
@ -27,30 +24,18 @@ public class ServerProperties {
|
||||
|
||||
private final Supplier<Integer> onlinePlayers;
|
||||
|
||||
public ServerProperties(Server server) {
|
||||
id = server.getServerId();
|
||||
ip = server::getIp;
|
||||
name = server.getName();
|
||||
port = server.getPort();
|
||||
version = server.getVersion();
|
||||
implVersion = server.getBukkitVersion();
|
||||
|
||||
maxPlayers = server.getMaxPlayers();
|
||||
|
||||
onlinePlayers = () -> server.getOnlinePlayers().size();
|
||||
}
|
||||
|
||||
public ServerProperties(ProxyServer server) {
|
||||
id = server.getServers().toString();
|
||||
ip = Settings.BUNGEE_IP::toString;
|
||||
name = "BungeeCord";
|
||||
port = -1;
|
||||
version = server.getVersion();
|
||||
implVersion = server.getVersion();
|
||||
|
||||
maxPlayers = server.getConfig().getPlayerLimit();
|
||||
|
||||
onlinePlayers = server::getOnlineCount;
|
||||
protected ServerProperties(
|
||||
String id, String name, int port,
|
||||
String version, String implVersion,
|
||||
Supplier<String> ip, int maxPlayers, Supplier<Integer> onlinePlayers) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.port = port;
|
||||
this.version = version;
|
||||
this.implVersion = implVersion;
|
||||
this.ip = ip;
|
||||
this.maxPlayers = maxPlayers;
|
||||
this.onlinePlayers = onlinePlayers;
|
||||
}
|
||||
|
||||
public ServerProperties(Game game) {
|
@ -0,0 +1,28 @@
|
||||
package com.djrapitops.plan.system.info.server.properties;
|
||||
|
||||
import org.spongepowered.api.Game;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
/**
|
||||
* ServerProperties for Sponge.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class SpongeServerProperties extends ServerProperties {
|
||||
|
||||
public SpongeServerProperties(Game game) {
|
||||
super(
|
||||
game.getServer().getMotd().toPlain(),
|
||||
"Sponge",
|
||||
game.getServer().getBoundAddress().orElseGet(() -> new InetSocketAddress(25565)).getPort(),
|
||||
game.getPlatform().getMinecraftVersion().getName(),
|
||||
game.getPlatform().getMinecraftVersion().getName(),
|
||||
() -> game.getServer().getBoundAddress()
|
||||
.orElseGet(() -> new InetSocketAddress(25565))
|
||||
.getAddress().getHostAddress(),
|
||||
game.getServer().getMaxPlayers(),
|
||||
() -> game.getServer().getOnlinePlayers().size()
|
||||
);
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@ package com.djrapitops.plan.system.tasks.bungee;
|
||||
import com.djrapitops.plan.PlanBungee;
|
||||
import com.djrapitops.plan.data.container.TPS;
|
||||
import com.djrapitops.plan.data.container.builders.TPSBuilder;
|
||||
import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||
import com.djrapitops.plan.system.tasks.TPSCountTimer;
|
||||
|
||||
public class BungeeTPSCountTimer extends TPSCountTimer<PlanBungee> {
|
||||
@ -13,7 +14,7 @@ public class BungeeTPSCountTimer extends TPSCountTimer<PlanBungee> {
|
||||
|
||||
@Override
|
||||
public void addNewTPSEntry(long nanoTime, long now) {
|
||||
int onlineCount = plugin.getProxy().getOnlineCount();
|
||||
int onlineCount = ServerInfo.getServerProperties().getOnlinePlayers();
|
||||
TPS tps = TPSBuilder.get()
|
||||
.date(now)
|
||||
.skipTPS()
|
||||
|
@ -13,7 +13,7 @@ import com.djrapitops.plan.system.info.connection.ConnectionLog;
|
||||
import com.djrapitops.plan.system.info.connection.ConnectionSystem;
|
||||
import com.djrapitops.plan.system.info.server.Server;
|
||||
import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||
import com.djrapitops.plan.system.info.server.ServerProperties;
|
||||
import com.djrapitops.plan.system.info.server.properties.ServerProperties;
|
||||
import com.djrapitops.plan.system.webserver.response.errors.ErrorResponse;
|
||||
import com.djrapitops.plan.utilities.file.FileUtil;
|
||||
import com.djrapitops.plan.utilities.html.Html;
|
||||
|
@ -8,7 +8,7 @@ import com.djrapitops.plan.api.exceptions.database.DBOpException;
|
||||
import com.djrapitops.plan.system.database.databases.Database;
|
||||
import com.djrapitops.plan.system.info.server.Server;
|
||||
import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||
import com.djrapitops.plan.system.info.server.ServerProperties;
|
||||
import com.djrapitops.plan.system.info.server.properties.ServerProperties;
|
||||
import com.djrapitops.plan.utilities.FormatUtils;
|
||||
import com.djrapitops.plan.utilities.html.graphs.line.OnlineActivityGraph;
|
||||
import com.djrapitops.plan.utilities.html.icon.Color;
|
||||
|
Loading…
Reference in New Issue
Block a user