mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-06 16:37:58 +01:00
Fixed new sonar smells
- Reduced constructor parameters in Exporter - Removed Throwable#printStackTrace calls - Cleaned up SessionsMutator#toJSONMaps a little - Replaced uses of getString/Number/ methods of PlanConfig with PlanConfig#get
This commit is contained in:
parent
a5219dd901
commit
8dcfd3ad9a
@ -19,7 +19,6 @@ package com.djrapitops.plan;
|
|||||||
import com.djrapitops.plan.commands.PlanCommand;
|
import com.djrapitops.plan.commands.PlanCommand;
|
||||||
import com.djrapitops.plan.gathering.ServerShutdownSave;
|
import com.djrapitops.plan.gathering.ServerShutdownSave;
|
||||||
import com.djrapitops.plan.modules.APFModule;
|
import com.djrapitops.plan.modules.APFModule;
|
||||||
import com.djrapitops.plan.modules.FilesModule;
|
|
||||||
import com.djrapitops.plan.modules.SystemObjectProvidingModule;
|
import com.djrapitops.plan.modules.SystemObjectProvidingModule;
|
||||||
import com.djrapitops.plan.modules.bukkit.BukkitPlanModule;
|
import com.djrapitops.plan.modules.bukkit.BukkitPlanModule;
|
||||||
import com.djrapitops.plan.modules.bukkit.BukkitServerPropertiesModule;
|
import com.djrapitops.plan.modules.bukkit.BukkitServerPropertiesModule;
|
||||||
@ -39,7 +38,7 @@ import javax.inject.Singleton;
|
|||||||
BukkitPlanModule.class,
|
BukkitPlanModule.class,
|
||||||
SystemObjectProvidingModule.class,
|
SystemObjectProvidingModule.class,
|
||||||
APFModule.class,
|
APFModule.class,
|
||||||
FilesModule.class,
|
|
||||||
BukkitServerPropertiesModule.class,
|
BukkitServerPropertiesModule.class,
|
||||||
BukkitSuperClassBindingModule.class
|
BukkitSuperClassBindingModule.class
|
||||||
})
|
})
|
||||||
|
@ -18,7 +18,6 @@ package com.djrapitops.plan;
|
|||||||
|
|
||||||
import com.djrapitops.plan.commands.PlanProxyCommand;
|
import com.djrapitops.plan.commands.PlanProxyCommand;
|
||||||
import com.djrapitops.plan.modules.APFModule;
|
import com.djrapitops.plan.modules.APFModule;
|
||||||
import com.djrapitops.plan.modules.FilesModule;
|
|
||||||
import com.djrapitops.plan.modules.ProxySuperClassBindingModule;
|
import com.djrapitops.plan.modules.ProxySuperClassBindingModule;
|
||||||
import com.djrapitops.plan.modules.SystemObjectProvidingModule;
|
import com.djrapitops.plan.modules.SystemObjectProvidingModule;
|
||||||
import com.djrapitops.plan.modules.bungee.BungeeCommandModule;
|
import com.djrapitops.plan.modules.bungee.BungeeCommandModule;
|
||||||
@ -41,7 +40,7 @@ import javax.inject.Singleton;
|
|||||||
BungeeCommandModule.class,
|
BungeeCommandModule.class,
|
||||||
SystemObjectProvidingModule.class,
|
SystemObjectProvidingModule.class,
|
||||||
APFModule.class,
|
APFModule.class,
|
||||||
FilesModule.class,
|
|
||||||
ProxySuperClassBindingModule.class,
|
ProxySuperClassBindingModule.class,
|
||||||
BungeeSuperClassBindingModule.class,
|
BungeeSuperClassBindingModule.class,
|
||||||
BungeeServerPropertiesModule.class
|
BungeeServerPropertiesModule.class
|
||||||
|
@ -196,7 +196,7 @@ public class SessionsMutator {
|
|||||||
private Predicate<Session> getBetweenPredicate(long after, long before) {
|
private Predicate<Session> getBetweenPredicate(long after, long before) {
|
||||||
return session -> {
|
return session -> {
|
||||||
Long start = session.getUnsafe(SessionKeys.START);
|
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);
|
return (after <= start && start <= before) || (after <= end && end <= before);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -265,12 +265,16 @@ public class SessionsMutator {
|
|||||||
) {
|
) {
|
||||||
return Lists.map(sessions, session -> {
|
return Lists.map(sessions, session -> {
|
||||||
Map<String, Object> sessionMap = new HashMap<>();
|
Map<String, Object> sessionMap = new HashMap<>();
|
||||||
sessionMap.put("player_name", session.getValue(SessionKeys.NAME).orElse(session.getUnsafe(SessionKeys.UUID).toString()));
|
String playerUUID = session.getUnsafe(SessionKeys.UUID).toString();
|
||||||
sessionMap.put("player_url_name", Html.encodeToURL((String) sessionMap.get("player_name")));
|
String serverUUID = session.getUnsafe(SessionKeys.SERVER_UUID).toString();
|
||||||
sessionMap.put("player_uuid", session.getUnsafe(SessionKeys.UUID).toString());
|
String playerName = session.getValue(SessionKeys.NAME).orElse(playerUUID);
|
||||||
sessionMap.put("server_name", session.getValue(SessionKeys.SERVER_NAME).orElse(session.getUnsafe(SessionKeys.SERVER_UUID).toString()));
|
String serverName = session.getValue(SessionKeys.SERVER_NAME).orElse(serverUUID);
|
||||||
sessionMap.put("server_url_name", Html.encodeToURL((String) sessionMap.get("server_name")));
|
sessionMap.put("player_name", playerName);
|
||||||
sessionMap.put("server_uuid", session.getUnsafe(SessionKeys.SERVER_UUID).toString());
|
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("name", nameFunction.apply(sessionMap));
|
||||||
sessionMap.put("start", session.getValue(SessionKeys.START).map(formatters.yearLong()).orElse("-") +
|
sessionMap.put("start", session.getValue(SessionKeys.START).map(formatters.yearLong()).orElse("-") +
|
||||||
(session.supports(SessionKeys.END) ? "" : " (Online)"));
|
(session.supports(SessionKeys.END) ? "" : " (Online)"));
|
||||||
|
@ -22,14 +22,11 @@ import com.djrapitops.plan.exceptions.connection.NotFoundException;
|
|||||||
import com.djrapitops.plan.identification.Server;
|
import com.djrapitops.plan.identification.Server;
|
||||||
import com.djrapitops.plan.settings.config.PlanConfig;
|
import com.djrapitops.plan.settings.config.PlanConfig;
|
||||||
import com.djrapitops.plan.settings.config.paths.ExportSettings;
|
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.Inject;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -42,61 +39,34 @@ import java.util.UUID;
|
|||||||
@Singleton
|
@Singleton
|
||||||
public class Exporter extends FileExporter {
|
public class Exporter extends FileExporter {
|
||||||
|
|
||||||
private final PlanFiles files;
|
|
||||||
private final PlanConfig config;
|
private final PlanConfig config;
|
||||||
private final PlayerJSONExporter playerJSONExporter;
|
private final PlayerJSONExporter playerJSONExporter;
|
||||||
private final PlayerPageExporter playerPageExporter;
|
private final PlayerPageExporter playerPageExporter;
|
||||||
private final PlayersPageExporter playersPageExporter;
|
private final PlayersPageExporter playersPageExporter;
|
||||||
private final ServerPageExporter serverPageExporter;
|
private final ServerPageExporter serverPageExporter;
|
||||||
private final NetworkPageExporter networkPageExporter;
|
private final NetworkPageExporter networkPageExporter;
|
||||||
private final PluginLogger logger;
|
|
||||||
|
|
||||||
private final Set<UUID> failedServers;
|
private final Set<UUID> failedServers;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public Exporter(
|
public Exporter(
|
||||||
PlanFiles files,
|
|
||||||
PlanConfig config,
|
PlanConfig config,
|
||||||
PlayerJSONExporter playerJSONExporter,
|
PlayerJSONExporter playerJSONExporter,
|
||||||
PlayerPageExporter playerPageExporter,
|
PlayerPageExporter playerPageExporter,
|
||||||
PlayersPageExporter playersPageExporter,
|
PlayersPageExporter playersPageExporter,
|
||||||
ServerPageExporter serverPageExporter,
|
ServerPageExporter serverPageExporter,
|
||||||
NetworkPageExporter networkPageExporter,
|
NetworkPageExporter networkPageExporter
|
||||||
PluginLogger logger
|
|
||||||
) {
|
) {
|
||||||
this.files = files;
|
|
||||||
this.config = config;
|
this.config = config;
|
||||||
this.playerJSONExporter = playerJSONExporter;
|
this.playerJSONExporter = playerJSONExporter;
|
||||||
this.playerPageExporter = playerPageExporter;
|
this.playerPageExporter = playerPageExporter;
|
||||||
this.playersPageExporter = playersPageExporter;
|
this.playersPageExporter = playersPageExporter;
|
||||||
this.serverPageExporter = serverPageExporter;
|
this.serverPageExporter = serverPageExporter;
|
||||||
this.networkPageExporter = networkPageExporter;
|
this.networkPageExporter = networkPageExporter;
|
||||||
this.logger = logger;
|
|
||||||
|
|
||||||
failedServers = new HashSet<>();
|
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.
|
* 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;
|
if (failedServers.contains(serverUUID) || config.isFalse(ExportSettings.SERVER_PAGE)) return false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Path toDirectory = getPageExportDirectory();
|
Path toDirectory = config.getPageExportPath();
|
||||||
if (server.isProxy()) {
|
if (server.isProxy()) {
|
||||||
networkPageExporter.export(toDirectory, server);
|
networkPageExporter.export(toDirectory, server);
|
||||||
} else {
|
} else {
|
||||||
@ -127,7 +97,7 @@ public class Exporter extends FileExporter {
|
|||||||
if (failedServers.contains(serverUUID) || config.isFalse(ExportSettings.SERVER_JSON)) return false;
|
if (failedServers.contains(serverUUID) || config.isFalse(ExportSettings.SERVER_JSON)) return false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Path toDirectory = getJSONExportDirectory().resolve(toFileName(server.getName()));
|
Path toDirectory = config.getJSONExportPath().resolve(toFileName(server.getName()));
|
||||||
if (server.isProxy()) {
|
if (server.isProxy()) {
|
||||||
networkPageExporter.exportJSON(toDirectory, server);
|
networkPageExporter.exportJSON(toDirectory, server);
|
||||||
} else {
|
} else {
|
||||||
@ -149,7 +119,7 @@ public class Exporter extends FileExporter {
|
|||||||
* @throws ExportException If the export failed due to IO, NotFound or GenerationException.
|
* @throws ExportException If the export failed due to IO, NotFound or GenerationException.
|
||||||
*/
|
*/
|
||||||
public boolean exportPlayerPage(UUID playerUUID, String playerName) throws ExportException {
|
public boolean exportPlayerPage(UUID playerUUID, String playerName) throws ExportException {
|
||||||
Path toDirectory = getPageExportDirectory();
|
Path toDirectory = config.getPageExportPath();
|
||||||
if (config.isFalse(ExportSettings.PLAYER_PAGES)) return false;
|
if (config.isFalse(ExportSettings.PLAYER_PAGES)) return false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -161,7 +131,7 @@ public class Exporter extends FileExporter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean exportPlayersPage() throws ExportException {
|
public boolean exportPlayersPage() throws ExportException {
|
||||||
Path toDirectory = getPageExportDirectory();
|
Path toDirectory = config.getPageExportPath();
|
||||||
if (config.isFalse(ExportSettings.PLAYERS_PAGE)) return false;
|
if (config.isFalse(ExportSettings.PLAYERS_PAGE)) return false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -181,7 +151,7 @@ public class Exporter extends FileExporter {
|
|||||||
* @throws ExportException If the export failed due to IOException.
|
* @throws ExportException If the export failed due to IOException.
|
||||||
*/
|
*/
|
||||||
public boolean exportPlayerJSON(UUID playerUUID, String playerName) throws ExportException {
|
public boolean exportPlayerJSON(UUID playerUUID, String playerName) throws ExportException {
|
||||||
Path toDirectory = getJSONExportDirectory();
|
Path toDirectory = config.getJSONExportPath();
|
||||||
if (config.isFalse(ExportSettings.PLAYER_JSON)) return false;
|
if (config.isFalse(ExportSettings.PLAYER_JSON)) return false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -205,7 +205,7 @@ public class JSONFactory {
|
|||||||
TPSMutator tpsWeek = tpsMonth.filterDataBetween(weekAgo, now);
|
TPSMutator tpsWeek = tpsMonth.filterDataBetween(weekAgo, now);
|
||||||
double averageTPS = tpsWeek.averageTPS();
|
double averageTPS = tpsWeek.averageTPS();
|
||||||
server.put("avg_tps", averageTPS != -1 ? decimals.apply(averageTPS) : locale.get(HtmlLang.UNIT_NO_DATA).toString());
|
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()));
|
server.put("downtime", timeAmount.apply(tpsWeek.serverDownTime()));
|
||||||
|
|
||||||
Optional<TPS> online = tpsWeek.getLast();
|
Optional<TPS> online = tpsWeek.getLast();
|
||||||
|
@ -193,7 +193,7 @@ public class OnlineActivityOverviewJSONCreator implements ServerTabJSONCreator<M
|
|||||||
|
|
||||||
TPSMutator tpsMutator = new TPSMutator(db.query(TPSQueries.fetchTPSDataOfServer(monthAgo, now, serverUUID)));
|
TPSMutator tpsMutator = new TPSMutator(db.query(TPSQueries.fetchTPSDataOfServer(monthAgo, now, serverUUID)));
|
||||||
numbers.put("average_tps", decimalFormatter.apply(tpsMutator.averageTPS()));
|
numbers.put("average_tps", decimalFormatter.apply(tpsMutator.averageTPS()));
|
||||||
numbers.put("low_tps_spikes", tpsMutator.lowTpsSpikeCount(config.getNumber(DisplaySettings.GRAPH_TPS_THRESHOLD_MED)));
|
numbers.put("low_tps_spikes", tpsMutator.lowTpsSpikeCount(config.get(DisplaySettings.GRAPH_TPS_THRESHOLD_MED)));
|
||||||
numbers.put("downtime", timeAmountFormatter.apply(tpsMutator.serverDownTime()));
|
numbers.put("downtime", timeAmountFormatter.apply(tpsMutator.serverDownTime()));
|
||||||
|
|
||||||
return numbers;
|
return numbers;
|
||||||
|
@ -112,7 +112,7 @@ public class ServerOverviewJSONCreator implements ServerTabJSONCreator<Map<Strin
|
|||||||
TPSMutator tpsMutator = new TPSMutator(db.query(TPSQueries.fetchTPSDataOfServer(weekAgo, now, serverUUID)));
|
TPSMutator tpsMutator = new TPSMutator(db.query(TPSQueries.fetchTPSDataOfServer(weekAgo, now, serverUUID)));
|
||||||
double averageTPS = tpsMutator.averageTPS();
|
double averageTPS = tpsMutator.averageTPS();
|
||||||
sevenDays.put("average_tps", averageTPS != -1 ? decimals.apply(averageTPS) : locale.get(GenericLang.UNAVAILABLE).toString());
|
sevenDays.put("average_tps", averageTPS != -1 ? decimals.apply(averageTPS) : locale.get(GenericLang.UNAVAILABLE).toString());
|
||||||
sevenDays.put("low_tps_spikes", tpsMutator.lowTpsSpikeCount(config.getNumber(DisplaySettings.GRAPH_TPS_THRESHOLD_MED)));
|
sevenDays.put("low_tps_spikes", tpsMutator.lowTpsSpikeCount(config.get(DisplaySettings.GRAPH_TPS_THRESHOLD_MED)));
|
||||||
sevenDays.put("downtime", timeAmount.apply(tpsMutator.serverDownTime()));
|
sevenDays.put("downtime", timeAmount.apply(tpsMutator.serverDownTime()));
|
||||||
|
|
||||||
return sevenDays;
|
return sevenDays;
|
||||||
|
@ -110,7 +110,7 @@ public class RequestHandler implements HttpHandler {
|
|||||||
responseHeaders.set("WWW-Authenticate", response.getHeader("WWW-Authenticate").orElse("Basic realm=\"Plan WebUser (/plan register)\""));
|
responseHeaders.set("WWW-Authenticate", response.getHeader("WWW-Authenticate").orElse("Basic realm=\"Plan WebUser (/plan register)\""));
|
||||||
}
|
}
|
||||||
|
|
||||||
responseHeaders.set("Access-Control-Allow-Origin", config.getString(WebserverSettings.CORS_ALLOW_ORIGIN));
|
responseHeaders.set("Access-Control-Allow-Origin", config.get(WebserverSettings.CORS_ALLOW_ORIGIN));
|
||||||
responseHeaders.set("Access-Control-Allow-Methods", "GET, OPTIONS");
|
responseHeaders.set("Access-Control-Allow-Methods", "GET, OPTIONS");
|
||||||
response.setResponseHeaders(responseHeaders);
|
response.setResponseHeaders(responseHeaders);
|
||||||
response.send(exchange, locale, theme);
|
response.send(exchange, locale, theme);
|
||||||
|
@ -46,7 +46,6 @@ public interface Geolocator {
|
|||||||
InetAddress inetAddress = InetAddress.getByName(address);
|
InetAddress inetAddress = InetAddress.getByName(address);
|
||||||
return getCountry(inetAddress);
|
return getCountry(inetAddress);
|
||||||
} catch (UnknownHostException e) {
|
} catch (UnknownHostException e) {
|
||||||
e.printStackTrace();
|
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,6 @@ public class IP2CGeolocator implements Geolocator {
|
|||||||
try {
|
try {
|
||||||
return readIPFromURL(address);
|
return readIPFromURL(address);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,42 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of Player Analytics (Plan).
|
|
||||||
*
|
|
||||||
* Plan is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Lesser General Public License v3 as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* Plan is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Lesser General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
|
||||||
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -93,7 +93,7 @@ public abstract class ConfigSystem implements SubSystem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void checkWrongTimeZone() {
|
public void checkWrongTimeZone() {
|
||||||
String timeZone = config.getString(FormatSettings.TIMEZONE);
|
String timeZone = config.get(FormatSettings.TIMEZONE);
|
||||||
Optional<TimeZone> foundTZ = TimeZoneUtility.parseTimeZone(timeZone);
|
Optional<TimeZone> foundTZ = TimeZoneUtility.parseTimeZone(timeZone);
|
||||||
if (!foundTZ.isPresent()) {
|
if (!foundTZ.isPresent()) {
|
||||||
logger.warn("Config: " + FormatSettings.TIMEZONE.getPath() + " has invalid value '" + timeZone + "', using GMT+0");
|
logger.warn("Config: " + FormatSettings.TIMEZONE.getPath() + " has invalid value '" + timeZone + "', using GMT+0");
|
||||||
|
@ -16,17 +16,18 @@
|
|||||||
*/
|
*/
|
||||||
package com.djrapitops.plan.settings.config;
|
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.FormatSettings;
|
||||||
import com.djrapitops.plan.settings.config.paths.key.Setting;
|
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.logging.console.PluginLogger;
|
||||||
import com.djrapitops.plugin.utilities.Verify;
|
import com.djrapitops.plugin.utilities.Verify;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
import java.io.File;
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
@ -40,22 +41,23 @@ import java.util.concurrent.TimeUnit;
|
|||||||
@Singleton
|
@Singleton
|
||||||
public class PlanConfig extends Config {
|
public class PlanConfig extends Config {
|
||||||
|
|
||||||
|
private final PlanFiles files;
|
||||||
private final ExtensionSettings extensionSettings;
|
private final ExtensionSettings extensionSettings;
|
||||||
private final WorldAliasSettings worldAliasSettings;
|
private final WorldAliasSettings worldAliasSettings;
|
||||||
private final PluginLogger logger;
|
private final PluginLogger logger;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public PlanConfig(
|
public PlanConfig(
|
||||||
@Named("configFile") File file,
|
PlanFiles files,
|
||||||
WorldAliasSettings worldAliasSettings,
|
WorldAliasSettings worldAliasSettings,
|
||||||
PluginLogger logger
|
PluginLogger logger
|
||||||
) {
|
) {
|
||||||
super(file);
|
super(files.getConfigFile());
|
||||||
|
|
||||||
|
this.files = files;
|
||||||
|
this.extensionSettings = new ExtensionSettings(this);
|
||||||
this.worldAliasSettings = worldAliasSettings;
|
this.worldAliasSettings = worldAliasSettings;
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
|
|
||||||
extensionSettings = new ExtensionSettings(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T> T get(Setting<T> setting) {
|
public <T> T get(Setting<T> setting) {
|
||||||
@ -83,38 +85,12 @@ public class PlanConfig extends Config {
|
|||||||
return !isTrue(setting);
|
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<String> 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<Integer> setting) {
|
|
||||||
return get(setting);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<String> getStringList(Setting<List<String>> setting) {
|
|
||||||
return get(setting);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ConfigNode getConfigNode(Setting<ConfigNode> setting) {
|
|
||||||
return get(setting);
|
|
||||||
}
|
|
||||||
|
|
||||||
public <T> void set(Setting<T> setting, T value) {
|
public <T> void set(Setting<T> setting, T value) {
|
||||||
set(setting.getPath(), value);
|
set(setting.getPath(), value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TimeZone getTimeZone() {
|
public TimeZone getTimeZone() {
|
||||||
String timeZone = getString(FormatSettings.TIMEZONE);
|
String timeZone = get(FormatSettings.TIMEZONE);
|
||||||
Optional<TimeZone> foundTZ = TimeZoneUtility.parseTimeZone(timeZone);
|
Optional<TimeZone> foundTZ = TimeZoneUtility.parseTimeZone(timeZone);
|
||||||
return foundTZ.orElse(TimeZone.getTimeZone(ZoneId.of("UTC")));
|
return foundTZ.orElse(TimeZone.getTimeZone(ZoneId.of("UTC")));
|
||||||
}
|
}
|
||||||
@ -125,6 +101,27 @@ public class PlanConfig extends Config {
|
|||||||
return -offset / hourMs;
|
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() {
|
public ExtensionSettings getExtensionSettings() {
|
||||||
return extensionSettings;
|
return extensionSettings;
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,6 @@ import com.djrapitops.plan.PlanPlugin;
|
|||||||
import com.djrapitops.plan.PlanSystem;
|
import com.djrapitops.plan.PlanSystem;
|
||||||
import com.djrapitops.plan.commands.PlanCommand;
|
import com.djrapitops.plan.commands.PlanCommand;
|
||||||
import com.djrapitops.plan.modules.APFModule;
|
import com.djrapitops.plan.modules.APFModule;
|
||||||
import com.djrapitops.plan.modules.FilesModule;
|
|
||||||
import com.djrapitops.plan.modules.SystemObjectProvidingModule;
|
import com.djrapitops.plan.modules.SystemObjectProvidingModule;
|
||||||
import dagger.BindsInstance;
|
import dagger.BindsInstance;
|
||||||
import dagger.Component;
|
import dagger.Component;
|
||||||
@ -37,7 +36,7 @@ import javax.inject.Singleton;
|
|||||||
PlanPluginModule.class,
|
PlanPluginModule.class,
|
||||||
SystemObjectProvidingModule.class,
|
SystemObjectProvidingModule.class,
|
||||||
APFModule.class,
|
APFModule.class,
|
||||||
FilesModule.class,
|
|
||||||
PluginServerPropertiesModule.class,
|
PluginServerPropertiesModule.class,
|
||||||
PluginSuperClassBindingModule.class
|
PluginSuperClassBindingModule.class
|
||||||
})
|
})
|
||||||
|
@ -19,7 +19,6 @@ package com.djrapitops.plan;
|
|||||||
import com.djrapitops.plan.commands.PlanCommand;
|
import com.djrapitops.plan.commands.PlanCommand;
|
||||||
import com.djrapitops.plan.gathering.ServerShutdownSave;
|
import com.djrapitops.plan.gathering.ServerShutdownSave;
|
||||||
import com.djrapitops.plan.modules.APFModule;
|
import com.djrapitops.plan.modules.APFModule;
|
||||||
import com.djrapitops.plan.modules.FilesModule;
|
|
||||||
import com.djrapitops.plan.modules.SystemObjectProvidingModule;
|
import com.djrapitops.plan.modules.SystemObjectProvidingModule;
|
||||||
import com.djrapitops.plan.modules.nukkit.NukkitPlanModule;
|
import com.djrapitops.plan.modules.nukkit.NukkitPlanModule;
|
||||||
import com.djrapitops.plan.modules.nukkit.NukkitServerPropertiesModule;
|
import com.djrapitops.plan.modules.nukkit.NukkitServerPropertiesModule;
|
||||||
@ -39,7 +38,7 @@ import javax.inject.Singleton;
|
|||||||
NukkitPlanModule.class,
|
NukkitPlanModule.class,
|
||||||
SystemObjectProvidingModule.class,
|
SystemObjectProvidingModule.class,
|
||||||
APFModule.class,
|
APFModule.class,
|
||||||
FilesModule.class,
|
|
||||||
NukkitServerPropertiesModule.class,
|
NukkitServerPropertiesModule.class,
|
||||||
NukkitSuperClassBindingModule.class
|
NukkitSuperClassBindingModule.class
|
||||||
})
|
})
|
||||||
|
@ -19,7 +19,6 @@ package com.djrapitops.plan;
|
|||||||
import com.djrapitops.plan.commands.PlanCommand;
|
import com.djrapitops.plan.commands.PlanCommand;
|
||||||
import com.djrapitops.plan.gathering.ServerShutdownSave;
|
import com.djrapitops.plan.gathering.ServerShutdownSave;
|
||||||
import com.djrapitops.plan.modules.APFModule;
|
import com.djrapitops.plan.modules.APFModule;
|
||||||
import com.djrapitops.plan.modules.FilesModule;
|
|
||||||
import com.djrapitops.plan.modules.SystemObjectProvidingModule;
|
import com.djrapitops.plan.modules.SystemObjectProvidingModule;
|
||||||
import com.djrapitops.plan.modules.sponge.SpongePlanModule;
|
import com.djrapitops.plan.modules.sponge.SpongePlanModule;
|
||||||
import com.djrapitops.plan.modules.sponge.SpongeServerPropertiesModule;
|
import com.djrapitops.plan.modules.sponge.SpongeServerPropertiesModule;
|
||||||
@ -39,7 +38,7 @@ import javax.inject.Singleton;
|
|||||||
SpongePlanModule.class,
|
SpongePlanModule.class,
|
||||||
SystemObjectProvidingModule.class,
|
SystemObjectProvidingModule.class,
|
||||||
APFModule.class,
|
APFModule.class,
|
||||||
FilesModule.class,
|
|
||||||
SpongeSuperClassBindingModule.class,
|
SpongeSuperClassBindingModule.class,
|
||||||
SpongeServerPropertiesModule.class
|
SpongeServerPropertiesModule.class
|
||||||
})
|
})
|
||||||
|
@ -18,7 +18,6 @@ package com.djrapitops.plan;
|
|||||||
|
|
||||||
import com.djrapitops.plan.commands.PlanProxyCommand;
|
import com.djrapitops.plan.commands.PlanProxyCommand;
|
||||||
import com.djrapitops.plan.modules.APFModule;
|
import com.djrapitops.plan.modules.APFModule;
|
||||||
import com.djrapitops.plan.modules.FilesModule;
|
|
||||||
import com.djrapitops.plan.modules.ProxySuperClassBindingModule;
|
import com.djrapitops.plan.modules.ProxySuperClassBindingModule;
|
||||||
import com.djrapitops.plan.modules.SystemObjectProvidingModule;
|
import com.djrapitops.plan.modules.SystemObjectProvidingModule;
|
||||||
import com.djrapitops.plan.modules.velocity.VelocityCommandModule;
|
import com.djrapitops.plan.modules.velocity.VelocityCommandModule;
|
||||||
@ -41,7 +40,7 @@ import javax.inject.Singleton;
|
|||||||
VelocityCommandModule.class,
|
VelocityCommandModule.class,
|
||||||
SystemObjectProvidingModule.class,
|
SystemObjectProvidingModule.class,
|
||||||
APFModule.class,
|
APFModule.class,
|
||||||
FilesModule.class,
|
|
||||||
ProxySuperClassBindingModule.class,
|
ProxySuperClassBindingModule.class,
|
||||||
VelocitySuperClassBindingModule.class,
|
VelocitySuperClassBindingModule.class,
|
||||||
VelocityServerPropertiesModule.class
|
VelocityServerPropertiesModule.class
|
||||||
|
Loading…
Reference in New Issue
Block a user