From 8da9dc643b4dca95b2f285c7e2706d7448c159b5 Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Wed, 8 Aug 2018 21:12:42 +0300 Subject: [PATCH] Added RedisBungee online count #642, split ServerProperties to 3 classes --- Plan/dependency-reduced-pom.xml | 10 +++++ Plan/pom.xml | 13 ++++++ .../store/containers/AnalysisContainer.java | 2 +- .../system/info/server/BukkitServerInfo.java | 4 +- .../system/info/server/BungeeServerInfo.java | 4 +- .../plan/system/info/server/ServerInfo.java | 1 + .../system/info/server/SpongeServerInfo.java | 3 +- .../properties/BukkitServerProperties.java | 25 +++++++++++ .../properties/BungeeServerProperties.java | 27 ++++++++++++ .../info/server/properties/RedisCheck.java | 19 ++++++++ .../RedisPlayersOnlineSupplier.java | 18 ++++++++ .../{ => properties}/ServerProperties.java | 43 ++++++------------- .../properties/SpongeServerProperties.java | 28 ++++++++++++ .../tasks/bungee/BungeeTPSCountTimer.java | 3 +- .../response/pages/DebugPageResponse.java | 2 +- .../plan/utilities/html/HtmlStructure.java | 2 +- 16 files changed, 168 insertions(+), 36 deletions(-) create mode 100644 Plan/src/main/java/com/djrapitops/plan/system/info/server/properties/BukkitServerProperties.java create mode 100644 Plan/src/main/java/com/djrapitops/plan/system/info/server/properties/BungeeServerProperties.java create mode 100644 Plan/src/main/java/com/djrapitops/plan/system/info/server/properties/RedisCheck.java create mode 100644 Plan/src/main/java/com/djrapitops/plan/system/info/server/properties/RedisPlayersOnlineSupplier.java rename Plan/src/main/java/com/djrapitops/plan/system/info/server/{ => properties}/ServerProperties.java (66%) create mode 100644 Plan/src/main/java/com/djrapitops/plan/system/info/server/properties/SpongeServerProperties.java diff --git a/Plan/dependency-reduced-pom.xml b/Plan/dependency-reduced-pom.xml index 67d6f5663..39b5c60d5 100644 --- a/Plan/dependency-reduced-pom.xml +++ b/Plan/dependency-reduced-pom.xml @@ -145,6 +145,10 @@ sponge-repo https://repo.spongepowered.org/maven + + md_5-releases + http://repo.md-5.net/content/repositories/releases/ + @@ -347,6 +351,12 @@ + + com.imaginarycode.minecraft + RedisBungee + RELEASE + provided + org.mockito mockito-core diff --git a/Plan/pom.xml b/Plan/pom.xml index ef6bcd10b..a6ade7375 100644 --- a/Plan/pom.xml +++ b/Plan/pom.xml @@ -24,6 +24,11 @@ sponge-repo https://repo.spongepowered.org/maven + + + md_5-releases + http://repo.md-5.net/content/repositories/releases/ + @@ -77,6 +82,14 @@ jar provided + + + com.imaginarycode.minecraft + RedisBungee + RELEASE + jar + provided + diff --git a/Plan/src/main/java/com/djrapitops/plan/data/store/containers/AnalysisContainer.java b/Plan/src/main/java/com/djrapitops/plan/data/store/containers/AnalysisContainer.java index 0396fff06..be17d6d9b 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/store/containers/AnalysisContainer.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/store/containers/AnalysisContainer.java @@ -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; diff --git a/Plan/src/main/java/com/djrapitops/plan/system/info/server/BukkitServerInfo.java b/Plan/src/main/java/com/djrapitops/plan/system/info/server/BukkitServerInfo.java index 7353f347a..0984066f9 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/info/server/BukkitServerInfo.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/info/server/BukkitServerInfo.java @@ -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) { diff --git a/Plan/src/main/java/com/djrapitops/plan/system/info/server/BungeeServerInfo.java b/Plan/src/main/java/com/djrapitops/plan/system/info/server/BungeeServerInfo.java index c98fa570a..c0658b8fa 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/info/server/BungeeServerInfo.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/info/server/BungeeServerInfo.java @@ -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 diff --git a/Plan/src/main/java/com/djrapitops/plan/system/info/server/ServerInfo.java b/Plan/src/main/java/com/djrapitops/plan/system/info/server/ServerInfo.java index c12522cb7..9ba36b991 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/info/server/ServerInfo.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/info/server/ServerInfo.java @@ -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; diff --git a/Plan/src/main/java/com/djrapitops/plan/system/info/server/SpongeServerInfo.java b/Plan/src/main/java/com/djrapitops/plan/system/info/server/SpongeServerInfo.java index 0368e6073..b82b09321 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/info/server/SpongeServerInfo.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/info/server/SpongeServerInfo.java @@ -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())); } } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/info/server/properties/BukkitServerProperties.java b/Plan/src/main/java/com/djrapitops/plan/system/info/server/properties/BukkitServerProperties.java new file mode 100644 index 000000000..8f664a9ae --- /dev/null +++ b/Plan/src/main/java/com/djrapitops/plan/system/info/server/properties/BukkitServerProperties.java @@ -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() + ); + } + +} \ No newline at end of file diff --git a/Plan/src/main/java/com/djrapitops/plan/system/info/server/properties/BungeeServerProperties.java b/Plan/src/main/java/com/djrapitops/plan/system/info/server/properties/BungeeServerProperties.java new file mode 100644 index 000000000..4f6c2cc39 --- /dev/null +++ b/Plan/src/main/java/com/djrapitops/plan/system/info/server/properties/BungeeServerProperties.java @@ -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. + *

+ * 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 + ); + } +} \ No newline at end of file diff --git a/Plan/src/main/java/com/djrapitops/plan/system/info/server/properties/RedisCheck.java b/Plan/src/main/java/com/djrapitops/plan/system/info/server/properties/RedisCheck.java new file mode 100644 index 000000000..d25fc7a0b --- /dev/null +++ b/Plan/src/main/java/com/djrapitops/plan/system/info/server/properties/RedisCheck.java @@ -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; + } + } + +} \ No newline at end of file diff --git a/Plan/src/main/java/com/djrapitops/plan/system/info/server/properties/RedisPlayersOnlineSupplier.java b/Plan/src/main/java/com/djrapitops/plan/system/info/server/properties/RedisPlayersOnlineSupplier.java new file mode 100644 index 000000000..1d3a2f28a --- /dev/null +++ b/Plan/src/main/java/com/djrapitops/plan/system/info/server/properties/RedisPlayersOnlineSupplier.java @@ -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 { + + @Override + public Integer get() { + return RedisBungee.getApi().getPlayerCount(); + } +} \ No newline at end of file diff --git a/Plan/src/main/java/com/djrapitops/plan/system/info/server/ServerProperties.java b/Plan/src/main/java/com/djrapitops/plan/system/info/server/properties/ServerProperties.java similarity index 66% rename from Plan/src/main/java/com/djrapitops/plan/system/info/server/ServerProperties.java rename to Plan/src/main/java/com/djrapitops/plan/system/info/server/properties/ServerProperties.java index 497663815..cd58e2f7b 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/info/server/ServerProperties.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/info/server/properties/ServerProperties.java @@ -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 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 ip, int maxPlayers, Supplier 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) { diff --git a/Plan/src/main/java/com/djrapitops/plan/system/info/server/properties/SpongeServerProperties.java b/Plan/src/main/java/com/djrapitops/plan/system/info/server/properties/SpongeServerProperties.java new file mode 100644 index 000000000..1e9a4121b --- /dev/null +++ b/Plan/src/main/java/com/djrapitops/plan/system/info/server/properties/SpongeServerProperties.java @@ -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() + ); + } +} \ No newline at end of file diff --git a/Plan/src/main/java/com/djrapitops/plan/system/tasks/bungee/BungeeTPSCountTimer.java b/Plan/src/main/java/com/djrapitops/plan/system/tasks/bungee/BungeeTPSCountTimer.java index 058ca284e..2d5edb328 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/tasks/bungee/BungeeTPSCountTimer.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/tasks/bungee/BungeeTPSCountTimer.java @@ -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 { @@ -13,7 +14,7 @@ public class BungeeTPSCountTimer extends TPSCountTimer { @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() diff --git a/Plan/src/main/java/com/djrapitops/plan/system/webserver/response/pages/DebugPageResponse.java b/Plan/src/main/java/com/djrapitops/plan/system/webserver/response/pages/DebugPageResponse.java index b31b49cb0..6da1cfb01 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/webserver/response/pages/DebugPageResponse.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/webserver/response/pages/DebugPageResponse.java @@ -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; diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/html/HtmlStructure.java b/Plan/src/main/java/com/djrapitops/plan/utilities/html/HtmlStructure.java index 82206c59b..c787fb606 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/html/HtmlStructure.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/html/HtmlStructure.java @@ -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;