diff --git a/Plan/src/main/java/com/djrapitops/plan/PlanBungee.java b/Plan/src/main/java/com/djrapitops/plan/PlanBungee.java index 577a09ca4..3dcd7db97 100644 --- a/Plan/src/main/java/com/djrapitops/plan/PlanBungee.java +++ b/Plan/src/main/java/com/djrapitops/plan/PlanBungee.java @@ -7,15 +7,11 @@ package com.djrapitops.plan; import com.djrapitops.plan.api.exceptions.EnableException; import com.djrapitops.plan.command.PlanBungeeCommand; import com.djrapitops.plan.modules.APFModule; -import com.djrapitops.plan.modules.bungee.BungeeAPIModule; -import com.djrapitops.plan.modules.bungee.BungeeConfigModule; -import com.djrapitops.plan.modules.bungee.BungeeDatabaseModule; -import com.djrapitops.plan.modules.bungee.BungeeInfoModule; +import com.djrapitops.plan.modules.bungee.*; import com.djrapitops.plan.modules.common.ExportModule; import com.djrapitops.plan.modules.common.LocaleModule; import com.djrapitops.plan.modules.common.PluginHookModule; import com.djrapitops.plan.modules.common.VersionCheckModule; -import com.djrapitops.plan.modules.server.ServerInfoSystemModule; import com.djrapitops.plan.system.BungeeSystem; import com.djrapitops.plan.system.locale.Locale; import com.djrapitops.plan.system.locale.lang.PluginLang; @@ -34,10 +30,8 @@ import dagger.Module; import dagger.Provides; import javax.inject.Named; -import javax.inject.Singleton; import java.io.InputStream; -@Singleton @Component(modules = { BungeePlanModule.class, APFModule.class, @@ -45,9 +39,9 @@ import java.io.InputStream; VersionCheckModule.class, BungeeConfigModule.class, LocaleModule.class, + BungeeInfoSystemModule.class, BungeeInfoModule.class, BungeeDatabaseModule.class, - ServerInfoSystemModule.class, PluginHookModule.class, BungeeAPIModule.class }) @@ -60,7 +54,6 @@ interface PlanBungeeComponent { @Component.Builder interface Builder { - @Singleton @BindsInstance Builder plan(PlanBungee plan); diff --git a/Plan/src/main/java/com/djrapitops/plan/modules/bungee/BungeeInfoModule.java b/Plan/src/main/java/com/djrapitops/plan/modules/bungee/BungeeInfoModule.java index 8117c3a9a..59fc60ac7 100644 --- a/Plan/src/main/java/com/djrapitops/plan/modules/bungee/BungeeInfoModule.java +++ b/Plan/src/main/java/com/djrapitops/plan/modules/bungee/BungeeInfoModule.java @@ -1,6 +1,8 @@ package com.djrapitops.plan.modules.bungee; import com.djrapitops.plan.PlanBungee; +import com.djrapitops.plan.system.info.server.BungeeServerInfo; +import com.djrapitops.plan.system.info.server.ServerInfo; import com.djrapitops.plan.system.info.server.properties.BungeeServerProperties; import com.djrapitops.plan.system.info.server.properties.ServerProperties; import dagger.Module; @@ -14,6 +16,11 @@ import dagger.Provides; @Module public class BungeeInfoModule { + @Provides + ServerInfo provideBungeeServerInfo(BungeeServerInfo bungeeServerInfo) { + return bungeeServerInfo; + } + @Provides ServerProperties provideServerProperties(PlanBungee plugin) { return new BungeeServerProperties(plugin.getProxy()); diff --git a/Plan/src/main/java/com/djrapitops/plan/modules/bungee/BungeeInfoSystemModule.java b/Plan/src/main/java/com/djrapitops/plan/modules/bungee/BungeeInfoSystemModule.java new file mode 100644 index 000000000..507395057 --- /dev/null +++ b/Plan/src/main/java/com/djrapitops/plan/modules/bungee/BungeeInfoSystemModule.java @@ -0,0 +1,32 @@ +package com.djrapitops.plan.modules.bungee; + +import com.djrapitops.plan.system.info.BungeeInfoSystem; +import com.djrapitops.plan.system.info.InfoSystem; +import com.djrapitops.plan.system.info.connection.BungeeConnectionSystem; +import com.djrapitops.plan.system.info.connection.ConnectionSystem; +import dagger.Module; +import dagger.Provides; + +import javax.inject.Singleton; + +/** + * Dagger module for InfoSystem. + * + * @author Rsl1122 + */ +@Module +public class BungeeInfoSystemModule { + + @Provides + @Singleton + InfoSystem provideBungeeInfoSystem(BungeeInfoSystem bungeeInfoSystem) { + return bungeeInfoSystem; + } + + @Provides + @Singleton + ConnectionSystem provideBungeeConnectionSystem(BungeeConnectionSystem bungeeConnectionSystem) { + return bungeeConnectionSystem; + } + +} \ No newline at end of file diff --git a/Plan/src/main/java/com/djrapitops/plan/system/BungeeSystem.java b/Plan/src/main/java/com/djrapitops/plan/system/BungeeSystem.java index 4708af47e..06e4890af 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/BungeeSystem.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/BungeeSystem.java @@ -12,8 +12,8 @@ import com.djrapitops.plan.system.cache.BungeeCacheSystem; import com.djrapitops.plan.system.database.DBSystem; import com.djrapitops.plan.system.export.ExportSystem; import com.djrapitops.plan.system.file.FileSystem; -import com.djrapitops.plan.system.info.BungeeInfoSystem; -import com.djrapitops.plan.system.info.server.BungeeServerInfo; +import com.djrapitops.plan.system.info.InfoSystem; +import com.djrapitops.plan.system.info.server.ServerInfo; import com.djrapitops.plan.system.listeners.BungeeListenerSystem; import com.djrapitops.plan.system.settings.config.BungeeConfigSystem; import com.djrapitops.plan.system.settings.network.NetworkSettings; @@ -31,17 +31,19 @@ import javax.inject.Inject; public class BungeeSystem extends PlanSystem { @Inject - public BungeeSystem(PlanBungee plugin, - VersionCheckSystem versionCheckSystem, - FileSystem fileSystem, - BungeeConfigSystem bungeeConfigSystem, - BungeeServerInfo bungeeServerInfo, - BungeeCacheSystem bungeeCacheSystem, - DBSystem databaseSystem, - WebServerSystem webServerSystem, - HookHandler hookHandler, - ExportSystem exportSystem, - PlanAPI planAPI + public BungeeSystem( + PlanBungee plugin, + VersionCheckSystem versionCheckSystem, + FileSystem fileSystem, + BungeeConfigSystem bungeeConfigSystem, + InfoSystem infoSystem, + ServerInfo serverInfo, + BungeeCacheSystem bungeeCacheSystem, + DBSystem databaseSystem, + WebServerSystem webServerSystem, + HookHandler hookHandler, + ExportSystem exportSystem, + PlanAPI planAPI ) { super(webServerSystem); setTestSystem(this); @@ -55,8 +57,8 @@ public class BungeeSystem extends PlanSystem { listenerSystem = new BungeeListenerSystem(plugin); taskSystem = new BungeeTaskSystem(plugin.getRunnableFactory()); - infoSystem = new BungeeInfoSystem(); - serverInfo = bungeeServerInfo; + this.infoSystem = infoSystem; + this.serverInfo = serverInfo; this.hookHandler = hookHandler; this.planAPI = planAPI; diff --git a/Plan/src/main/java/com/djrapitops/plan/system/info/BungeeInfoSystem.java b/Plan/src/main/java/com/djrapitops/plan/system/info/BungeeInfoSystem.java index 44afb67d5..9537f7239 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/info/BungeeInfoSystem.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/info/BungeeInfoSystem.java @@ -7,7 +7,7 @@ package com.djrapitops.plan.system.info; import com.djrapitops.plan.api.exceptions.ParseException; import com.djrapitops.plan.api.exceptions.connection.NoServersException; import com.djrapitops.plan.api.exceptions.connection.WebException; -import com.djrapitops.plan.system.info.connection.BungeeConnectionSystem; +import com.djrapitops.plan.system.info.connection.ConnectionSystem; import com.djrapitops.plan.system.info.request.CacheRequest; import com.djrapitops.plan.system.info.request.GenerateInspectPageRequest; import com.djrapitops.plan.system.info.request.InfoRequest; @@ -17,6 +17,8 @@ import com.djrapitops.plan.system.webserver.cache.ResponseCache; import com.djrapitops.plan.system.webserver.response.errors.InternalErrorResponse; import com.djrapitops.plan.system.webserver.response.pages.NetworkPageResponse; +import javax.inject.Inject; + /** * InfoSystem for Bungee. * @@ -24,8 +26,13 @@ import com.djrapitops.plan.system.webserver.response.pages.NetworkPageResponse; */ public class BungeeInfoSystem extends InfoSystem { - public BungeeInfoSystem() { - super(new BungeeConnectionSystem()); + private final ServerInfo serverInfo; + + @Inject + public BungeeInfoSystem(ConnectionSystem connectionSystem, ServerInfo serverInfo) { + super(connectionSystem); + + this.serverInfo = serverInfo; } @Override @@ -41,7 +48,7 @@ public class BungeeInfoSystem extends InfoSystem { @Override public void updateNetworkPage() { - ResponseCache.cacheResponse(PageId.SERVER.of(ServerInfo.getServerUUID_Old()), () -> { + ResponseCache.cacheResponse(PageId.SERVER.of(serverInfo.getServerUUID()), () -> { try { return new NetworkPageResponse(); } catch (ParseException e) { diff --git a/Plan/src/main/java/com/djrapitops/plan/system/info/connection/BungeeConnectionSystem.java b/Plan/src/main/java/com/djrapitops/plan/system/info/connection/BungeeConnectionSystem.java index 58823e08f..03c995492 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/info/connection/BungeeConnectionSystem.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/info/connection/BungeeConnectionSystem.java @@ -10,10 +10,12 @@ import com.djrapitops.plan.system.database.databases.Database; import com.djrapitops.plan.system.info.request.*; import com.djrapitops.plan.system.info.server.Server; import com.djrapitops.plan.system.info.server.ServerInfo; -import com.djrapitops.plan.system.webserver.WebServerSystem; +import com.djrapitops.plan.system.webserver.WebServer; import com.djrapitops.plugin.api.TimeAmount; -import com.djrapitops.plugin.api.utility.log.Log; +import com.djrapitops.plugin.logging.L; +import com.djrapitops.plugin.logging.error.ErrorHandler; +import javax.inject.Inject; import java.util.UUID; /** @@ -23,19 +25,35 @@ import java.util.UUID; */ public class BungeeConnectionSystem extends ConnectionSystem { + private final Database database; + private final ServerInfo serverInfo; + private final WebServer webServer; + private ErrorHandler errorHandler; + private long latestServerMapRefresh; - public BungeeConnectionSystem() { + @Inject + public BungeeConnectionSystem( + Database database, + ServerInfo serverInfo, + WebServer webServer, + ErrorHandler errorHandler + ) { + this.database = database; + this.serverInfo = serverInfo; + this.webServer = webServer; + this.errorHandler = errorHandler; + latestServerMapRefresh = 0; } private void refreshServerMap() { if (latestServerMapRefresh < System.currentTimeMillis() - TimeAmount.SECOND.ms() * 15L) { try { - bukkitServers = Database.getActive().fetch().getBukkitServers(); + bukkitServers = database.fetch().getBukkitServers(); latestServerMapRefresh = System.currentTimeMillis(); } catch (DBOpException e) { - Log.toLog(this.getClass(), e); + errorHandler.log(L.ERROR, this.getClass(), e); } } } @@ -46,7 +64,7 @@ public class BungeeConnectionSystem extends ConnectionSystem { Server server = null; if (infoRequest instanceof CacheRequest || infoRequest instanceof GenerateInspectPageRequest) { // Run locally - return ServerInfo.getServer_Old(); + return serverInfo.getServer(); } else if (infoRequest instanceof GenerateAnalysisPageRequest) { UUID serverUUID = ((GenerateAnalysisPageRequest) infoRequest).getServerUUID(); server = bukkitServers.get(serverUUID); @@ -75,7 +93,7 @@ public class BungeeConnectionSystem extends ConnectionSystem { @Override public String getMainAddress() { - return WebServerSystem.getInstance().getWebServer().getAccessAddress(); + return webServer.getAccessAddress(); } @Override