From c6b9058bb0fc9ab679826564ff05e0778aecf709 Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Thu, 23 Aug 2018 09:49:17 +0300 Subject: [PATCH] Tasks, BungeeTaskSystem initialized by Dagger --- .../java/com/djrapitops/plan/PlanBungee.java | 3 ++ .../modules/bungee/BungeeDataCacheModule.java | 27 ++++++++++++++ .../server/bukkit/BukkitInfoModule.java | 7 ++++ .../server/sponge/SpongeInfoModule.java | 7 ++++ .../djrapitops/plan/system/BungeeSystem.java | 7 ++-- .../plan/system/info/InfoSystem.java | 1 + .../listeners/BungeeListenerSystem.java | 9 +++-- .../bungee/PlayerOnlineListener.java | 35 ++++++++++++++----- .../plan/system/tasks/BukkitTaskSystem.java | 30 +++++++++++----- .../plan/system/tasks/BungeeTaskSystem.java | 22 +++++++++--- .../plan/system/tasks/ServerTaskSystem.java | 34 +++++++++++------- .../plan/system/tasks/SpongeTaskSystem.java | 23 ++++++++++-- .../plan/system/tasks/TPSCountTimer.java | 15 +++++--- .../tasks/bungee/BungeeTPSCountTimer.java | 20 +++++++++-- .../tasks/bungee/EnableConnectionTask.java | 11 +++++- .../system/tasks/server/BootAnalysisTask.java | 18 ++++++++-- .../tasks/server/BukkitTPSCountTimer.java | 18 ++++++++-- .../tasks/server/NetworkPageRefreshTask.java | 11 +++++- .../tasks/server/PaperTPSCountTimer.java | 15 ++++++-- .../tasks/server/PeriodicAnalysisTask.java | 32 ++++++++++++++--- .../system/tasks/server/PingCountTimer.java | 10 ++++-- .../tasks/server/SpongeTPSCountTimer.java | 15 +++++--- 22 files changed, 300 insertions(+), 70 deletions(-) create mode 100644 Plan/src/main/java/com/djrapitops/plan/modules/bungee/BungeeDataCacheModule.java diff --git a/Plan/src/main/java/com/djrapitops/plan/PlanBungee.java b/Plan/src/main/java/com/djrapitops/plan/PlanBungee.java index 3dcd7db97..c19ccc04e 100644 --- a/Plan/src/main/java/com/djrapitops/plan/PlanBungee.java +++ b/Plan/src/main/java/com/djrapitops/plan/PlanBungee.java @@ -30,8 +30,10 @@ 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, @@ -41,6 +43,7 @@ import java.io.InputStream; LocaleModule.class, BungeeInfoSystemModule.class, BungeeInfoModule.class, + BungeeDataCacheModule.class, BungeeDatabaseModule.class, PluginHookModule.class, BungeeAPIModule.class diff --git a/Plan/src/main/java/com/djrapitops/plan/modules/bungee/BungeeDataCacheModule.java b/Plan/src/main/java/com/djrapitops/plan/modules/bungee/BungeeDataCacheModule.java new file mode 100644 index 000000000..ffc8d4f6e --- /dev/null +++ b/Plan/src/main/java/com/djrapitops/plan/modules/bungee/BungeeDataCacheModule.java @@ -0,0 +1,27 @@ +package com.djrapitops.plan.modules.bungee; + +import com.djrapitops.plan.system.cache.BungeeDataCache; +import com.djrapitops.plan.system.cache.DataCache; +import com.djrapitops.plan.system.cache.SessionCache; +import dagger.Module; +import dagger.Provides; + +/** + * Dagger module for Server CacheSystem. + * + * @author Rsl1122 + */ +@Module +public class BungeeDataCacheModule { + + @Provides + DataCache provideDataCache(BungeeDataCache bungeeDataCache) { + return bungeeDataCache; + } + + @Provides + SessionCache provideSessionCache(DataCache cache) { + return cache; + } + +} \ No newline at end of file diff --git a/Plan/src/main/java/com/djrapitops/plan/modules/server/bukkit/BukkitInfoModule.java b/Plan/src/main/java/com/djrapitops/plan/modules/server/bukkit/BukkitInfoModule.java index e3196266e..6b0814896 100644 --- a/Plan/src/main/java/com/djrapitops/plan/modules/server/bukkit/BukkitInfoModule.java +++ b/Plan/src/main/java/com/djrapitops/plan/modules/server/bukkit/BukkitInfoModule.java @@ -1,6 +1,8 @@ package com.djrapitops.plan.modules.server.bukkit; import com.djrapitops.plan.Plan; +import com.djrapitops.plan.system.info.server.BukkitServerInfo; +import com.djrapitops.plan.system.info.server.ServerInfo; import com.djrapitops.plan.system.info.server.properties.BukkitServerProperties; import com.djrapitops.plan.system.info.server.properties.ServerProperties; import dagger.Module; @@ -14,6 +16,11 @@ import dagger.Provides; @Module public class BukkitInfoModule { + @Provides + ServerInfo provideBukkitServerInfo(BukkitServerInfo bukkitServerInfo) { + return bukkitServerInfo; + } + @Provides ServerProperties provideServerProperties(Plan plugin) { return new BukkitServerProperties(plugin.getServer()); diff --git a/Plan/src/main/java/com/djrapitops/plan/modules/server/sponge/SpongeInfoModule.java b/Plan/src/main/java/com/djrapitops/plan/modules/server/sponge/SpongeInfoModule.java index b02eae5e7..3bf79eb3c 100644 --- a/Plan/src/main/java/com/djrapitops/plan/modules/server/sponge/SpongeInfoModule.java +++ b/Plan/src/main/java/com/djrapitops/plan/modules/server/sponge/SpongeInfoModule.java @@ -1,5 +1,7 @@ package com.djrapitops.plan.modules.server.sponge; +import com.djrapitops.plan.system.info.server.ServerInfo; +import com.djrapitops.plan.system.info.server.SpongeServerInfo; import com.djrapitops.plan.system.info.server.properties.ServerProperties; import com.djrapitops.plan.system.info.server.properties.SpongeServerProperties; import dagger.Module; @@ -14,6 +16,11 @@ import org.spongepowered.api.Sponge; @Module public class SpongeInfoModule { + @Provides + ServerInfo provideSpongeServerInfo(SpongeServerInfo spongeServerInfo) { + return spongeServerInfo; + } + @Provides ServerProperties provideServerProperties() { return new SpongeServerProperties(Sponge.getGame()); 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 06e4890af..8519b3a28 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/BungeeSystem.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/BungeeSystem.java @@ -32,7 +32,6 @@ public class BungeeSystem extends PlanSystem { @Inject public BungeeSystem( - PlanBungee plugin, VersionCheckSystem versionCheckSystem, FileSystem fileSystem, BungeeConfigSystem bungeeConfigSystem, @@ -41,6 +40,8 @@ public class BungeeSystem extends PlanSystem { BungeeCacheSystem bungeeCacheSystem, DBSystem databaseSystem, WebServerSystem webServerSystem, + BungeeListenerSystem bungeeListenerSystem, + BungeeTaskSystem bungeeTaskSystem, HookHandler hookHandler, ExportSystem exportSystem, PlanAPI planAPI @@ -54,8 +55,8 @@ public class BungeeSystem extends PlanSystem { this.exportSystem = exportSystem; this.databaseSystem = databaseSystem; cacheSystem = bungeeCacheSystem; - listenerSystem = new BungeeListenerSystem(plugin); - taskSystem = new BungeeTaskSystem(plugin.getRunnableFactory()); + listenerSystem = bungeeListenerSystem; + taskSystem = bungeeTaskSystem; this.infoSystem = infoSystem; this.serverInfo = serverInfo; diff --git a/Plan/src/main/java/com/djrapitops/plan/system/info/InfoSystem.java b/Plan/src/main/java/com/djrapitops/plan/system/info/InfoSystem.java index fc5e3efd7..644cd41b0 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/info/InfoSystem.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/info/InfoSystem.java @@ -42,6 +42,7 @@ public abstract class InfoSystem implements SubSystem { this.connectionSystem = connectionSystem; } + @Deprecated public static InfoSystem getInstance() { InfoSystem infoSystem = PlanSystem.getInstance().getInfoSystem(); Verify.nullCheck(infoSystem, () -> new IllegalStateException("Info System was not initialized.")); diff --git a/Plan/src/main/java/com/djrapitops/plan/system/listeners/BungeeListenerSystem.java b/Plan/src/main/java/com/djrapitops/plan/system/listeners/BungeeListenerSystem.java index 0b48be733..6ca8c300b 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/listeners/BungeeListenerSystem.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/listeners/BungeeListenerSystem.java @@ -3,17 +3,22 @@ package com.djrapitops.plan.system.listeners; import com.djrapitops.plan.PlanBungee; import com.djrapitops.plan.system.listeners.bungee.PlayerOnlineListener; +import javax.inject.Inject; + public class BungeeListenerSystem extends ListenerSystem { private final PlanBungee plugin; + private PlayerOnlineListener playerOnlineListener; - public BungeeListenerSystem(PlanBungee plugin) { + @Inject + public BungeeListenerSystem(PlanBungee plugin, PlayerOnlineListener playerOnlineListener) { this.plugin = plugin; + this.playerOnlineListener = playerOnlineListener; } @Override protected void registerListeners() { - plugin.registerListener(new PlayerOnlineListener()); + plugin.registerListener(playerOnlineListener); } @Override diff --git a/Plan/src/main/java/com/djrapitops/plan/system/listeners/bungee/PlayerOnlineListener.java b/Plan/src/main/java/com/djrapitops/plan/system/listeners/bungee/PlayerOnlineListener.java index 923fd3c4e..d5a2721f1 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/listeners/bungee/PlayerOnlineListener.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/listeners/bungee/PlayerOnlineListener.java @@ -13,7 +13,8 @@ import com.djrapitops.plan.system.processing.processors.player.BungeePlayerRegis import com.djrapitops.plan.system.processing.processors.player.IPUpdateProcessor; import com.djrapitops.plan.system.webserver.cache.PageId; import com.djrapitops.plan.system.webserver.cache.ResponseCache; -import com.djrapitops.plugin.api.utility.log.Log; +import com.djrapitops.plugin.logging.L; +import com.djrapitops.plugin.logging.error.ErrorHandler; import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.event.PostLoginEvent; import net.md_5.bungee.api.event.ServerDisconnectEvent; @@ -21,6 +22,7 @@ import net.md_5.bungee.api.event.ServerSwitchEvent; import net.md_5.bungee.api.plugin.Listener; import net.md_5.bungee.event.EventHandler; +import javax.inject.Inject; import java.net.InetAddress; import java.util.UUID; @@ -31,6 +33,21 @@ import java.util.UUID; */ public class PlayerOnlineListener implements Listener { + private final SessionCache sessionCache; + private final ServerInfo serverInfo; + private final ErrorHandler errorHandler; + + @Inject + public PlayerOnlineListener( + SessionCache sessionCache, + ServerInfo serverInfo, + ErrorHandler errorHandler + ) { + this.sessionCache = sessionCache; + this.serverInfo = serverInfo; + this.errorHandler = errorHandler; + } + @EventHandler public void onPostLogin(PostLoginEvent event) { try { @@ -40,15 +57,15 @@ public class PlayerOnlineListener implements Listener { InetAddress address = player.getAddress().getAddress(); long now = System.currentTimeMillis(); - SessionCache.getInstance().cacheSession(uuid, new Session(uuid, now, "", "")); + sessionCache.cacheSession(uuid, new Session(uuid, now, "", "")); Processing.submit(new BungeePlayerRegisterProcessor(uuid, name, now, new IPUpdateProcessor(uuid, address, now)) ); Processing.submit(new PlayerPageUpdateProcessor(uuid)); - ResponseCache.clearResponse(PageId.SERVER.of(ServerInfo.getServerUUID_Old())); + ResponseCache.clearResponse(PageId.SERVER.of(serverInfo.getServerUUID())); } catch (Exception e) { - Log.toLog(this.getClass(), e); + errorHandler.log(L.WARN, this.getClass(), e); } } @@ -58,11 +75,11 @@ public class PlayerOnlineListener implements Listener { ProxiedPlayer player = event.getPlayer(); UUID uuid = player.getUniqueId(); - SessionCache.getInstance().endSession(uuid, System.currentTimeMillis()); + sessionCache.endSession(uuid, System.currentTimeMillis()); Processing.submit(new PlayerPageUpdateProcessor(uuid)); - ResponseCache.clearResponse(PageId.SERVER.of(ServerInfo.getServerUUID_Old())); + ResponseCache.clearResponse(PageId.SERVER.of(serverInfo.getServerUUID())); } catch (Exception e) { - Log.toLog(this.getClass(), e); + errorHandler.log(L.WARN, this.getClass(), e); } } @@ -74,10 +91,10 @@ public class PlayerOnlineListener implements Listener { long now = System.currentTimeMillis(); // Replaces the current session in the cache. - SessionCache.getInstance().cacheSession(uuid, new Session(uuid, now, "", "")); + sessionCache.cacheSession(uuid, new Session(uuid, now, "", "")); Processing.submit(new PlayerPageUpdateProcessor(uuid)); } catch (Exception e) { - Log.toLog(this.getClass(), e); + errorHandler.log(L.WARN, this.getClass(), e); } } } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/tasks/BukkitTaskSystem.java b/Plan/src/main/java/com/djrapitops/plan/system/tasks/BukkitTaskSystem.java index b90182fcd..53ecfb28c 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/tasks/BukkitTaskSystem.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/tasks/BukkitTaskSystem.java @@ -5,9 +5,8 @@ package com.djrapitops.plan.system.tasks; import com.djrapitops.plan.Plan; -import com.djrapitops.plan.system.tasks.server.BukkitTPSCountTimer; -import com.djrapitops.plan.system.tasks.server.PaperTPSCountTimer; -import com.djrapitops.plan.system.tasks.server.PingCountTimer; +import com.djrapitops.plan.system.settings.config.PlanConfig; +import com.djrapitops.plan.system.tasks.server.*; import com.djrapitops.plugin.api.Check; import com.djrapitops.plugin.task.RunnableFactory; import org.bukkit.Bukkit; @@ -24,11 +23,25 @@ public class BukkitTaskSystem extends ServerTaskSystem { private final Plan plugin; @Inject - public BukkitTaskSystem(Plan plugin, RunnableFactory runnableFactory) { - super(runnableFactory, + public BukkitTaskSystem( + Plan plugin, + PlanConfig config, + RunnableFactory runnableFactory, + PaperTPSCountTimer paperTPSCountTimer, + BukkitTPSCountTimer bukkitTPSCountTimer, + NetworkPageRefreshTask networkPageRefreshTask, + BootAnalysisTask bootAnalysisTask, + PeriodicAnalysisTask periodicAnalysisTask + ) { + super( + runnableFactory, Check.isPaperAvailable() - ? new PaperTPSCountTimer(plugin) - : new BukkitTPSCountTimer(plugin) + ? paperTPSCountTimer + : bukkitTPSCountTimer, + config, + networkPageRefreshTask, + bootAnalysisTask, + periodicAnalysisTask ); this.plugin = plugin; } @@ -37,7 +50,8 @@ public class BukkitTaskSystem extends ServerTaskSystem { public void enable() { super.enable(); try { - PingCountTimer pingCountTimer = new PingCountTimer(); + PingCountTimer pingCountTimer = new PingCountTimer(runnableFactory); + plugin.registerListener(pingCountTimer); registerTask("PingCountTimer", pingCountTimer) .runTaskTimer(20L, PingCountTimer.PING_INTERVAL); diff --git a/Plan/src/main/java/com/djrapitops/plan/system/tasks/BungeeTaskSystem.java b/Plan/src/main/java/com/djrapitops/plan/system/tasks/BungeeTaskSystem.java index ffd516cf8..746cd39ab 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/tasks/BungeeTaskSystem.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/tasks/BungeeTaskSystem.java @@ -9,7 +9,8 @@ import com.djrapitops.plan.system.tasks.bungee.EnableConnectionTask; import com.djrapitops.plan.system.tasks.server.NetworkPageRefreshTask; import com.djrapitops.plugin.api.TimeAmount; import com.djrapitops.plugin.task.RunnableFactory; -import com.google.inject.Inject; + +import javax.inject.Inject; /** * TaskSystem responsible for registering tasks for Bungee. @@ -18,9 +19,20 @@ import com.google.inject.Inject; */ public class BungeeTaskSystem extends TaskSystem { + private final EnableConnectionTask enableConnectionTask; + private final NetworkPageRefreshTask networkPageRefreshTask; + @Inject - public BungeeTaskSystem(RunnableFactory runnableFactory) { - super(runnableFactory, new BungeeTPSCountTimer()); + public BungeeTaskSystem( + RunnableFactory runnableFactory, + BungeeTPSCountTimer bungeeTPSCountTimer, + EnableConnectionTask enableConnectionTask, + NetworkPageRefreshTask networkPageRefreshTask + ) { + super(runnableFactory, bungeeTPSCountTimer); + + this.enableConnectionTask = enableConnectionTask; + this.networkPageRefreshTask = networkPageRefreshTask; } @Override @@ -29,8 +41,8 @@ public class BungeeTaskSystem extends TaskSystem { } private void registerTasks() { - registerTask(new EnableConnectionTask()).runTaskAsynchronously(); + registerTask(enableConnectionTask).runTaskAsynchronously(); registerTask(tpsCountTimer).runTaskTimerAsynchronously(1000, TimeAmount.SECOND.ticks()); - registerTask(new NetworkPageRefreshTask()).runTaskTimerAsynchronously(1500, TimeAmount.MINUTE.ticks()); + registerTask(networkPageRefreshTask).runTaskTimerAsynchronously(1500, TimeAmount.MINUTE.ticks()); } } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/tasks/ServerTaskSystem.java b/Plan/src/main/java/com/djrapitops/plan/system/tasks/ServerTaskSystem.java index 3adba6e1e..0aefb6aea 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/tasks/ServerTaskSystem.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/tasks/ServerTaskSystem.java @@ -1,12 +1,11 @@ package com.djrapitops.plan.system.tasks; import com.djrapitops.plan.system.settings.Settings; +import com.djrapitops.plan.system.settings.config.PlanConfig; import com.djrapitops.plan.system.tasks.server.BootAnalysisTask; import com.djrapitops.plan.system.tasks.server.NetworkPageRefreshTask; import com.djrapitops.plan.system.tasks.server.PeriodicAnalysisTask; -import com.djrapitops.plugin.api.Benchmark; import com.djrapitops.plugin.api.TimeAmount; -import com.djrapitops.plugin.task.PluginTask; import com.djrapitops.plugin.task.RunnableFactory; /** @@ -14,12 +13,26 @@ import com.djrapitops.plugin.task.RunnableFactory; * * @author Rsl1122 */ -public class ServerTaskSystem extends TaskSystem { +public abstract class ServerTaskSystem extends TaskSystem { - protected PluginTask bootAnalysisTask; + private final PlanConfig config; + private final NetworkPageRefreshTask networkPageRefreshTask; + private final PeriodicAnalysisTask periodicAnalysisTask; + protected BootAnalysisTask bootAnalysisTask; - public ServerTaskSystem(RunnableFactory runnableFactory, TPSCountTimer tpsCountTimer) { + public ServerTaskSystem( + RunnableFactory runnableFactory, + TPSCountTimer tpsCountTimer, + PlanConfig config, + NetworkPageRefreshTask networkPageRefreshTask, + BootAnalysisTask bootAnalysisTask, + PeriodicAnalysisTask periodicAnalysisTask + ) { super(runnableFactory, tpsCountTimer); + this.config = config; + this.networkPageRefreshTask = networkPageRefreshTask; + this.bootAnalysisTask = bootAnalysisTask; + this.periodicAnalysisTask = periodicAnalysisTask; } @Override @@ -28,21 +41,18 @@ public class ServerTaskSystem extends TaskSystem { } private void registerTasks() { - Benchmark.start("Task Registration"); - // Analysis refresh settings - int analysisRefreshMinutes = Settings.ANALYSIS_AUTO_REFRESH.getNumber(); + int analysisRefreshMinutes = config.getNumber(Settings.ANALYSIS_AUTO_REFRESH); boolean analysisRefreshTaskIsEnabled = analysisRefreshMinutes > 0; long analysisPeriod = analysisRefreshMinutes * TimeAmount.MINUTE.ticks(); registerTask(tpsCountTimer).runTaskTimer(1000, TimeAmount.SECOND.ticks()); - registerTask(new NetworkPageRefreshTask()).runTaskTimerAsynchronously(20L, 5L * TimeAmount.MINUTE.ticks()); - bootAnalysisTask = registerTask(new BootAnalysisTask()).runTaskLaterAsynchronously(30L * TimeAmount.SECOND.ticks()); + registerTask(networkPageRefreshTask).runTaskTimerAsynchronously(20L, 5L * TimeAmount.MINUTE.ticks()); + registerTask(bootAnalysisTask).runTaskLaterAsynchronously(30L * TimeAmount.SECOND.ticks()); if (analysisRefreshTaskIsEnabled) { - registerTask(new PeriodicAnalysisTask()).runTaskTimerAsynchronously(analysisPeriod, analysisPeriod); + registerTask(periodicAnalysisTask).runTaskTimerAsynchronously(analysisPeriod, analysisPeriod); } - Benchmark.stop("Enable", "Task Registration"); } public void cancelBootAnalysis() { diff --git a/Plan/src/main/java/com/djrapitops/plan/system/tasks/SpongeTaskSystem.java b/Plan/src/main/java/com/djrapitops/plan/system/tasks/SpongeTaskSystem.java index 1b546e246..09329dc1e 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/tasks/SpongeTaskSystem.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/tasks/SpongeTaskSystem.java @@ -1,6 +1,10 @@ package com.djrapitops.plan.system.tasks; import com.djrapitops.plan.PlanSponge; +import com.djrapitops.plan.system.settings.config.PlanConfig; +import com.djrapitops.plan.system.tasks.server.BootAnalysisTask; +import com.djrapitops.plan.system.tasks.server.NetworkPageRefreshTask; +import com.djrapitops.plan.system.tasks.server.PeriodicAnalysisTask; import com.djrapitops.plan.system.tasks.server.SpongeTPSCountTimer; import com.djrapitops.plugin.task.RunnableFactory; import org.spongepowered.api.Sponge; @@ -13,8 +17,23 @@ public class SpongeTaskSystem extends ServerTaskSystem { private final PlanSponge plugin; @Inject - public SpongeTaskSystem(PlanSponge plugin, RunnableFactory runnableFactory) { - super(runnableFactory, new SpongeTPSCountTimer(plugin)); + public SpongeTaskSystem( + PlanSponge plugin, + PlanConfig config, + RunnableFactory runnableFactory, + SpongeTPSCountTimer spongeTPSCountTimer, + NetworkPageRefreshTask networkPageRefreshTask, + BootAnalysisTask bootAnalysisTask, + PeriodicAnalysisTask periodicAnalysisTask + ) { + super( + runnableFactory, + spongeTPSCountTimer, + config, + networkPageRefreshTask, + bootAnalysisTask, + periodicAnalysisTask + ); this.plugin = plugin; } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/tasks/TPSCountTimer.java b/Plan/src/main/java/com/djrapitops/plan/system/tasks/TPSCountTimer.java index 95a854b1d..954d8d4d9 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/tasks/TPSCountTimer.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/tasks/TPSCountTimer.java @@ -3,7 +3,9 @@ package com.djrapitops.plan.system.tasks; import com.djrapitops.plan.data.container.TPS; import com.djrapitops.plan.system.processing.Processing; import com.djrapitops.plan.system.processing.processors.TPSInsertProcessor; -import com.djrapitops.plugin.api.utility.log.Log; +import com.djrapitops.plugin.logging.L; +import com.djrapitops.plugin.logging.console.PluginLogger; +import com.djrapitops.plugin.logging.error.ErrorHandler; import com.djrapitops.plugin.task.AbsRunnable; import java.util.ArrayList; @@ -17,11 +19,14 @@ import java.util.List; public abstract class TPSCountTimer extends AbsRunnable { protected final List history; + protected final PluginLogger logger; + protected final ErrorHandler errorHandler; protected int latestPlayersOnline = 0; - public TPSCountTimer() { - super(); + public TPSCountTimer(PluginLogger logger, ErrorHandler errorHandler) { + this.logger = logger; + this.errorHandler = errorHandler; history = new ArrayList<>(); } @@ -38,8 +43,8 @@ public abstract class TPSCountTimer extends AbsRunnable { history.clear(); } } catch (Exception | NoClassDefFoundError | NoSuchMethodError | NoSuchFieldError e) { - Log.error("TPS Count Task Disabled due to error, reload Plan to re-enable."); - Log.toLog(this.getClass(), e); + logger.error("TPS Count Task Disabled due to error, reload Plan to re-enable."); + errorHandler.log(L.ERROR, this.getClass(), e); cancel(); } } 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 27322782c..6afc980b6 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 @@ -2,14 +2,30 @@ package com.djrapitops.plan.system.tasks.bungee; 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.info.server.properties.ServerProperties; import com.djrapitops.plan.system.tasks.TPSCountTimer; +import com.djrapitops.plugin.logging.console.PluginLogger; +import com.djrapitops.plugin.logging.error.ErrorHandler; + +import javax.inject.Inject; public class BungeeTPSCountTimer extends TPSCountTimer { + private final ServerProperties serverProperties; + + @Inject + public BungeeTPSCountTimer( + ServerProperties serverProperties, + PluginLogger logger, + ErrorHandler errorHandler + ) { + super(logger, errorHandler); + this.serverProperties = serverProperties; + } + @Override public void addNewTPSEntry(long nanoTime, long now) { - int onlineCount = ServerInfo.getServerProperties_Old().getOnlinePlayers(); + int onlineCount = serverProperties.getOnlinePlayers(); TPS tps = TPSBuilder.get() .date(now) .skipTPS() diff --git a/Plan/src/main/java/com/djrapitops/plan/system/tasks/bungee/EnableConnectionTask.java b/Plan/src/main/java/com/djrapitops/plan/system/tasks/bungee/EnableConnectionTask.java index 80d762879..83876540e 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/tasks/bungee/EnableConnectionTask.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/tasks/bungee/EnableConnectionTask.java @@ -5,12 +5,21 @@ import com.djrapitops.plan.system.info.connection.WebExceptionLogger; import com.djrapitops.plan.system.info.request.GenerateNetworkPageContentRequest; import com.djrapitops.plugin.task.AbsRunnable; +import javax.inject.Inject; + public class EnableConnectionTask extends AbsRunnable { + private ConnectionSystem connectionSystem; + + @Inject + public EnableConnectionTask(ConnectionSystem connectionSystem) { + this.connectionSystem = connectionSystem; + } + @Override public void run() { WebExceptionLogger.logIfOccurs(this.getClass(), - () -> ConnectionSystem.getInstance().sendWideInfoRequest(new GenerateNetworkPageContentRequest()) + () -> connectionSystem.sendWideInfoRequest(new GenerateNetworkPageContentRequest()) ); cancel(); } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/tasks/server/BootAnalysisTask.java b/Plan/src/main/java/com/djrapitops/plan/system/tasks/server/BootAnalysisTask.java index 5b19b2c88..bbcb42700 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/tasks/server/BootAnalysisTask.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/tasks/server/BootAnalysisTask.java @@ -5,20 +5,32 @@ import com.djrapitops.plan.system.info.InfoSystem; import com.djrapitops.plan.system.info.connection.WebExceptionLogger; import com.djrapitops.plan.system.info.request.GenerateAnalysisPageRequest; import com.djrapitops.plan.system.info.server.ServerInfo; -import com.djrapitops.plugin.api.utility.log.Log; +import com.djrapitops.plugin.logging.L; +import com.djrapitops.plugin.logging.error.ErrorHandler; import com.djrapitops.plugin.task.AbsRunnable; +import javax.inject.Inject; + public class BootAnalysisTask extends AbsRunnable { + private InfoSystem infoSystem; + private ErrorHandler errorHandler; + + @Inject + public BootAnalysisTask(InfoSystem infoSystem, ErrorHandler errorHandler) { + this.infoSystem = infoSystem; + this.errorHandler = errorHandler; + } + @Override public void run() { try { WebExceptionLogger.logIfOccurs(this.getClass(), () -> - InfoSystem.getInstance().sendRequest(new GenerateAnalysisPageRequest(ServerInfo.getServerUUID_Old())) + infoSystem.sendRequest(new GenerateAnalysisPageRequest(ServerInfo.getServerUUID_Old())) ); } catch (IllegalStateException e) { if (!PlanPlugin.getInstance().isReloading()) { - Log.toLog(this.getClass(), e); + errorHandler.log(L.WARN, this.getClass(), e); } } finally { cancel(); diff --git a/Plan/src/main/java/com/djrapitops/plan/system/tasks/server/BukkitTPSCountTimer.java b/Plan/src/main/java/com/djrapitops/plan/system/tasks/server/BukkitTPSCountTimer.java index da2edaff6..c2cc994f1 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/tasks/server/BukkitTPSCountTimer.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/tasks/server/BukkitTPSCountTimer.java @@ -2,22 +2,34 @@ package com.djrapitops.plan.system.tasks.server; import com.djrapitops.plan.Plan; import com.djrapitops.plan.data.container.TPS; -import com.djrapitops.plan.system.info.server.ServerInfo; +import com.djrapitops.plan.system.info.server.properties.ServerProperties; import com.djrapitops.plan.system.tasks.TPSCountTimer; import com.djrapitops.plugin.api.TimeAmount; import com.djrapitops.plugin.api.utility.log.Log; +import com.djrapitops.plugin.logging.console.PluginLogger; +import com.djrapitops.plugin.logging.error.ErrorHandler; import org.bukkit.World; +import javax.inject.Inject; import java.lang.management.ManagementFactory; import java.lang.management.OperatingSystemMXBean; public class BukkitTPSCountTimer extends TPSCountTimer { protected final Plan plugin; + private ServerProperties serverProperties; private long lastCheckNano; - public BukkitTPSCountTimer(Plan plugin) { + @Inject + public BukkitTPSCountTimer( + Plan plugin, + ServerProperties serverProperties, + PluginLogger logger, + ErrorHandler errorHandler + ) { + super(logger, errorHandler); this.plugin = plugin; + this.serverProperties = serverProperties; lastCheckNano = -1; } @@ -50,7 +62,7 @@ public class BukkitTPSCountTimer extends TPSCountTimer { long totalMemory = runtime.totalMemory(); long usedMemory = (totalMemory - runtime.freeMemory()) / 1000000; - int playersOnline = ServerInfo.getServerProperties_Old().getOnlinePlayers(); + int playersOnline = serverProperties.getOnlinePlayers(); latestPlayersOnline = playersOnline; int loadedChunks = getLoadedChunks(); int entityCount; diff --git a/Plan/src/main/java/com/djrapitops/plan/system/tasks/server/NetworkPageRefreshTask.java b/Plan/src/main/java/com/djrapitops/plan/system/tasks/server/NetworkPageRefreshTask.java index fccd0bcab..b5643cc30 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/tasks/server/NetworkPageRefreshTask.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/tasks/server/NetworkPageRefreshTask.java @@ -4,10 +4,19 @@ import com.djrapitops.plan.system.info.InfoSystem; import com.djrapitops.plan.system.info.connection.WebExceptionLogger; import com.djrapitops.plugin.task.AbsRunnable; +import javax.inject.Inject; + public class NetworkPageRefreshTask extends AbsRunnable { + private InfoSystem infoSystem; + + @Inject + public NetworkPageRefreshTask(InfoSystem infoSystem) { + this.infoSystem = infoSystem; + } + @Override public void run() { - WebExceptionLogger.logIfOccurs(this.getClass(), () -> InfoSystem.getInstance().updateNetworkPage()); + WebExceptionLogger.logIfOccurs(this.getClass(), () -> infoSystem.updateNetworkPage()); } } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/tasks/server/PaperTPSCountTimer.java b/Plan/src/main/java/com/djrapitops/plan/system/tasks/server/PaperTPSCountTimer.java index 56930fb94..14649a87a 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/tasks/server/PaperTPSCountTimer.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/tasks/server/PaperTPSCountTimer.java @@ -2,12 +2,23 @@ package com.djrapitops.plan.system.tasks.server; import com.djrapitops.plan.Plan; import com.djrapitops.plan.data.container.TPS; +import com.djrapitops.plan.system.info.server.properties.ServerProperties; +import com.djrapitops.plugin.logging.console.PluginLogger; +import com.djrapitops.plugin.logging.error.ErrorHandler; import org.bukkit.World; +import javax.inject.Inject; + public class PaperTPSCountTimer extends BukkitTPSCountTimer { - public PaperTPSCountTimer(Plan plugin) { - super(plugin); + @Inject + public PaperTPSCountTimer( + Plan plugin, + ServerProperties serverProperties, + PluginLogger logger, + ErrorHandler errorHandler + ) { + super(plugin, serverProperties, logger, errorHandler); } @Override diff --git a/Plan/src/main/java/com/djrapitops/plan/system/tasks/server/PeriodicAnalysisTask.java b/Plan/src/main/java/com/djrapitops/plan/system/tasks/server/PeriodicAnalysisTask.java index f234fd51c..c97afc47c 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/tasks/server/PeriodicAnalysisTask.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/tasks/server/PeriodicAnalysisTask.java @@ -5,24 +5,46 @@ import com.djrapitops.plan.system.info.InfoSystem; import com.djrapitops.plan.system.info.connection.WebExceptionLogger; import com.djrapitops.plan.system.info.request.GenerateAnalysisPageRequest; import com.djrapitops.plan.system.info.server.ServerInfo; -import com.djrapitops.plugin.api.utility.log.Log; +import com.djrapitops.plugin.logging.L; +import com.djrapitops.plugin.logging.console.PluginLogger; +import com.djrapitops.plugin.logging.error.ErrorHandler; import com.djrapitops.plugin.task.AbsRunnable; +import javax.inject.Inject; + public class PeriodicAnalysisTask extends AbsRunnable { + private final InfoSystem infoSystem; + private final ServerInfo serverInfo; + private final PluginLogger logger; + private final ErrorHandler errorHandler; + + @Inject + public PeriodicAnalysisTask( + InfoSystem infoSystem, + ServerInfo serverInfo, + PluginLogger logger, + ErrorHandler errorHandler + ) { + this.infoSystem = infoSystem; + this.serverInfo = serverInfo; + this.logger = logger; + this.errorHandler = errorHandler; + } + @Override public void run() { try { WebExceptionLogger.logIfOccurs(this.getClass(), () -> - InfoSystem.getInstance().sendRequest(new GenerateAnalysisPageRequest(ServerInfo.getServerUUID_Old())) + infoSystem.sendRequest(new GenerateAnalysisPageRequest(serverInfo.getServerUUID())) ); } catch (IllegalStateException e) { if (!PlanPlugin.getInstance().isReloading()) { - Log.toLog(this.getClass(), e); + errorHandler.log(L.WARN, this.getClass(), e); } } catch (Exception | NoClassDefFoundError | NoSuchMethodError | NoSuchFieldError e) { - Log.error("Periodic Analysis Task Disabled due to error, reload Plan to re-enable."); - Log.toLog(this.getClass(), e); + logger.error("Periodic Analysis Task Disabled due to error, reload Plan to re-enable."); + errorHandler.log(L.ERROR, this.getClass(), e); cancel(); } } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/tasks/server/PingCountTimer.java b/Plan/src/main/java/com/djrapitops/plan/system/tasks/server/PingCountTimer.java index 8e1e360c0..ea6497a64 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/tasks/server/PingCountTimer.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/tasks/server/PingCountTimer.java @@ -87,7 +87,13 @@ public class PingCountTimer extends AbsRunnable implements Listener { pingField = localPing; } - private final Map>> playerHistory = new HashMap<>(); + private final Map>> playerHistory; + private final RunnableFactory runnableFactory; + + public PingCountTimer(RunnableFactory runnableFactory) { + this.runnableFactory = runnableFactory; + playerHistory = new HashMap<>(); + } private static boolean isPingMethodAvailable() { try { @@ -153,7 +159,7 @@ public class PingCountTimer extends AbsRunnable implements Listener { @EventHandler public void onPlayerJoin(PlayerJoinEvent joinEvent) { Player player = joinEvent.getPlayer(); - RunnableFactory.createNew("Add Player to Ping list", new AbsRunnable() { + runnableFactory.create("Add Player to Ping list", new AbsRunnable() { @Override public void run() { if (player.isOnline()) { diff --git a/Plan/src/main/java/com/djrapitops/plan/system/tasks/server/SpongeTPSCountTimer.java b/Plan/src/main/java/com/djrapitops/plan/system/tasks/server/SpongeTPSCountTimer.java index 6da631794..1a198ed10 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/tasks/server/SpongeTPSCountTimer.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/tasks/server/SpongeTPSCountTimer.java @@ -1,23 +1,28 @@ package com.djrapitops.plan.system.tasks.server; -import com.djrapitops.plan.PlanSponge; 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.info.server.properties.ServerProperties; import com.djrapitops.plan.system.tasks.TPSCountTimer; import com.djrapitops.plugin.api.utility.log.Log; +import com.djrapitops.plugin.logging.console.PluginLogger; +import com.djrapitops.plugin.logging.error.ErrorHandler; import org.spongepowered.api.Sponge; import org.spongepowered.api.world.World; +import javax.inject.Inject; import java.lang.management.ManagementFactory; import java.lang.management.OperatingSystemMXBean; public class SpongeTPSCountTimer extends TPSCountTimer { private long lastCheckNano; + private ServerProperties serverProperties; - public SpongeTPSCountTimer(PlanSponge plugin) { - super(); + @Inject + public SpongeTPSCountTimer(ServerProperties serverProperties, PluginLogger logger, ErrorHandler errorHandler) { + super(logger, errorHandler); + this.serverProperties = serverProperties; lastCheckNano = -1; } @@ -56,7 +61,7 @@ public class SpongeTPSCountTimer extends TPSCountTimer { long usedMemory = (totalMemory - runtime.freeMemory()) / 1000000; double tps = Sponge.getGame().getServer().getTicksPerSecond(); - int playersOnline = ServerInfo.getServerProperties_Old().getOnlinePlayers(); + int playersOnline = serverProperties.getOnlinePlayers(); latestPlayersOnline = playersOnline; int loadedChunks = -1; // getLoadedChunks(); int entityCount = getEntityCount();