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

View File

@ -21,24 +21,58 @@ package com.djrapitops.plan;
import com.djrapitops.plan.api.exceptions.EnableException;
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.locale.Locale;
import com.djrapitops.plan.system.locale.lang.PluginLang;
import com.djrapitops.plan.system.processing.importing.ImporterManager;
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.utilities.metrics.BStatsBukkit;
import com.djrapitops.plugin.BukkitPlugin;
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.Log;
import com.djrapitops.plugin.benchmarking.Benchmark;
import com.djrapitops.plugin.command.ColorScheme;
import dagger.BindsInstance;
import dagger.Component;
import org.bukkit.configuration.file.FileConfiguration;
import javax.inject.Singleton;
import java.util.logging.Level;
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.
*
@ -62,35 +96,38 @@ public class Plan extends BukkitPlugin implements PlanPlugin {
@Override
public void onEnable() {
super.onEnable();
PlanComponent component = DaggerPlanComponent.builder().plan(this).build();
try {
Benchmark.start("Enable");
system = new BukkitSystem(this);
timings.start("Enable");
system = component.system();
locale = system.getLocaleSystem().getLocale();
system.enable();
String debugString = Settings.DEBUG.toString();
// TODO Set debug logger
ImporterManager.registerImporter(new OfflinePlayerImporter());
new BStatsBukkit(this).registerMetrics();
Log.debug("Verbose debug messages are enabled.");
Benchmark.stop("Enable", "Enable");
Log.logDebug("Enable");
Log.info(locale.getString(PluginLang.ENABLED));
logger.debug("Verbose debug messages are enabled.");
String benchTime = " (" + timings.end("Enable").map(Benchmark::toDurationString).orElse("-") + ")";
logger.info(locale.getString(PluginLang.ENABLED) + benchTime);
} 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) {
Log.error("----------------------------------------");
Log.error("Error: " + e.getMessage());
Log.error("----------------------------------------");
Log.error("Plugin Failed to Initialize Correctly. If this issue is caused by config settings you can use /plan reload");
logger.error("----------------------------------------");
logger.error("Error: " + e.getMessage());
logger.error("----------------------------------------");
logger.error("Plugin Failed to Initialize Correctly. If this issue is caused by config settings you can use /plan reload");
onDisable();
} catch (Exception 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");
Log.error("This error should be reported at https://github.com/Rsl1122/Plan-PlayerAnalytics/issues");
logger.error("Plugin Failed to Initialize Correctly. If this issue is caused by config settings you can use /plan reload");
logger.error("This error should be reported at https://github.com/Rsl1122/Plan-PlayerAnalytics/issues");
onDisable();
}
registerCommand("plan", new PlanCommand(this));
registerCommand("plan", component.planCommand());
}
@Override
@ -105,8 +142,7 @@ public class Plan extends BukkitPlugin implements PlanPlugin {
public void onDisable() {
system.disable();
Log.info(locale.getString(PluginLang.DISABLED));
Benchmark.pluginDisabled(Plan.class);
logger.info(locale.getString(PluginLang.DISABLED));
DebugLog.pluginDisabled(Plan.class);
}
@ -165,4 +201,4 @@ public class Plan extends BukkitPlugin implements PlanPlugin {
public BukkitSystem getSystem() {
return system;
}
}
}

View File

@ -4,10 +4,13 @@
*/
package com.djrapitops.plan.api;
import com.djrapitops.plan.data.plugin.HookHandler;
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 javax.inject.Inject;
import java.util.UUID;
/**
@ -17,24 +20,29 @@ import java.util.UUID;
*/
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) {
this.serverSystem = serverSystem;
@Inject
public ServerAPI(HookHandler hookHandler, Database activeDatabase, DataCache dataCache) {
this.hookHandler = hookHandler;
this.activeDatabase = activeDatabase;
this.dataCache = dataCache;
}
@Override
public void addPluginDataSource(PluginData pluginData) {
serverSystem.getHookHandler().addPluginDataSource(pluginData);
hookHandler.addPluginDataSource(pluginData);
}
@Override
public String getPlayerName(UUID uuid) {
return serverSystem.getCacheSystem().getDataCache().getName(uuid);
return dataCache.getName(uuid);
}
@Override
public FetchOperations fetchFromPlanDB() {
return serverSystem.getDatabaseSystem().getActiveDatabase().fetch();
return activeDatabase.fetch();
}
}

View File

@ -23,7 +23,7 @@ public class PluginsConfigSection {
}
private ConfigNode getPluginsSection() {
return ConfigSystem.getConfig().getConfigNode("Plugins");
return ConfigSystem.getConfig_Old().getConfigNode("Plugins");
}
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.data.plugin.HookHandler;
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.info.ServerInfoSystem;
import com.djrapitops.plan.system.info.connection.ServerConnectionSystem;
import com.djrapitops.plan.system.info.server.BukkitServerInfo;
import com.djrapitops.plan.system.listeners.BukkitListenerSystem;
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.api.utility.log.Log;
import javax.inject.Inject;
import java.util.function.Supplier;
/**
@ -32,6 +35,7 @@ import java.util.function.Supplier;
*/
public class BukkitSystem extends PlanSystem implements ServerSystem {
@Inject
public BukkitSystem(Plan plugin) {
setTestSystem(this);
@ -42,15 +46,16 @@ public class BukkitSystem extends PlanSystem implements ServerSystem {
versionCheckSystem = new VersionCheckSystem(plugin.getVersion(), localeSupplier);
fileSystem = new FileSystem(plugin);
configSystem = new ServerConfigSystem();
exportSystem = new ExportSystem(plugin);
databaseSystem = new ServerDBSystem(localeSupplier);
listenerSystem = new BukkitListenerSystem(plugin);
taskSystem = new BukkitTaskSystem(plugin);
infoSystem = new ServerInfoSystem(localeSupplier);
infoSystem = new ServerInfoSystem(new ServerConnectionSystem(localeSupplier));
serverInfo = new BukkitServerInfo(plugin);
hookHandler = new HookHandler();
planAPI = new ServerAPI(this);
planAPI = new ServerAPI(hookHandler, databaseSystem.getActiveDatabase(), cacheSystem.getDataCache());
StaticHolder.saveInstance(ShutdownHook.class, plugin.getClass());
new ShutdownHook().register();
@ -65,4 +70,4 @@ public class BukkitSystem extends PlanSystem implements ServerSystem {
super.enable();
NetworkSettings.loadSettingsFromDB();
}
}
}

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.database.BungeeDBSystem;
import com.djrapitops.plan.system.database.DBSystem;
import com.djrapitops.plan.system.export.ExportSystem;
import com.djrapitops.plan.system.file.FileSystem;
import com.djrapitops.plan.system.info.BungeeInfoSystem;
import com.djrapitops.plan.system.info.server.BungeeServerInfo;
@ -42,10 +43,11 @@ public class BungeeSystem extends PlanSystem {
versionCheckSystem = new VersionCheckSystem(plugin.getVersion(), localeSupplier);
fileSystem = new FileSystem(plugin);
configSystem = new BungeeConfigSystem();
exportSystem = new ExportSystem(plugin);
databaseSystem = new BungeeDBSystem(localeSupplier);
cacheSystem = new BungeeCacheSystem(this);
listenerSystem = new BungeeListenerSystem(plugin);
taskSystem = new BungeeTaskSystem(plugin);
taskSystem = new BungeeTaskSystem(plugin.getRunnableFactory());
infoSystem = new BungeeInfoSystem();
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.system.cache.CacheSystem;
import com.djrapitops.plan.system.database.DBSystem;
import com.djrapitops.plan.system.export.ExportSystem;
import com.djrapitops.plan.system.file.FileSystem;
import com.djrapitops.plan.system.info.InfoSystem;
import com.djrapitops.plan.system.info.server.ServerInfo;
@ -47,6 +48,7 @@ public abstract class PlanSystem implements SubSystem {
protected VersionCheckSystem versionCheckSystem;
protected FileSystem fileSystem;
protected ConfigSystem configSystem;
protected ExportSystem exportSystem;
protected DBSystem databaseSystem;
protected InfoSystem infoSystem;
@ -94,6 +96,7 @@ public abstract class PlanSystem implements SubSystem {
localeSystem,
versionCheckSystem,
databaseSystem,
exportSystem,
webServerSystem,
processing,
serverInfo,
@ -118,6 +121,7 @@ public abstract class PlanSystem implements SubSystem {
hookHandler,
cacheSystem,
listenerSystem,
exportSystem,
processing,
databaseSystem,
webServerSystem,
@ -221,4 +225,4 @@ public abstract class PlanSystem implements SubSystem {
public LocaleSystem getLocaleSystem() {
return localeSystem;
}
}
}

View File

@ -10,6 +10,7 @@ import com.djrapitops.plan.api.ServerAPI;
import com.djrapitops.plan.api.exceptions.EnableException;
import com.djrapitops.plan.data.plugin.HookHandler;
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.info.ServerInfoSystem;
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);
fileSystem = new FileSystem(plugin);
configSystem = new SpongeConfigSystem();
exportSystem = new ExportSystem(plugin);
databaseSystem = new ServerDBSystem(localeSupplier);
listenerSystem = new SpongeListenerSystem(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 File configFile;
@Deprecated
public FileSystem(PlanPlugin plugin) {
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.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.InfoRequest;
import com.djrapitops.plan.system.info.request.SetupRequest;
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.plugin.api.utility.log.Log;
import java.util.function.Supplier;
/**
* InfoSystem for Bukkit servers.
*
@ -24,8 +21,8 @@ import java.util.function.Supplier;
*/
public class ServerInfoSystem extends InfoSystem {
public ServerInfoSystem(Supplier<Locale> locale) {
super(new ServerConnectionSystem(locale));
public ServerInfoSystem(ConnectionSystem connectionSystem) {
super(connectionSystem);
}
@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.utility.log.Log;
import javax.inject.Inject;
import java.util.Optional;
import java.util.UUID;
import java.util.function.Supplier;
@ -35,6 +36,7 @@ public class ServerConnectionSystem extends ConnectionSystem {
private Server mainServer;
@Inject
public ServerConnectionSystem(Supplier<Locale> locale) {
this.locale = locale;
latestServerMapRefresh = 0;

View File

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

View File

@ -143,7 +143,7 @@ public enum Settings {
public static void save() {
try {
ConfigSystem.getConfig().save();
ConfigSystem.getConfig_Old().save();
} catch (IOException e) {
Log.toLog(Settings.class, e);
}
@ -197,7 +197,7 @@ public enum Settings {
}
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!"));
return config;
}

View File

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

View File

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

View File

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

View File

@ -4,14 +4,12 @@
*/
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.EnableConnectionTask;
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.task.RunnableFactory;
import com.google.inject.Inject;
/**
* TaskSystem responsible for registering tasks for Bungee.
@ -20,11 +18,9 @@ import com.djrapitops.plugin.api.TimeAmount;
*/
public class BungeeTaskSystem extends TaskSystem {
private final PlanBungee plugin;
public BungeeTaskSystem(PlanBungee plugin) {
super(plugin, new BungeeTPSCountTimer(plugin));
this.plugin = plugin;
@Inject
public BungeeTaskSystem(RunnableFactory runnableFactory) {
super(runnableFactory, new BungeeTPSCountTimer());
}
@Override
@ -36,8 +32,5 @@ public class BungeeTaskSystem extends TaskSystem {
registerTask(new EnableConnectionTask()).runTaskAsynchronously();
registerTask(tpsCountTimer).runTaskTimerAsynchronously(1000, TimeAmount.SECOND.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;
import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.system.processing.Processing;
import com.djrapitops.plan.system.settings.Settings;
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.utilities.file.export.HtmlExport;
import com.djrapitops.plugin.api.Benchmark;
import com.djrapitops.plugin.api.TimeAmount;
import com.djrapitops.plugin.task.PluginTask;
import com.djrapitops.plugin.task.RunnableFactory;
/**
* Abstracted TaskSystem implementation for both Bukkit and Sponge.
@ -18,12 +16,10 @@ import com.djrapitops.plugin.task.PluginTask;
*/
public class ServerTaskSystem extends TaskSystem {
protected final PlanPlugin plugin;
protected PluginTask bootAnalysisTask;
public ServerTaskSystem(PlanPlugin plugin, TPSCountTimer tpsCountTimer) {
super(plugin, tpsCountTimer);
this.plugin = plugin;
public ServerTaskSystem(RunnableFactory runnableFactory, TPSCountTimer tpsCountTimer) {
super(runnableFactory, tpsCountTimer);
}
@Override
@ -46,9 +42,6 @@ public class ServerTaskSystem extends TaskSystem {
if (analysisRefreshTaskIsEnabled) {
registerTask(new PeriodicAnalysisTask()).runTaskTimerAsynchronously(analysisPeriod, analysisPeriod);
}
if (Settings.ANALYSIS_EXPORT.isTrue()) {
Processing.submitNonCritical(new HtmlExport(plugin));
}
Benchmark.stop("Enable", "Task Registration");
}

View File

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

View File

@ -1,6 +1,5 @@
package com.djrapitops.plan.system.tasks;
import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.data.container.TPS;
import com.djrapitops.plan.system.processing.Processing;
import com.djrapitops.plan.system.processing.processors.TPSInsertProcessor;
@ -15,16 +14,14 @@ import java.util.List;
*
* @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 int latestPlayersOnline = 0;
public TPSCountTimer(T plugin) {
public TPSCountTimer() {
super();
this.plugin = plugin;
history = new ArrayList<>();
}

View File

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

View File

@ -1,16 +1,11 @@
package com.djrapitops.plan.system.tasks.bungee;
import com.djrapitops.plan.PlanBungee;
import com.djrapitops.plan.data.container.TPS;
import com.djrapitops.plan.data.container.builders.TPSBuilder;
import com.djrapitops.plan.system.info.server.ServerInfo;
import com.djrapitops.plan.system.tasks.TPSCountTimer;
public class BungeeTPSCountTimer extends TPSCountTimer<PlanBungee> {
public BungeeTPSCountTimer(PlanBungee plugin) {
super(plugin);
}
public class BungeeTPSCountTimer extends TPSCountTimer {
@Override
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.data.container.TPS;
import com.djrapitops.plan.system.info.server.ServerInfo;
import com.djrapitops.plan.system.tasks.TPSCountTimer;
import com.djrapitops.plugin.api.TimeAmount;
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.OperatingSystemMXBean;
public class BukkitTPSCountTimer extends TPSCountTimer<Plan> {
public class BukkitTPSCountTimer extends TPSCountTimer {
protected final Plan plugin;
private long lastCheckNano;
public BukkitTPSCountTimer(Plan plugin) {
super(plugin);
this.plugin = plugin;
lastCheckNano = -1;
}
@ -48,7 +50,7 @@ public class BukkitTPSCountTimer extends TPSCountTimer<Plan> {
long totalMemory = runtime.totalMemory();
long usedMemory = (totalMemory - runtime.freeMemory()) / 1000000;
int playersOnline = plugin.getServer().getOnlinePlayers().size();
int playersOnline = ServerInfo.getServerProperties().getOnlinePlayers();
latestPlayersOnline = playersOnline;
int loadedChunks = getLoadedChunks();
int entityCount;

View File

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