Started work on Dagger modules, extremely incomplete - will not run.

This commit is contained in:
Rsl1122 2018-08-18 21:53:33 +03:00
parent f324541343
commit 0b56576bb8
36 changed files with 478 additions and 95 deletions

View File

@ -166,6 +166,12 @@
<version>1.3</version> <version>1.3</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>com.google.dagger</groupId>
<artifactId>dagger</artifactId>
<version>2.16</version>
</dependency>
</dependencies> </dependencies>
<build> <build>
@ -195,6 +201,13 @@
<configuration> <configuration>
<source>1.8</source> <source>1.8</source>
<target>1.8</target> <target>1.8</target>
<annotationProcessorPaths>
<path>
<groupId>com.google.dagger</groupId>
<artifactId>dagger-compiler</artifactId>
<version>2.16</version>
</path>
</annotationProcessorPaths>
</configuration> </configuration>
</plugin> </plugin>
<plugin> <plugin>

View File

@ -21,24 +21,58 @@ package com.djrapitops.plan;
import com.djrapitops.plan.api.exceptions.EnableException; import com.djrapitops.plan.api.exceptions.EnableException;
import com.djrapitops.plan.command.PlanCommand; import com.djrapitops.plan.command.PlanCommand;
import com.djrapitops.plan.modules.APFModule;
import com.djrapitops.plan.modules.common.ExportModule;
import com.djrapitops.plan.modules.common.FileSystemModule;
import com.djrapitops.plan.modules.common.LocaleModule;
import com.djrapitops.plan.modules.common.VersionCheckModule;
import com.djrapitops.plan.modules.server.ServerCommandModule;
import com.djrapitops.plan.system.BukkitSystem; import com.djrapitops.plan.system.BukkitSystem;
import com.djrapitops.plan.system.locale.Locale; import com.djrapitops.plan.system.locale.Locale;
import com.djrapitops.plan.system.locale.lang.PluginLang; import com.djrapitops.plan.system.locale.lang.PluginLang;
import com.djrapitops.plan.system.processing.importing.ImporterManager; import com.djrapitops.plan.system.processing.importing.ImporterManager;
import com.djrapitops.plan.system.processing.importing.importers.OfflinePlayerImporter; import com.djrapitops.plan.system.processing.importing.importers.OfflinePlayerImporter;
import com.djrapitops.plan.system.settings.Settings;
import com.djrapitops.plan.system.settings.theme.PlanColorScheme; import com.djrapitops.plan.system.settings.theme.PlanColorScheme;
import com.djrapitops.plan.utilities.metrics.BStatsBukkit; import com.djrapitops.plan.utilities.metrics.BStatsBukkit;
import com.djrapitops.plugin.BukkitPlugin; import com.djrapitops.plugin.BukkitPlugin;
import com.djrapitops.plugin.StaticHolder; import com.djrapitops.plugin.StaticHolder;
import com.djrapitops.plugin.api.Benchmark;
import com.djrapitops.plugin.api.utility.log.DebugLog; import com.djrapitops.plugin.api.utility.log.DebugLog;
import com.djrapitops.plugin.api.utility.log.Log; import com.djrapitops.plugin.benchmarking.Benchmark;
import com.djrapitops.plugin.command.ColorScheme; import com.djrapitops.plugin.command.ColorScheme;
import dagger.BindsInstance;
import dagger.Component;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import javax.inject.Singleton;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@Singleton
@Component(modules = {
APFModule.class,
ServerCommandModule.class,
ExportModule.class,
VersionCheckModule.class,
FileSystemModule.class,
LocaleModule.class
})
interface PlanComponent {
PlanCommand planCommand();
BukkitSystem system();
@Component.Builder
interface Builder {
@BindsInstance
Builder plan(Plan plan);
PlanComponent build();
}
}
/** /**
* Main class for Bukkit that manages the plugin. * Main class for Bukkit that manages the plugin.
* *
@ -62,35 +96,38 @@ public class Plan extends BukkitPlugin implements PlanPlugin {
@Override @Override
public void onEnable() { public void onEnable() {
super.onEnable(); super.onEnable();
PlanComponent component = DaggerPlanComponent.builder().plan(this).build();
try { try {
Benchmark.start("Enable"); timings.start("Enable");
system = new BukkitSystem(this); system = component.system();
locale = system.getLocaleSystem().getLocale(); locale = system.getLocaleSystem().getLocale();
system.enable(); system.enable();
String debugString = Settings.DEBUG.toString();
// TODO Set debug logger
ImporterManager.registerImporter(new OfflinePlayerImporter()); ImporterManager.registerImporter(new OfflinePlayerImporter());
new BStatsBukkit(this).registerMetrics(); new BStatsBukkit(this).registerMetrics();
Log.debug("Verbose debug messages are enabled."); logger.debug("Verbose debug messages are enabled.");
Benchmark.stop("Enable", "Enable"); String benchTime = " (" + timings.end("Enable").map(Benchmark::toDurationString).orElse("-") + ")";
Log.logDebug("Enable"); logger.info(locale.getString(PluginLang.ENABLED) + benchTime);
Log.info(locale.getString(PluginLang.ENABLED));
} catch (AbstractMethodError e) { } catch (AbstractMethodError e) {
Log.error("Plugin ran into AbstractMethodError - Server restart is required. Likely cause is updating the jar without a restart."); logger.error("Plugin ran into AbstractMethodError - Server restart is required. Likely cause is updating the jar without a restart.");
} catch (EnableException e) { } catch (EnableException e) {
Log.error("----------------------------------------"); logger.error("----------------------------------------");
Log.error("Error: " + e.getMessage()); logger.error("Error: " + e.getMessage());
Log.error("----------------------------------------"); logger.error("----------------------------------------");
Log.error("Plugin Failed to Initialize Correctly. If this issue is caused by config settings you can use /plan reload"); logger.error("Plugin Failed to Initialize Correctly. If this issue is caused by config settings you can use /plan reload");
onDisable(); onDisable();
} catch (Exception e) { } catch (Exception e) {
Logger.getGlobal().log(Level.SEVERE, this.getClass().getSimpleName() + "-v" + getVersion(), e); Logger.getGlobal().log(Level.SEVERE, this.getClass().getSimpleName() + "-v" + getVersion(), e);
Log.error("Plugin Failed to Initialize Correctly. If this issue is caused by config settings you can use /plan reload"); logger.error("Plugin Failed to Initialize Correctly. If this issue is caused by config settings you can use /plan reload");
Log.error("This error should be reported at https://github.com/Rsl1122/Plan-PlayerAnalytics/issues"); logger.error("This error should be reported at https://github.com/Rsl1122/Plan-PlayerAnalytics/issues");
onDisable(); onDisable();
} }
registerCommand("plan", new PlanCommand(this)); registerCommand("plan", component.planCommand());
} }
@Override @Override
@ -105,8 +142,7 @@ public class Plan extends BukkitPlugin implements PlanPlugin {
public void onDisable() { public void onDisable() {
system.disable(); system.disable();
Log.info(locale.getString(PluginLang.DISABLED)); logger.info(locale.getString(PluginLang.DISABLED));
Benchmark.pluginDisabled(Plan.class);
DebugLog.pluginDisabled(Plan.class); DebugLog.pluginDisabled(Plan.class);
} }

View File

@ -4,10 +4,13 @@
*/ */
package com.djrapitops.plan.api; package com.djrapitops.plan.api;
import com.djrapitops.plan.data.plugin.HookHandler;
import com.djrapitops.plan.data.plugin.PluginData; import com.djrapitops.plan.data.plugin.PluginData;
import com.djrapitops.plan.system.ServerSystem; import com.djrapitops.plan.system.cache.DataCache;
import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.database.databases.operation.FetchOperations; import com.djrapitops.plan.system.database.databases.operation.FetchOperations;
import javax.inject.Inject;
import java.util.UUID; import java.util.UUID;
/** /**
@ -17,24 +20,29 @@ import java.util.UUID;
*/ */
public class ServerAPI extends CommonAPI { public class ServerAPI extends CommonAPI {
private final ServerSystem serverSystem; private final HookHandler hookHandler;
private final Database activeDatabase;
private final DataCache dataCache;
public ServerAPI(ServerSystem serverSystem) { @Inject
this.serverSystem = serverSystem; public ServerAPI(HookHandler hookHandler, Database activeDatabase, DataCache dataCache) {
this.hookHandler = hookHandler;
this.activeDatabase = activeDatabase;
this.dataCache = dataCache;
} }
@Override @Override
public void addPluginDataSource(PluginData pluginData) { public void addPluginDataSource(PluginData pluginData) {
serverSystem.getHookHandler().addPluginDataSource(pluginData); hookHandler.addPluginDataSource(pluginData);
} }
@Override @Override
public String getPlayerName(UUID uuid) { public String getPlayerName(UUID uuid) {
return serverSystem.getCacheSystem().getDataCache().getName(uuid); return dataCache.getName(uuid);
} }
@Override @Override
public FetchOperations fetchFromPlanDB() { public FetchOperations fetchFromPlanDB() {
return serverSystem.getDatabaseSystem().getActiveDatabase().fetch(); return activeDatabase.fetch();
} }
} }

View File

@ -23,7 +23,7 @@ public class PluginsConfigSection {
} }
private ConfigNode getPluginsSection() { private ConfigNode getPluginsSection() {
return ConfigSystem.getConfig().getConfigNode("Plugins"); return ConfigSystem.getConfig_Old().getConfigNode("Plugins");
} }
public void createSection(PluginData dataSource) { public void createSection(PluginData dataSource) {

View File

@ -0,0 +1,45 @@
package com.djrapitops.plan.modules;
import com.djrapitops.plugin.IPlugin;
import com.djrapitops.plugin.benchmarking.Timings;
import com.djrapitops.plugin.logging.console.PluginLogger;
import com.djrapitops.plugin.logging.debug.DebugLogger;
import com.djrapitops.plugin.logging.error.ErrorHandler;
import com.djrapitops.plugin.task.RunnableFactory;
import dagger.Module;
import dagger.Provides;
/**
* Dagger module for defining Abstract Plugin Framework utilities.
*
* @author Rsl1122
*/
@Module
public class APFModule {
@Provides
DebugLogger provideDebugLogger(IPlugin plugin) {
return plugin.getDebugLogger();
}
@Provides
PluginLogger providePluginLogger(IPlugin plugin) {
return plugin.getPluginLogger();
}
@Provides
ErrorHandler provideErrorHandler(IPlugin plugin) {
return plugin.getErrorHandler();
}
@Provides
Timings provideTimings(IPlugin plugin) {
return plugin.getTimings();
}
@Provides
RunnableFactory provideRunnableFactory(IPlugin plugin) {
return plugin.getRunnableFactory();
}
}

View File

@ -0,0 +1,20 @@
package com.djrapitops.plan.modules.common;
import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.system.export.ExportSystem;
import dagger.Module;
import dagger.Provides;
/**
* Dagger module for Export system.
*
* @author Rsl1122
*/
@Module
public class ExportModule {
@Provides
ExportSystem provideExportSystem(PlanPlugin plugin) {
return new ExportSystem(plugin);
}
}

View File

@ -0,0 +1,24 @@
package com.djrapitops.plan.modules.common;
import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.system.file.FileSystem;
import dagger.Module;
import dagger.Provides;
import javax.inject.Singleton;
/**
* Dagger module for providing FileSystem.
*
* @author Rsl1122
*/
@Module
public class FileSystemModule {
@Singleton
@Provides
FileSystem provideFileSystem(PlanPlugin plugin) {
return new FileSystem(plugin.getDataFolder());
}
}

View File

@ -0,0 +1,28 @@
package com.djrapitops.plan.modules.common;
import com.djrapitops.plan.system.locale.Locale;
import com.djrapitops.plan.system.locale.LocaleSystem;
import dagger.Module;
import dagger.Provides;
import javax.inject.Singleton;
/**
* Dagger Module for LocaleSystem.
*
* @author Rsl1122
*/
@Module
public class LocaleModule {
@Provides
@Singleton
LocaleSystem provideLocaleSystem() {
return new LocaleSystem();
}
@Provides
Locale provideLocale(LocaleSystem localeSystem) {
return localeSystem.getLocale();
}
}

View File

@ -0,0 +1,19 @@
package com.djrapitops.plan.modules.common;
import com.djrapitops.plan.data.plugin.HookHandler;
import dagger.Module;
import dagger.Provides;
/**
* Dagger module for Hooking to other plugins.
*
* @author Rsl1122
*/
@Module
public class PluginHookModule {
@Provides
HookHandler provideHookHandler() {
return new HookHandler();
}
}

View File

@ -0,0 +1,23 @@
package com.djrapitops.plan.modules.common;
import com.djrapitops.plan.system.locale.Locale;
import com.djrapitops.plan.system.update.VersionCheckSystem;
import com.djrapitops.plugin.IPlugin;
import dagger.Module;
import dagger.Provides;
/**
* Dagger module for VersionCheckSystem.
*
* @author Rsl1122
*/
@Module
public class VersionCheckModule {
@Provides
VersionCheckSystem provideVersionCheckSystem(IPlugin plugin, Locale locale) {
// TODO Remove supplier
return new VersionCheckSystem(plugin.getVersion(), () -> locale);
}
}

View File

@ -0,0 +1,24 @@
package com.djrapitops.plan.modules.server;
import com.djrapitops.plan.api.PlanAPI;
import com.djrapitops.plan.api.ServerAPI;
import com.djrapitops.plan.data.plugin.HookHandler;
import com.djrapitops.plan.system.cache.DataCache;
import com.djrapitops.plan.system.database.databases.Database;
import dagger.Module;
import dagger.Provides;
/**
* Dagger module for Server PlanAPI.
*
* @author Rsl1122
*/
@Module
public class ServerAPIModule {
@Provides
PlanAPI providePlanAPI(HookHandler hookHandler, DataCache dataCache, Database database) {
return new ServerAPI(hookHandler, database, dataCache);
}
}

View File

@ -0,0 +1,21 @@
package com.djrapitops.plan.modules.server;
import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.command.PlanCommand;
import dagger.Module;
import dagger.Provides;
/**
* Dagger module for Server Command /plan.
*
* @author Rsl1122
*/
@Module
public class ServerCommandModule {
@Provides
PlanCommand providePlanCommand(PlanPlugin plugin) {
return new PlanCommand(plugin);
}
}

View File

@ -0,0 +1,22 @@
package com.djrapitops.plan.modules.server;
import com.djrapitops.plan.system.database.DBSystem;
import com.djrapitops.plan.system.database.ServerDBSystem;
import com.djrapitops.plan.system.locale.Locale;
import dagger.Module;
import dagger.Provides;
/**
* Dagger module for server database.
*
* @author Rsl1122
*/
@Module
public class ServerDatabaseModule {
@Provides
DBSystem provideDatabaseSystem(Locale locale) {
return new ServerDBSystem(() -> locale);
}
}

View File

@ -0,0 +1,29 @@
package com.djrapitops.plan.modules.server;
import com.djrapitops.plan.system.info.InfoSystem;
import com.djrapitops.plan.system.info.ServerInfoSystem;
import com.djrapitops.plan.system.info.connection.ConnectionSystem;
import com.djrapitops.plan.system.info.connection.ServerConnectionSystem;
import com.djrapitops.plan.system.locale.Locale;
import dagger.Module;
import dagger.Provides;
/**
* Dagger module for InfoSystem.
*
* @author Rsl1122
*/
@Module
public class ServerInfoSystemModule {
@Provides
InfoSystem provideServerInfoSystem(ConnectionSystem connectionSystem) {
return new ServerInfoSystem(connectionSystem);
}
@Provides
ConnectionSystem provideServerConnectionSystem(Locale locale) {
return new ServerConnectionSystem(() -> locale); // TODO Remove supplier
}
}

View File

@ -0,0 +1,33 @@
package com.djrapitops.plan.modules.server.bukkit;
import com.djrapitops.plan.system.settings.config.ConfigSystem;
import com.djrapitops.plan.system.settings.config.ServerConfigSystem;
import com.djrapitops.plan.system.settings.theme.Theme;
import com.djrapitops.plugin.config.Config;
import dagger.Module;
import dagger.Provides;
/**
* Dagger module for Bukkit Configuration.
*
* @author Rsl1122
*/
@Module
public class BukkitConfigModule {
@Provides
ConfigSystem provideConfigSystem() {
return new ServerConfigSystem();
}
@Provides
Config provideConfig(ConfigSystem configSystem) {
return configSystem.getConfig();
}
@Provides
Theme provideTheme(ConfigSystem configSystem) {
return configSystem.getTheme();
}
}

View File

@ -10,8 +10,10 @@ import com.djrapitops.plan.api.ServerAPI;
import com.djrapitops.plan.api.exceptions.EnableException; import com.djrapitops.plan.api.exceptions.EnableException;
import com.djrapitops.plan.data.plugin.HookHandler; import com.djrapitops.plan.data.plugin.HookHandler;
import com.djrapitops.plan.system.database.ServerDBSystem; import com.djrapitops.plan.system.database.ServerDBSystem;
import com.djrapitops.plan.system.export.ExportSystem;
import com.djrapitops.plan.system.file.FileSystem; import com.djrapitops.plan.system.file.FileSystem;
import com.djrapitops.plan.system.info.ServerInfoSystem; import com.djrapitops.plan.system.info.ServerInfoSystem;
import com.djrapitops.plan.system.info.connection.ServerConnectionSystem;
import com.djrapitops.plan.system.info.server.BukkitServerInfo; import com.djrapitops.plan.system.info.server.BukkitServerInfo;
import com.djrapitops.plan.system.listeners.BukkitListenerSystem; import com.djrapitops.plan.system.listeners.BukkitListenerSystem;
import com.djrapitops.plan.system.locale.Locale; import com.djrapitops.plan.system.locale.Locale;
@ -23,6 +25,7 @@ import com.djrapitops.plan.system.update.VersionCheckSystem;
import com.djrapitops.plugin.StaticHolder; import com.djrapitops.plugin.StaticHolder;
import com.djrapitops.plugin.api.utility.log.Log; import com.djrapitops.plugin.api.utility.log.Log;
import javax.inject.Inject;
import java.util.function.Supplier; import java.util.function.Supplier;
/** /**
@ -32,6 +35,7 @@ import java.util.function.Supplier;
*/ */
public class BukkitSystem extends PlanSystem implements ServerSystem { public class BukkitSystem extends PlanSystem implements ServerSystem {
@Inject
public BukkitSystem(Plan plugin) { public BukkitSystem(Plan plugin) {
setTestSystem(this); setTestSystem(this);
@ -42,15 +46,16 @@ public class BukkitSystem extends PlanSystem implements ServerSystem {
versionCheckSystem = new VersionCheckSystem(plugin.getVersion(), localeSupplier); versionCheckSystem = new VersionCheckSystem(plugin.getVersion(), localeSupplier);
fileSystem = new FileSystem(plugin); fileSystem = new FileSystem(plugin);
configSystem = new ServerConfigSystem(); configSystem = new ServerConfigSystem();
exportSystem = new ExportSystem(plugin);
databaseSystem = new ServerDBSystem(localeSupplier); databaseSystem = new ServerDBSystem(localeSupplier);
listenerSystem = new BukkitListenerSystem(plugin); listenerSystem = new BukkitListenerSystem(plugin);
taskSystem = new BukkitTaskSystem(plugin); taskSystem = new BukkitTaskSystem(plugin);
infoSystem = new ServerInfoSystem(localeSupplier); infoSystem = new ServerInfoSystem(new ServerConnectionSystem(localeSupplier));
serverInfo = new BukkitServerInfo(plugin); serverInfo = new BukkitServerInfo(plugin);
hookHandler = new HookHandler(); hookHandler = new HookHandler();
planAPI = new ServerAPI(this); planAPI = new ServerAPI(hookHandler, databaseSystem.getActiveDatabase(), cacheSystem.getDataCache());
StaticHolder.saveInstance(ShutdownHook.class, plugin.getClass()); StaticHolder.saveInstance(ShutdownHook.class, plugin.getClass());
new ShutdownHook().register(); new ShutdownHook().register();

View File

@ -11,6 +11,7 @@ import com.djrapitops.plan.data.plugin.HookHandler;
import com.djrapitops.plan.system.cache.BungeeCacheSystem; import com.djrapitops.plan.system.cache.BungeeCacheSystem;
import com.djrapitops.plan.system.database.BungeeDBSystem; import com.djrapitops.plan.system.database.BungeeDBSystem;
import com.djrapitops.plan.system.database.DBSystem; 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.file.FileSystem;
import com.djrapitops.plan.system.info.BungeeInfoSystem; import com.djrapitops.plan.system.info.BungeeInfoSystem;
import com.djrapitops.plan.system.info.server.BungeeServerInfo; import com.djrapitops.plan.system.info.server.BungeeServerInfo;
@ -42,10 +43,11 @@ public class BungeeSystem extends PlanSystem {
versionCheckSystem = new VersionCheckSystem(plugin.getVersion(), localeSupplier); versionCheckSystem = new VersionCheckSystem(plugin.getVersion(), localeSupplier);
fileSystem = new FileSystem(plugin); fileSystem = new FileSystem(plugin);
configSystem = new BungeeConfigSystem(); configSystem = new BungeeConfigSystem();
exportSystem = new ExportSystem(plugin);
databaseSystem = new BungeeDBSystem(localeSupplier); databaseSystem = new BungeeDBSystem(localeSupplier);
cacheSystem = new BungeeCacheSystem(this); cacheSystem = new BungeeCacheSystem(this);
listenerSystem = new BungeeListenerSystem(plugin); listenerSystem = new BungeeListenerSystem(plugin);
taskSystem = new BungeeTaskSystem(plugin); taskSystem = new BungeeTaskSystem(plugin.getRunnableFactory());
infoSystem = new BungeeInfoSystem(); infoSystem = new BungeeInfoSystem();
serverInfo = new BungeeServerInfo(plugin); serverInfo = new BungeeServerInfo(plugin);

View File

@ -9,6 +9,7 @@ import com.djrapitops.plan.api.exceptions.EnableException;
import com.djrapitops.plan.data.plugin.HookHandler; import com.djrapitops.plan.data.plugin.HookHandler;
import com.djrapitops.plan.system.cache.CacheSystem; import com.djrapitops.plan.system.cache.CacheSystem;
import com.djrapitops.plan.system.database.DBSystem; 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.file.FileSystem;
import com.djrapitops.plan.system.info.InfoSystem; import com.djrapitops.plan.system.info.InfoSystem;
import com.djrapitops.plan.system.info.server.ServerInfo; import com.djrapitops.plan.system.info.server.ServerInfo;
@ -47,6 +48,7 @@ public abstract class PlanSystem implements SubSystem {
protected VersionCheckSystem versionCheckSystem; protected VersionCheckSystem versionCheckSystem;
protected FileSystem fileSystem; protected FileSystem fileSystem;
protected ConfigSystem configSystem; protected ConfigSystem configSystem;
protected ExportSystem exportSystem;
protected DBSystem databaseSystem; protected DBSystem databaseSystem;
protected InfoSystem infoSystem; protected InfoSystem infoSystem;
@ -94,6 +96,7 @@ public abstract class PlanSystem implements SubSystem {
localeSystem, localeSystem,
versionCheckSystem, versionCheckSystem,
databaseSystem, databaseSystem,
exportSystem,
webServerSystem, webServerSystem,
processing, processing,
serverInfo, serverInfo,
@ -118,6 +121,7 @@ public abstract class PlanSystem implements SubSystem {
hookHandler, hookHandler,
cacheSystem, cacheSystem,
listenerSystem, listenerSystem,
exportSystem,
processing, processing,
databaseSystem, databaseSystem,
webServerSystem, webServerSystem,

View File

@ -10,6 +10,7 @@ import com.djrapitops.plan.api.ServerAPI;
import com.djrapitops.plan.api.exceptions.EnableException; import com.djrapitops.plan.api.exceptions.EnableException;
import com.djrapitops.plan.data.plugin.HookHandler; import com.djrapitops.plan.data.plugin.HookHandler;
import com.djrapitops.plan.system.database.ServerDBSystem; import com.djrapitops.plan.system.database.ServerDBSystem;
import com.djrapitops.plan.system.export.ExportSystem;
import com.djrapitops.plan.system.file.FileSystem; import com.djrapitops.plan.system.file.FileSystem;
import com.djrapitops.plan.system.info.ServerInfoSystem; import com.djrapitops.plan.system.info.ServerInfoSystem;
import com.djrapitops.plan.system.info.server.SpongeServerInfo; import com.djrapitops.plan.system.info.server.SpongeServerInfo;
@ -42,6 +43,7 @@ public class SpongeSystem extends PlanSystem implements ServerSystem {
versionCheckSystem = new VersionCheckSystem(plugin.getVersion(), localeSupplier); versionCheckSystem = new VersionCheckSystem(plugin.getVersion(), localeSupplier);
fileSystem = new FileSystem(plugin); fileSystem = new FileSystem(plugin);
configSystem = new SpongeConfigSystem(); configSystem = new SpongeConfigSystem();
exportSystem = new ExportSystem(plugin);
databaseSystem = new ServerDBSystem(localeSupplier); databaseSystem = new ServerDBSystem(localeSupplier);
listenerSystem = new SpongeListenerSystem(plugin); listenerSystem = new SpongeListenerSystem(plugin);
taskSystem = new SpongeTaskSystem(plugin); taskSystem = new SpongeTaskSystem(plugin);

View File

@ -0,0 +1,33 @@
package com.djrapitops.plan.system.export;
import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.system.SubSystem;
import com.djrapitops.plan.system.processing.Processing;
import com.djrapitops.plan.system.settings.Settings;
import com.djrapitops.plan.utilities.file.export.HtmlExport;
/**
* System in charge of exporting html.
*
* @author Rsl1122
*/
public class ExportSystem implements SubSystem {
private final PlanPlugin plugin;
public ExportSystem(PlanPlugin plugin) {
this.plugin = plugin;
}
@Override
public void enable() {
if (Settings.ANALYSIS_EXPORT.isTrue()) {
Processing.submitNonCritical(new HtmlExport(plugin));
}
}
@Override
public void disable() {
}
}

View File

@ -29,6 +29,7 @@ public class FileSystem implements SubSystem {
private final File dataFolder; private final File dataFolder;
private File configFile; private File configFile;
@Deprecated
public FileSystem(PlanPlugin plugin) { public FileSystem(PlanPlugin plugin) {
this(plugin.getDataFolder()); this(plugin.getDataFolder());
} }

View File

@ -6,17 +6,14 @@ package com.djrapitops.plan.system.info;
import com.djrapitops.plan.api.exceptions.connection.NoServersException; import com.djrapitops.plan.api.exceptions.connection.NoServersException;
import com.djrapitops.plan.api.exceptions.connection.WebException; import com.djrapitops.plan.api.exceptions.connection.WebException;
import com.djrapitops.plan.system.info.connection.ServerConnectionSystem; import com.djrapitops.plan.system.info.connection.ConnectionSystem;
import com.djrapitops.plan.system.info.request.CacheNetworkPageContentRequest; import com.djrapitops.plan.system.info.request.CacheNetworkPageContentRequest;
import com.djrapitops.plan.system.info.request.InfoRequest; import com.djrapitops.plan.system.info.request.InfoRequest;
import com.djrapitops.plan.system.info.request.SetupRequest; import com.djrapitops.plan.system.info.request.SetupRequest;
import com.djrapitops.plan.system.info.server.ServerInfo; import com.djrapitops.plan.system.info.server.ServerInfo;
import com.djrapitops.plan.system.locale.Locale;
import com.djrapitops.plan.utilities.html.HtmlStructure; import com.djrapitops.plan.utilities.html.HtmlStructure;
import com.djrapitops.plugin.api.utility.log.Log; import com.djrapitops.plugin.api.utility.log.Log;
import java.util.function.Supplier;
/** /**
* InfoSystem for Bukkit servers. * InfoSystem for Bukkit servers.
* *
@ -24,8 +21,8 @@ import java.util.function.Supplier;
*/ */
public class ServerInfoSystem extends InfoSystem { public class ServerInfoSystem extends InfoSystem {
public ServerInfoSystem(Supplier<Locale> locale) { public ServerInfoSystem(ConnectionSystem connectionSystem) {
super(new ServerConnectionSystem(locale)); super(connectionSystem);
} }
@Override @Override

View File

@ -18,6 +18,7 @@ import com.djrapitops.plan.system.webserver.WebServerSystem;
import com.djrapitops.plugin.api.TimeAmount; import com.djrapitops.plugin.api.TimeAmount;
import com.djrapitops.plugin.api.utility.log.Log; import com.djrapitops.plugin.api.utility.log.Log;
import javax.inject.Inject;
import java.util.Optional; import java.util.Optional;
import java.util.UUID; import java.util.UUID;
import java.util.function.Supplier; import java.util.function.Supplier;
@ -35,6 +36,7 @@ public class ServerConnectionSystem extends ConnectionSystem {
private Server mainServer; private Server mainServer;
@Inject
public ServerConnectionSystem(Supplier<Locale> locale) { public ServerConnectionSystem(Supplier<Locale> locale) {
this.locale = locale; this.locale = locale;
latestServerMapRefresh = 0; latestServerMapRefresh = 0;

View File

@ -26,7 +26,7 @@ public class ServerSpecificSettings {
public static void updateSettings(Map<String, String> settings) { public static void updateSettings(Map<String, String> settings) {
Log.debug("Checking new settings.."); Log.debug("Checking new settings..");
Config config = ConfigSystem.getConfig(); Config config = ConfigSystem.getConfig_Old();
boolean changedSomething = false; boolean changedSomething = false;
for (Map.Entry<String, String> setting : settings.entrySet()) { for (Map.Entry<String, String> setting : settings.entrySet()) {
@ -79,7 +79,7 @@ public class ServerSpecificSettings {
public void addOriginalBukkitSettings(UUID serverUUID, Map<String, Object> settings) { public void addOriginalBukkitSettings(UUID serverUUID, Map<String, Object> settings) {
try { try {
Config config = ConfigSystem.getConfig(); Config config = ConfigSystem.getConfig_Old();
if (!Verify.isEmpty(config.getString("Servers." + serverUUID + ".ServerName"))) { if (!Verify.isEmpty(config.getString("Servers." + serverUUID + ".ServerName"))) {
return; return;
} }
@ -111,25 +111,25 @@ public class ServerSpecificSettings {
} }
public boolean getBoolean(UUID serverUUID, Settings setting) { public boolean getBoolean(UUID serverUUID, Settings setting) {
Config config = ConfigSystem.getConfig(); Config config = ConfigSystem.getConfig_Old();
String path = getPath(serverUUID, setting); String path = getPath(serverUUID, setting);
return config.getBoolean(path); return config.getBoolean(path);
} }
public String getString(UUID serverUUID, Settings setting) { public String getString(UUID serverUUID, Settings setting) {
Config config = ConfigSystem.getConfig(); Config config = ConfigSystem.getConfig_Old();
String path = getPath(serverUUID, setting); String path = getPath(serverUUID, setting);
return config.getString(path); return config.getString(path);
} }
public Integer getInt(UUID serverUUID, Settings setting) { public Integer getInt(UUID serverUUID, Settings setting) {
Config config = ConfigSystem.getConfig(); Config config = ConfigSystem.getConfig_Old();
String path = getPath(serverUUID, setting); String path = getPath(serverUUID, setting);
return config.getInt(path); return config.getInt(path);
} }
public void set(UUID serverUUID, Settings setting, Object value) throws IOException { public void set(UUID serverUUID, Settings setting, Object value) throws IOException {
Config config = ConfigSystem.getConfig(); Config config = ConfigSystem.getConfig_Old();
String path = getPath(serverUUID, setting); String path = getPath(serverUUID, setting);
config.set(path, value); config.set(path, value);
config.save(); config.save();

View File

@ -143,7 +143,7 @@ public enum Settings {
public static void save() { public static void save() {
try { try {
ConfigSystem.getConfig().save(); ConfigSystem.getConfig_Old().save();
} catch (IOException e) { } catch (IOException e) {
Log.toLog(Settings.class, e); Log.toLog(Settings.class, e);
} }
@ -197,7 +197,7 @@ public enum Settings {
} }
private Config getConfig() { private Config getConfig() {
Config config = ConfigSystem.getConfig(); Config config = ConfigSystem.getConfig_Old();
Verify.nullCheck(config, () -> new IllegalStateException("Settings are not supposed to be called before ConfigSystem is Enabled!")); Verify.nullCheck(config, () -> new IllegalStateException("Settings are not supposed to be called before ConfigSystem is Enabled!"));
return config; return config;
} }

View File

@ -42,7 +42,7 @@ public class WorldAliasSettings {
} }
private static ConfigNode getAliasSection() { private static ConfigNode getAliasSection() {
Config config = ConfigSystem.getConfig(); Config config = ConfigSystem.getConfig_Old();
return config.getConfigNode(Settings.WORLD_ALIASES.getPath()); return config.getConfigNode(Settings.WORLD_ALIASES.getPath());
} }

View File

@ -36,10 +36,19 @@ public abstract class ConfigSystem implements SubSystem {
return configSystem; return configSystem;
} }
public static Config getConfig() { @Deprecated
public static Config getConfig_Old() {
return getInstance().config; return getInstance().config;
} }
public Config getConfig() {
return config;
}
public Theme getTheme() {
return theme;
}
public Theme getThemeSystem() { public Theme getThemeSystem() {
return getInstance().theme; return getInstance().theme;
} }

View File

@ -18,12 +18,15 @@ import org.bukkit.Bukkit;
*/ */
public class BukkitTaskSystem extends ServerTaskSystem { public class BukkitTaskSystem extends ServerTaskSystem {
private final Plan plugin;
public BukkitTaskSystem(Plan plugin) { public BukkitTaskSystem(Plan plugin) {
super(plugin, super(plugin.getRunnableFactory(),
Check.isPaperAvailable() Check.isPaperAvailable()
? new PaperTPSCountTimer(plugin) ? new PaperTPSCountTimer(plugin)
: new BukkitTPSCountTimer(plugin) : new BukkitTPSCountTimer(plugin)
); );
this.plugin = plugin;
} }
@Override @Override
@ -31,7 +34,7 @@ public class BukkitTaskSystem extends ServerTaskSystem {
super.enable(); super.enable();
try { try {
PingCountTimer pingCountTimer = new PingCountTimer(); PingCountTimer pingCountTimer = new PingCountTimer();
((Plan) plugin).registerListener(pingCountTimer); plugin.registerListener(pingCountTimer);
registerTask("PingCountTimer", pingCountTimer) registerTask("PingCountTimer", pingCountTimer)
.runTaskTimer(20L, PingCountTimer.PING_INTERVAL); .runTaskTimer(20L, PingCountTimer.PING_INTERVAL);
} catch (ExceptionInInitializerError | NoClassDefFoundError ignore) { } catch (ExceptionInInitializerError | NoClassDefFoundError ignore) {
@ -42,6 +45,6 @@ public class BukkitTaskSystem extends ServerTaskSystem {
@Override @Override
public void disable() { public void disable() {
super.disable(); super.disable();
Bukkit.getScheduler().cancelTasks((Plan) plugin); Bukkit.getScheduler().cancelTasks(plugin);
} }
} }

View File

@ -4,14 +4,12 @@
*/ */
package com.djrapitops.plan.system.tasks; package com.djrapitops.plan.system.tasks;
import com.djrapitops.plan.PlanBungee;
import com.djrapitops.plan.system.processing.Processing;
import com.djrapitops.plan.system.settings.Settings;
import com.djrapitops.plan.system.tasks.bungee.BungeeTPSCountTimer; import com.djrapitops.plan.system.tasks.bungee.BungeeTPSCountTimer;
import com.djrapitops.plan.system.tasks.bungee.EnableConnectionTask; import com.djrapitops.plan.system.tasks.bungee.EnableConnectionTask;
import com.djrapitops.plan.system.tasks.server.NetworkPageRefreshTask; import com.djrapitops.plan.system.tasks.server.NetworkPageRefreshTask;
import com.djrapitops.plan.utilities.file.export.HtmlExport;
import com.djrapitops.plugin.api.TimeAmount; import com.djrapitops.plugin.api.TimeAmount;
import com.djrapitops.plugin.task.RunnableFactory;
import com.google.inject.Inject;
/** /**
* TaskSystem responsible for registering tasks for Bungee. * TaskSystem responsible for registering tasks for Bungee.
@ -20,11 +18,9 @@ import com.djrapitops.plugin.api.TimeAmount;
*/ */
public class BungeeTaskSystem extends TaskSystem { public class BungeeTaskSystem extends TaskSystem {
private final PlanBungee plugin; @Inject
public BungeeTaskSystem(RunnableFactory runnableFactory) {
public BungeeTaskSystem(PlanBungee plugin) { super(runnableFactory, new BungeeTPSCountTimer());
super(plugin, new BungeeTPSCountTimer(plugin));
this.plugin = plugin;
} }
@Override @Override
@ -36,8 +32,5 @@ public class BungeeTaskSystem extends TaskSystem {
registerTask(new EnableConnectionTask()).runTaskAsynchronously(); registerTask(new EnableConnectionTask()).runTaskAsynchronously();
registerTask(tpsCountTimer).runTaskTimerAsynchronously(1000, TimeAmount.SECOND.ticks()); registerTask(tpsCountTimer).runTaskTimerAsynchronously(1000, TimeAmount.SECOND.ticks());
registerTask(new NetworkPageRefreshTask()).runTaskTimerAsynchronously(1500, TimeAmount.MINUTE.ticks()); registerTask(new NetworkPageRefreshTask()).runTaskTimerAsynchronously(1500, TimeAmount.MINUTE.ticks());
if (Settings.ANALYSIS_EXPORT.isTrue()) {
Processing.submitNonCritical(new HtmlExport(plugin));
}
} }
} }

View File

@ -1,15 +1,13 @@
package com.djrapitops.plan.system.tasks; package com.djrapitops.plan.system.tasks;
import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.system.processing.Processing;
import com.djrapitops.plan.system.settings.Settings; import com.djrapitops.plan.system.settings.Settings;
import com.djrapitops.plan.system.tasks.server.BootAnalysisTask; import com.djrapitops.plan.system.tasks.server.BootAnalysisTask;
import com.djrapitops.plan.system.tasks.server.NetworkPageRefreshTask; import com.djrapitops.plan.system.tasks.server.NetworkPageRefreshTask;
import com.djrapitops.plan.system.tasks.server.PeriodicAnalysisTask; import com.djrapitops.plan.system.tasks.server.PeriodicAnalysisTask;
import com.djrapitops.plan.utilities.file.export.HtmlExport;
import com.djrapitops.plugin.api.Benchmark; import com.djrapitops.plugin.api.Benchmark;
import com.djrapitops.plugin.api.TimeAmount; import com.djrapitops.plugin.api.TimeAmount;
import com.djrapitops.plugin.task.PluginTask; import com.djrapitops.plugin.task.PluginTask;
import com.djrapitops.plugin.task.RunnableFactory;
/** /**
* Abstracted TaskSystem implementation for both Bukkit and Sponge. * Abstracted TaskSystem implementation for both Bukkit and Sponge.
@ -18,12 +16,10 @@ import com.djrapitops.plugin.task.PluginTask;
*/ */
public class ServerTaskSystem extends TaskSystem { public class ServerTaskSystem extends TaskSystem {
protected final PlanPlugin plugin;
protected PluginTask bootAnalysisTask; protected PluginTask bootAnalysisTask;
public ServerTaskSystem(PlanPlugin plugin, TPSCountTimer tpsCountTimer) { public ServerTaskSystem(RunnableFactory runnableFactory, TPSCountTimer tpsCountTimer) {
super(plugin, tpsCountTimer); super(runnableFactory, tpsCountTimer);
this.plugin = plugin;
} }
@Override @Override
@ -46,9 +42,6 @@ public class ServerTaskSystem extends TaskSystem {
if (analysisRefreshTaskIsEnabled) { if (analysisRefreshTaskIsEnabled) {
registerTask(new PeriodicAnalysisTask()).runTaskTimerAsynchronously(analysisPeriod, analysisPeriod); registerTask(new PeriodicAnalysisTask()).runTaskTimerAsynchronously(analysisPeriod, analysisPeriod);
} }
if (Settings.ANALYSIS_EXPORT.isTrue()) {
Processing.submitNonCritical(new HtmlExport(plugin));
}
Benchmark.stop("Enable", "Task Registration"); Benchmark.stop("Enable", "Task Registration");
} }

View File

@ -7,8 +7,11 @@ import org.spongepowered.api.scheduler.Task;
public class SpongeTaskSystem extends ServerTaskSystem { public class SpongeTaskSystem extends ServerTaskSystem {
private final PlanSponge plugin;
public SpongeTaskSystem(PlanSponge plugin) { public SpongeTaskSystem(PlanSponge plugin) {
super(plugin, new SpongeTPSCountTimer(plugin)); super(plugin.getRunnableFactory(), new SpongeTPSCountTimer(plugin));
this.plugin = plugin;
} }
@Override @Override

View File

@ -1,6 +1,5 @@
package com.djrapitops.plan.system.tasks; package com.djrapitops.plan.system.tasks;
import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.data.container.TPS; import com.djrapitops.plan.data.container.TPS;
import com.djrapitops.plan.system.processing.Processing; import com.djrapitops.plan.system.processing.Processing;
import com.djrapitops.plan.system.processing.processors.TPSInsertProcessor; import com.djrapitops.plan.system.processing.processors.TPSInsertProcessor;
@ -15,16 +14,14 @@ import java.util.List;
* *
* @author Rsl1122 * @author Rsl1122
*/ */
public abstract class TPSCountTimer<T extends PlanPlugin> extends AbsRunnable { public abstract class TPSCountTimer extends AbsRunnable {
protected final T plugin;
protected final List<TPS> history; protected final List<TPS> history;
protected int latestPlayersOnline = 0; protected int latestPlayersOnline = 0;
public TPSCountTimer(T plugin) { public TPSCountTimer() {
super(); super();
this.plugin = plugin;
history = new ArrayList<>(); history = new ArrayList<>();
} }

View File

@ -4,7 +4,6 @@
*/ */
package com.djrapitops.plan.system.tasks; package com.djrapitops.plan.system.tasks;
import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.system.SubSystem; import com.djrapitops.plan.system.SubSystem;
import com.djrapitops.plugin.task.AbsRunnable; import com.djrapitops.plugin.task.AbsRunnable;
import com.djrapitops.plugin.task.PluginRunnable; import com.djrapitops.plugin.task.PluginRunnable;
@ -19,14 +18,12 @@ import com.djrapitops.plugin.task.RunnableFactory;
*/ */
public abstract class TaskSystem implements SubSystem { public abstract class TaskSystem implements SubSystem {
protected final PlanPlugin plugin;
protected TPSCountTimer tpsCountTimer; protected TPSCountTimer tpsCountTimer;
protected final RunnableFactory runnableFactory; protected final RunnableFactory runnableFactory;
public TaskSystem(PlanPlugin plugin, TPSCountTimer tpsCountTimer) { public TaskSystem(RunnableFactory runnableFactory, TPSCountTimer tpsCountTimer) {
this.plugin = plugin;
this.tpsCountTimer = tpsCountTimer; this.tpsCountTimer = tpsCountTimer;
runnableFactory = plugin.getRunnableFactory(); this.runnableFactory = runnableFactory;
} }
protected PluginRunnable registerTask(AbsRunnable runnable) { protected PluginRunnable registerTask(AbsRunnable runnable) {

View File

@ -1,16 +1,11 @@
package com.djrapitops.plan.system.tasks.bungee; 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.TPS;
import com.djrapitops.plan.data.container.builders.TPSBuilder; import com.djrapitops.plan.data.container.builders.TPSBuilder;
import com.djrapitops.plan.system.info.server.ServerInfo; import com.djrapitops.plan.system.info.server.ServerInfo;
import com.djrapitops.plan.system.tasks.TPSCountTimer; import com.djrapitops.plan.system.tasks.TPSCountTimer;
public class BungeeTPSCountTimer extends TPSCountTimer<PlanBungee> { public class BungeeTPSCountTimer extends TPSCountTimer {
public BungeeTPSCountTimer(PlanBungee plugin) {
super(plugin);
}
@Override @Override
public void addNewTPSEntry(long nanoTime, long now) { public void addNewTPSEntry(long nanoTime, long now) {

View File

@ -2,6 +2,7 @@ package com.djrapitops.plan.system.tasks.server;
import com.djrapitops.plan.Plan; import com.djrapitops.plan.Plan;
import com.djrapitops.plan.data.container.TPS; import com.djrapitops.plan.data.container.TPS;
import com.djrapitops.plan.system.info.server.ServerInfo;
import com.djrapitops.plan.system.tasks.TPSCountTimer; import com.djrapitops.plan.system.tasks.TPSCountTimer;
import com.djrapitops.plugin.api.TimeAmount; import com.djrapitops.plugin.api.TimeAmount;
import com.djrapitops.plugin.api.utility.log.Log; import com.djrapitops.plugin.api.utility.log.Log;
@ -10,12 +11,13 @@ import org.bukkit.World;
import java.lang.management.ManagementFactory; import java.lang.management.ManagementFactory;
import java.lang.management.OperatingSystemMXBean; import java.lang.management.OperatingSystemMXBean;
public class BukkitTPSCountTimer extends TPSCountTimer<Plan> { public class BukkitTPSCountTimer extends TPSCountTimer {
protected final Plan plugin;
private long lastCheckNano; private long lastCheckNano;
public BukkitTPSCountTimer(Plan plugin) { public BukkitTPSCountTimer(Plan plugin) {
super(plugin); this.plugin = plugin;
lastCheckNano = -1; lastCheckNano = -1;
} }
@ -48,7 +50,7 @@ public class BukkitTPSCountTimer extends TPSCountTimer<Plan> {
long totalMemory = runtime.totalMemory(); long totalMemory = runtime.totalMemory();
long usedMemory = (totalMemory - runtime.freeMemory()) / 1000000; long usedMemory = (totalMemory - runtime.freeMemory()) / 1000000;
int playersOnline = plugin.getServer().getOnlinePlayers().size(); int playersOnline = ServerInfo.getServerProperties().getOnlinePlayers();
latestPlayersOnline = playersOnline; latestPlayersOnline = playersOnline;
int loadedChunks = getLoadedChunks(); int loadedChunks = getLoadedChunks();
int entityCount; int entityCount;

View File

@ -12,12 +12,12 @@ import org.spongepowered.api.world.World;
import java.lang.management.ManagementFactory; import java.lang.management.ManagementFactory;
import java.lang.management.OperatingSystemMXBean; import java.lang.management.OperatingSystemMXBean;
public class SpongeTPSCountTimer extends TPSCountTimer<PlanSponge> { public class SpongeTPSCountTimer extends TPSCountTimer {
private long lastCheckNano; private long lastCheckNano;
public SpongeTPSCountTimer(PlanSponge plugin) { public SpongeTPSCountTimer(PlanSponge plugin) {
super(plugin); super();
lastCheckNano = -1; lastCheckNano = -1;
} }