diff --git a/Plan/bukkit/src/main/java/com/djrapitops/plan/PlanBukkitComponent.java b/Plan/bukkit/src/main/java/com/djrapitops/plan/PlanBukkitComponent.java index b42c4634e..bd53fc348 100644 --- a/Plan/bukkit/src/main/java/com/djrapitops/plan/PlanBukkitComponent.java +++ b/Plan/bukkit/src/main/java/com/djrapitops/plan/PlanBukkitComponent.java @@ -19,7 +19,6 @@ package com.djrapitops.plan; import com.djrapitops.plan.commands.PlanCommand; import com.djrapitops.plan.gathering.ServerShutdownSave; import com.djrapitops.plan.modules.APFModule; -import com.djrapitops.plan.modules.FilesModule; import com.djrapitops.plan.modules.SystemObjectProvidingModule; import com.djrapitops.plan.modules.bukkit.BukkitPlanModule; import com.djrapitops.plan.modules.bukkit.BukkitServerPropertiesModule; @@ -39,7 +38,7 @@ import javax.inject.Singleton; BukkitPlanModule.class, SystemObjectProvidingModule.class, APFModule.class, - FilesModule.class, + BukkitServerPropertiesModule.class, BukkitSuperClassBindingModule.class }) diff --git a/Plan/bungeecord/src/main/java/com/djrapitops/plan/PlanBungeeComponent.java b/Plan/bungeecord/src/main/java/com/djrapitops/plan/PlanBungeeComponent.java index c0bcb8a75..81543eb90 100644 --- a/Plan/bungeecord/src/main/java/com/djrapitops/plan/PlanBungeeComponent.java +++ b/Plan/bungeecord/src/main/java/com/djrapitops/plan/PlanBungeeComponent.java @@ -18,7 +18,6 @@ package com.djrapitops.plan; import com.djrapitops.plan.commands.PlanProxyCommand; import com.djrapitops.plan.modules.APFModule; -import com.djrapitops.plan.modules.FilesModule; import com.djrapitops.plan.modules.ProxySuperClassBindingModule; import com.djrapitops.plan.modules.SystemObjectProvidingModule; import com.djrapitops.plan.modules.bungee.BungeeCommandModule; @@ -41,7 +40,7 @@ import javax.inject.Singleton; BungeeCommandModule.class, SystemObjectProvidingModule.class, APFModule.class, - FilesModule.class, + ProxySuperClassBindingModule.class, BungeeSuperClassBindingModule.class, BungeeServerPropertiesModule.class diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/domain/mutators/SessionsMutator.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/domain/mutators/SessionsMutator.java index 598d8e9f4..bf463359c 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/domain/mutators/SessionsMutator.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/domain/mutators/SessionsMutator.java @@ -196,7 +196,7 @@ public class SessionsMutator { private Predicate getBetweenPredicate(long after, long before) { return session -> { Long start = session.getUnsafe(SessionKeys.START); - Long end = session.getValue(SessionKeys.END).orElse(System.currentTimeMillis()); + long end = session.getValue(SessionKeys.END).orElse(System.currentTimeMillis()); return (after <= start && start <= before) || (after <= end && end <= before); }; } @@ -265,12 +265,16 @@ public class SessionsMutator { ) { return Lists.map(sessions, session -> { Map sessionMap = new HashMap<>(); - sessionMap.put("player_name", session.getValue(SessionKeys.NAME).orElse(session.getUnsafe(SessionKeys.UUID).toString())); - sessionMap.put("player_url_name", Html.encodeToURL((String) sessionMap.get("player_name"))); - sessionMap.put("player_uuid", session.getUnsafe(SessionKeys.UUID).toString()); - sessionMap.put("server_name", session.getValue(SessionKeys.SERVER_NAME).orElse(session.getUnsafe(SessionKeys.SERVER_UUID).toString())); - sessionMap.put("server_url_name", Html.encodeToURL((String) sessionMap.get("server_name"))); - sessionMap.put("server_uuid", session.getUnsafe(SessionKeys.SERVER_UUID).toString()); + String playerUUID = session.getUnsafe(SessionKeys.UUID).toString(); + String serverUUID = session.getUnsafe(SessionKeys.SERVER_UUID).toString(); + String playerName = session.getValue(SessionKeys.NAME).orElse(playerUUID); + String serverName = session.getValue(SessionKeys.SERVER_NAME).orElse(serverUUID); + sessionMap.put("player_name", playerName); + sessionMap.put("player_url_name", Html.encodeToURL(playerName)); + sessionMap.put("player_uuid", playerUUID); + sessionMap.put("server_name", serverName); + sessionMap.put("server_url_name", Html.encodeToURL(serverName)); + sessionMap.put("server_uuid", serverUUID); sessionMap.put("name", nameFunction.apply(sessionMap)); sessionMap.put("start", session.getValue(SessionKeys.START).map(formatters.yearLong()).orElse("-") + (session.supports(SessionKeys.END) ? "" : " (Online)")); diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/export/Exporter.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/export/Exporter.java index 8b0237676..397bc5618 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/export/Exporter.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/export/Exporter.java @@ -22,14 +22,11 @@ import com.djrapitops.plan.exceptions.connection.NotFoundException; import com.djrapitops.plan.identification.Server; import com.djrapitops.plan.settings.config.PlanConfig; import com.djrapitops.plan.settings.config.paths.ExportSettings; -import com.djrapitops.plan.storage.file.PlanFiles; -import com.djrapitops.plugin.logging.console.PluginLogger; import javax.inject.Inject; import javax.inject.Singleton; import java.io.IOException; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.HashSet; import java.util.Set; import java.util.UUID; @@ -42,61 +39,34 @@ import java.util.UUID; @Singleton public class Exporter extends FileExporter { - private final PlanFiles files; private final PlanConfig config; private final PlayerJSONExporter playerJSONExporter; private final PlayerPageExporter playerPageExporter; private final PlayersPageExporter playersPageExporter; private final ServerPageExporter serverPageExporter; private final NetworkPageExporter networkPageExporter; - private final PluginLogger logger; private final Set failedServers; @Inject public Exporter( - PlanFiles files, PlanConfig config, PlayerJSONExporter playerJSONExporter, PlayerPageExporter playerPageExporter, PlayersPageExporter playersPageExporter, ServerPageExporter serverPageExporter, - NetworkPageExporter networkPageExporter, - PluginLogger logger + NetworkPageExporter networkPageExporter ) { - this.files = files; this.config = config; this.playerJSONExporter = playerJSONExporter; this.playerPageExporter = playerPageExporter; this.playersPageExporter = playersPageExporter; this.serverPageExporter = serverPageExporter; this.networkPageExporter = networkPageExporter; - this.logger = logger; failedServers = new HashSet<>(); } - private Path getPageExportDirectory() { - Path exportDirectory = Paths.get(config.get(ExportSettings.HTML_EXPORT_PATH)); - Path webDirectory = files.getDataDirectory().resolve("web"); - - if (exportDirectory.toAbsolutePath().equals(webDirectory.toAbsolutePath())) { - logger.warn("'" + ExportSettings.HTML_EXPORT_PATH.getPath() + "' can not be '/Plan/web/' directory, using '/Plan/Analysis Results' as fallback."); - exportDirectory = files.getDataDirectory().resolve("Analysis Results"); - } - - return exportDirectory.isAbsolute() - ? exportDirectory - : files.getDataDirectory().resolve(exportDirectory); - } - - private Path getJSONExportDirectory() { - Path exportDirectory = Paths.get(config.get(ExportSettings.JSON_EXPORT_PATH)); - return exportDirectory.isAbsolute() - ? exportDirectory - : files.getDataDirectory().resolve(exportDirectory); - } - /** * Export a page of a server. * @@ -109,7 +79,7 @@ public class Exporter extends FileExporter { if (failedServers.contains(serverUUID) || config.isFalse(ExportSettings.SERVER_PAGE)) return false; try { - Path toDirectory = getPageExportDirectory(); + Path toDirectory = config.getPageExportPath(); if (server.isProxy()) { networkPageExporter.export(toDirectory, server); } else { @@ -127,7 +97,7 @@ public class Exporter extends FileExporter { if (failedServers.contains(serverUUID) || config.isFalse(ExportSettings.SERVER_JSON)) return false; try { - Path toDirectory = getJSONExportDirectory().resolve(toFileName(server.getName())); + Path toDirectory = config.getJSONExportPath().resolve(toFileName(server.getName())); if (server.isProxy()) { networkPageExporter.exportJSON(toDirectory, server); } else { @@ -149,7 +119,7 @@ public class Exporter extends FileExporter { * @throws ExportException If the export failed due to IO, NotFound or GenerationException. */ public boolean exportPlayerPage(UUID playerUUID, String playerName) throws ExportException { - Path toDirectory = getPageExportDirectory(); + Path toDirectory = config.getPageExportPath(); if (config.isFalse(ExportSettings.PLAYER_PAGES)) return false; try { @@ -161,7 +131,7 @@ public class Exporter extends FileExporter { } public boolean exportPlayersPage() throws ExportException { - Path toDirectory = getPageExportDirectory(); + Path toDirectory = config.getPageExportPath(); if (config.isFalse(ExportSettings.PLAYERS_PAGE)) return false; try { @@ -181,7 +151,7 @@ public class Exporter extends FileExporter { * @throws ExportException If the export failed due to IOException. */ public boolean exportPlayerJSON(UUID playerUUID, String playerName) throws ExportException { - Path toDirectory = getJSONExportDirectory(); + Path toDirectory = config.getJSONExportPath(); if (config.isFalse(ExportSettings.PLAYER_JSON)) return false; try { diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/json/JSONFactory.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/json/JSONFactory.java index 9ac02bcd4..9c99df557 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/json/JSONFactory.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/json/JSONFactory.java @@ -205,7 +205,7 @@ public class JSONFactory { TPSMutator tpsWeek = tpsMonth.filterDataBetween(weekAgo, now); double averageTPS = tpsWeek.averageTPS(); server.put("avg_tps", averageTPS != -1 ? decimals.apply(averageTPS) : locale.get(HtmlLang.UNIT_NO_DATA).toString()); - server.put("low_tps_spikes", tpsWeek.lowTpsSpikeCount(config.getNumber(DisplaySettings.GRAPH_TPS_THRESHOLD_MED))); + server.put("low_tps_spikes", tpsWeek.lowTpsSpikeCount(config.get(DisplaySettings.GRAPH_TPS_THRESHOLD_MED))); server.put("downtime", timeAmount.apply(tpsWeek.serverDownTime())); Optional online = tpsWeek.getLast(); diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/json/OnlineActivityOverviewJSONCreator.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/json/OnlineActivityOverviewJSONCreator.java index 4c6b1f2cc..178aecb45 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/json/OnlineActivityOverviewJSONCreator.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/json/OnlineActivityOverviewJSONCreator.java @@ -193,7 +193,7 @@ public class OnlineActivityOverviewJSONCreator implements ServerTabJSONCreator. - */ -package com.djrapitops.plan.modules; - -import com.djrapitops.plan.storage.file.PlanFiles; -import dagger.Module; -import dagger.Provides; - -import javax.inject.Named; -import javax.inject.Singleton; -import java.io.File; - -/** - * Dagger Module for the Plan files. - * - * @author Rsl1122 - */ -@Module -public class FilesModule { - - @Provides - @Named("configFile") - @Singleton - File provideConfigFile(PlanFiles files) { - return files.getConfigFile(); - } - -} \ No newline at end of file diff --git a/Plan/common/src/main/java/com/djrapitops/plan/settings/ConfigSystem.java b/Plan/common/src/main/java/com/djrapitops/plan/settings/ConfigSystem.java index 07c6210be..f1367b2c9 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/settings/ConfigSystem.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/settings/ConfigSystem.java @@ -93,7 +93,7 @@ public abstract class ConfigSystem implements SubSystem { } public void checkWrongTimeZone() { - String timeZone = config.getString(FormatSettings.TIMEZONE); + String timeZone = config.get(FormatSettings.TIMEZONE); Optional foundTZ = TimeZoneUtility.parseTimeZone(timeZone); if (!foundTZ.isPresent()) { logger.warn("Config: " + FormatSettings.TIMEZONE.getPath() + " has invalid value '" + timeZone + "', using GMT+0"); diff --git a/Plan/common/src/main/java/com/djrapitops/plan/settings/config/PlanConfig.java b/Plan/common/src/main/java/com/djrapitops/plan/settings/config/PlanConfig.java index 6bb436f85..71590fa2e 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/settings/config/PlanConfig.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/settings/config/PlanConfig.java @@ -16,17 +16,18 @@ */ package com.djrapitops.plan.settings.config; +import com.djrapitops.plan.settings.config.paths.ExportSettings; import com.djrapitops.plan.settings.config.paths.FormatSettings; import com.djrapitops.plan.settings.config.paths.key.Setting; +import com.djrapitops.plan.storage.file.PlanFiles; import com.djrapitops.plugin.logging.console.PluginLogger; import com.djrapitops.plugin.utilities.Verify; import javax.inject.Inject; -import javax.inject.Named; import javax.inject.Singleton; -import java.io.File; +import java.nio.file.Path; +import java.nio.file.Paths; import java.time.ZoneId; -import java.util.List; import java.util.Objects; import java.util.Optional; import java.util.TimeZone; @@ -40,22 +41,23 @@ import java.util.concurrent.TimeUnit; @Singleton public class PlanConfig extends Config { + private final PlanFiles files; private final ExtensionSettings extensionSettings; private final WorldAliasSettings worldAliasSettings; private final PluginLogger logger; @Inject public PlanConfig( - @Named("configFile") File file, + PlanFiles files, WorldAliasSettings worldAliasSettings, PluginLogger logger ) { - super(file); + super(files.getConfigFile()); + this.files = files; + this.extensionSettings = new ExtensionSettings(this); this.worldAliasSettings = worldAliasSettings; this.logger = logger; - - extensionSettings = new ExtensionSettings(this); } public T get(Setting setting) { @@ -83,38 +85,12 @@ public class PlanConfig extends Config { return !isTrue(setting); } - /** - * If the settings is a String, this method should be used. - * - * @return String value of the config setting. - */ - public String getString(Setting setting) { - return get(setting); - } - - /** - * If the settings is a number, this method should be used. - * - * @return Integer value of the config setting - */ - public int getNumber(Setting setting) { - return get(setting); - } - - public List getStringList(Setting> setting) { - return get(setting); - } - - public ConfigNode getConfigNode(Setting setting) { - return get(setting); - } - public void set(Setting setting, T value) { set(setting.getPath(), value); } public TimeZone getTimeZone() { - String timeZone = getString(FormatSettings.TIMEZONE); + String timeZone = get(FormatSettings.TIMEZONE); Optional foundTZ = TimeZoneUtility.parseTimeZone(timeZone); return foundTZ.orElse(TimeZone.getTimeZone(ZoneId.of("UTC"))); } @@ -125,6 +101,27 @@ public class PlanConfig extends Config { return -offset / hourMs; } + public Path getPageExportPath() { + Path exportDirectory = Paths.get(get(ExportSettings.HTML_EXPORT_PATH)); + Path webDirectory = files.getDataDirectory().resolve("web"); + + if (exportDirectory.toAbsolutePath().equals(webDirectory.toAbsolutePath())) { + logger.warn("'" + ExportSettings.HTML_EXPORT_PATH.getPath() + "' can not be '/Plan/web/' directory, using '/Plan/Analysis Results' as fallback."); + exportDirectory = files.getDataDirectory().resolve("Analysis Results"); + } + + return exportDirectory.isAbsolute() + ? exportDirectory + : files.getDataDirectory().resolve(exportDirectory); + } + + public Path getJSONExportPath() { + Path exportDirectory = Paths.get(get(ExportSettings.JSON_EXPORT_PATH)); + return exportDirectory.isAbsolute() + ? exportDirectory + : files.getDataDirectory().resolve(exportDirectory); + } + public ExtensionSettings getExtensionSettings() { return extensionSettings; } diff --git a/Plan/common/src/test/java/utilities/dagger/PlanPluginComponent.java b/Plan/common/src/test/java/utilities/dagger/PlanPluginComponent.java index a8d4f67e1..f37ef2dc5 100644 --- a/Plan/common/src/test/java/utilities/dagger/PlanPluginComponent.java +++ b/Plan/common/src/test/java/utilities/dagger/PlanPluginComponent.java @@ -20,7 +20,6 @@ import com.djrapitops.plan.PlanPlugin; import com.djrapitops.plan.PlanSystem; import com.djrapitops.plan.commands.PlanCommand; import com.djrapitops.plan.modules.APFModule; -import com.djrapitops.plan.modules.FilesModule; import com.djrapitops.plan.modules.SystemObjectProvidingModule; import dagger.BindsInstance; import dagger.Component; @@ -37,7 +36,7 @@ import javax.inject.Singleton; PlanPluginModule.class, SystemObjectProvidingModule.class, APFModule.class, - FilesModule.class, + PluginServerPropertiesModule.class, PluginSuperClassBindingModule.class }) diff --git a/Plan/nukkit/src/main/java/com/djrapitops/plan/PlanNukkitComponent.java b/Plan/nukkit/src/main/java/com/djrapitops/plan/PlanNukkitComponent.java index 8b49517e9..4180dc857 100644 --- a/Plan/nukkit/src/main/java/com/djrapitops/plan/PlanNukkitComponent.java +++ b/Plan/nukkit/src/main/java/com/djrapitops/plan/PlanNukkitComponent.java @@ -19,7 +19,6 @@ package com.djrapitops.plan; import com.djrapitops.plan.commands.PlanCommand; import com.djrapitops.plan.gathering.ServerShutdownSave; import com.djrapitops.plan.modules.APFModule; -import com.djrapitops.plan.modules.FilesModule; import com.djrapitops.plan.modules.SystemObjectProvidingModule; import com.djrapitops.plan.modules.nukkit.NukkitPlanModule; import com.djrapitops.plan.modules.nukkit.NukkitServerPropertiesModule; @@ -39,7 +38,7 @@ import javax.inject.Singleton; NukkitPlanModule.class, SystemObjectProvidingModule.class, APFModule.class, - FilesModule.class, + NukkitServerPropertiesModule.class, NukkitSuperClassBindingModule.class }) diff --git a/Plan/sponge/src/main/java/com/djrapitops/plan/PlanSpongeComponent.java b/Plan/sponge/src/main/java/com/djrapitops/plan/PlanSpongeComponent.java index 687d4a68f..b4d8ce724 100644 --- a/Plan/sponge/src/main/java/com/djrapitops/plan/PlanSpongeComponent.java +++ b/Plan/sponge/src/main/java/com/djrapitops/plan/PlanSpongeComponent.java @@ -19,7 +19,6 @@ package com.djrapitops.plan; import com.djrapitops.plan.commands.PlanCommand; import com.djrapitops.plan.gathering.ServerShutdownSave; import com.djrapitops.plan.modules.APFModule; -import com.djrapitops.plan.modules.FilesModule; import com.djrapitops.plan.modules.SystemObjectProvidingModule; import com.djrapitops.plan.modules.sponge.SpongePlanModule; import com.djrapitops.plan.modules.sponge.SpongeServerPropertiesModule; @@ -39,7 +38,7 @@ import javax.inject.Singleton; SpongePlanModule.class, SystemObjectProvidingModule.class, APFModule.class, - FilesModule.class, + SpongeSuperClassBindingModule.class, SpongeServerPropertiesModule.class }) diff --git a/Plan/velocity/src/main/java/com/djrapitops/plan/PlanVelocityComponent.java b/Plan/velocity/src/main/java/com/djrapitops/plan/PlanVelocityComponent.java index a29dc442c..b6b2b3eef 100644 --- a/Plan/velocity/src/main/java/com/djrapitops/plan/PlanVelocityComponent.java +++ b/Plan/velocity/src/main/java/com/djrapitops/plan/PlanVelocityComponent.java @@ -18,7 +18,6 @@ package com.djrapitops.plan; import com.djrapitops.plan.commands.PlanProxyCommand; import com.djrapitops.plan.modules.APFModule; -import com.djrapitops.plan.modules.FilesModule; import com.djrapitops.plan.modules.ProxySuperClassBindingModule; import com.djrapitops.plan.modules.SystemObjectProvidingModule; import com.djrapitops.plan.modules.velocity.VelocityCommandModule; @@ -41,7 +40,7 @@ import javax.inject.Singleton; VelocityCommandModule.class, SystemObjectProvidingModule.class, APFModule.class, - FilesModule.class, + ProxySuperClassBindingModule.class, VelocitySuperClassBindingModule.class, VelocityServerPropertiesModule.class