mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-09-06 03:38:06 +02:00
Tasks, BungeeTaskSystem initialized by Dagger
This commit is contained in:
parent
8d28169c6c
commit
c6b9058bb0
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -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());
|
||||
|
@ -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());
|
||||
|
@ -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;
|
||||
|
@ -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."));
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
@ -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() {
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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<TPS> 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();
|
||||
}
|
||||
}
|
||||
|
@ -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()
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -87,7 +87,13 @@ public class PingCountTimer extends AbsRunnable implements Listener {
|
||||
pingField = localPing;
|
||||
}
|
||||
|
||||
private final Map<UUID, List<DateObj<Integer>>> playerHistory = new HashMap<>();
|
||||
private final Map<UUID, List<DateObj<Integer>>> 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()) {
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user