2018-01-11 15:19:30 +01:00
|
|
|
/*
|
2018-10-28 09:10:56 +01:00
|
|
|
* This file is part of Player Analytics (Plan).
|
|
|
|
*
|
|
|
|
* Plan is free software: you can redistribute it and/or modify
|
2018-11-11 19:55:11 +01:00
|
|
|
* it under the terms of the GNU Lesser General Public License v3 as published by
|
2018-10-28 09:10:56 +01:00
|
|
|
* 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
|
2018-11-11 19:55:11 +01:00
|
|
|
* GNU Lesser General Public License for more details.
|
2018-10-28 09:10:56 +01:00
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
|
2018-01-11 15:19:30 +01:00
|
|
|
*/
|
2019-08-30 22:14:54 +02:00
|
|
|
package com.djrapitops.plan;
|
2018-01-11 15:19:30 +01:00
|
|
|
|
2019-09-08 19:36:10 +02:00
|
|
|
import com.djrapitops.plan.api.PlanAPI;
|
2019-08-30 22:14:54 +02:00
|
|
|
import com.djrapitops.plan.delivery.DeliveryUtilities;
|
|
|
|
import com.djrapitops.plan.delivery.export.ExportSystem;
|
2022-02-02 16:36:20 +01:00
|
|
|
import com.djrapitops.plan.delivery.formatting.Formatters;
|
2019-09-21 11:17:04 +02:00
|
|
|
import com.djrapitops.plan.delivery.webserver.NonProxyWebserverDisableChecker;
|
2019-08-30 22:14:54 +02:00
|
|
|
import com.djrapitops.plan.delivery.webserver.WebServerSystem;
|
|
|
|
import com.djrapitops.plan.gathering.cache.CacheSystem;
|
|
|
|
import com.djrapitops.plan.gathering.importing.ImportSystem;
|
|
|
|
import com.djrapitops.plan.gathering.listeners.ListenerSystem;
|
|
|
|
import com.djrapitops.plan.identification.ServerInfo;
|
|
|
|
import com.djrapitops.plan.processing.Processing;
|
|
|
|
import com.djrapitops.plan.settings.ConfigSystem;
|
|
|
|
import com.djrapitops.plan.settings.locale.LocaleSystem;
|
|
|
|
import com.djrapitops.plan.storage.database.DBSystem;
|
|
|
|
import com.djrapitops.plan.storage.file.PlanFiles;
|
2020-05-15 11:20:29 +02:00
|
|
|
import com.djrapitops.plan.utilities.logging.ErrorContext;
|
2020-05-14 15:57:29 +02:00
|
|
|
import com.djrapitops.plan.utilities.logging.ErrorLogger;
|
2020-03-02 12:43:30 +01:00
|
|
|
import com.djrapitops.plan.version.VersionChecker;
|
2021-03-09 10:36:07 +01:00
|
|
|
import net.playeranalytics.plugin.server.PluginLogger;
|
2018-01-11 15:19:30 +01:00
|
|
|
|
2018-08-23 12:56:24 +02:00
|
|
|
import javax.inject.Inject;
|
|
|
|
import javax.inject.Singleton;
|
2018-07-29 08:39:08 +02:00
|
|
|
|
2018-01-11 15:19:30 +01:00
|
|
|
/**
|
|
|
|
* PlanSystem contains everything Plan needs to run.
|
|
|
|
* <p>
|
|
|
|
* This is an abstraction layer on top of Plugin instances so that tests can be run with less mocks.
|
|
|
|
*
|
2021-02-13 14:16:03 +01:00
|
|
|
* @author AuroraLS3
|
2018-01-11 15:19:30 +01:00
|
|
|
*/
|
2018-08-23 12:56:24 +02:00
|
|
|
@Singleton
|
|
|
|
public class PlanSystem implements SubSystem {
|
|
|
|
|
2021-07-18 09:43:38 +02:00
|
|
|
private static final long SERVER_ENABLE_TIME = System.currentTimeMillis();
|
|
|
|
|
2018-12-18 17:01:58 +01:00
|
|
|
private boolean enabled = false;
|
|
|
|
|
2018-09-29 11:44:56 +02:00
|
|
|
private final PlanFiles files;
|
2018-08-23 12:56:24 +02:00
|
|
|
private final ConfigSystem configSystem;
|
2020-03-02 12:43:30 +01:00
|
|
|
private final VersionChecker versionChecker;
|
2018-08-23 12:56:24 +02:00
|
|
|
private final LocaleSystem localeSystem;
|
|
|
|
private final DBSystem databaseSystem;
|
|
|
|
private final CacheSystem cacheSystem;
|
|
|
|
private final ListenerSystem listenerSystem;
|
|
|
|
private final TaskSystem taskSystem;
|
|
|
|
private final ServerInfo serverInfo;
|
|
|
|
private final WebServerSystem webServerSystem;
|
|
|
|
|
|
|
|
private final Processing processing;
|
|
|
|
|
2018-09-09 13:26:02 +02:00
|
|
|
private final ImportSystem importSystem;
|
2018-08-23 12:56:24 +02:00
|
|
|
private final ExportSystem exportSystem;
|
2019-08-30 11:36:38 +02:00
|
|
|
private final DeliveryUtilities deliveryUtilities;
|
2024-03-09 13:43:41 +01:00
|
|
|
private final ApiServices apiServices;
|
2019-09-21 11:17:04 +02:00
|
|
|
private final PluginLogger logger;
|
2020-05-14 15:57:29 +02:00
|
|
|
private final ErrorLogger errorLogger;
|
2018-08-23 12:56:24 +02:00
|
|
|
|
|
|
|
@Inject
|
|
|
|
public PlanSystem(
|
2018-09-29 11:44:56 +02:00
|
|
|
PlanFiles files,
|
2018-08-23 12:56:24 +02:00
|
|
|
ConfigSystem configSystem,
|
2020-03-02 12:43:30 +01:00
|
|
|
VersionChecker versionChecker,
|
2018-08-23 12:56:24 +02:00
|
|
|
LocaleSystem localeSystem,
|
|
|
|
DBSystem databaseSystem,
|
|
|
|
CacheSystem cacheSystem,
|
|
|
|
ListenerSystem listenerSystem,
|
|
|
|
TaskSystem taskSystem,
|
|
|
|
ServerInfo serverInfo,
|
|
|
|
WebServerSystem webServerSystem,
|
2018-08-29 09:58:29 +02:00
|
|
|
Processing processing,
|
2018-09-09 13:26:02 +02:00
|
|
|
ImportSystem importSystem,
|
2018-08-23 12:56:24 +02:00
|
|
|
ExportSystem exportSystem,
|
2019-08-30 11:36:38 +02:00
|
|
|
DeliveryUtilities deliveryUtilities,
|
2019-09-21 11:17:04 +02:00
|
|
|
PluginLogger logger,
|
2020-05-14 15:57:29 +02:00
|
|
|
ErrorLogger errorLogger,
|
2024-03-09 13:43:41 +01:00
|
|
|
ApiServices apiServices, // API v5
|
2023-09-24 07:39:01 +02:00
|
|
|
@SuppressWarnings("deprecation") PlanAPI.PlanAPIHolder apiHolder // Deprecated PlanAPI, backwards compatibility
|
2018-08-23 12:56:24 +02:00
|
|
|
) {
|
2018-09-29 11:44:56 +02:00
|
|
|
this.files = files;
|
2018-08-23 12:56:24 +02:00
|
|
|
this.configSystem = configSystem;
|
2020-03-02 12:43:30 +01:00
|
|
|
this.versionChecker = versionChecker;
|
2018-08-23 09:20:58 +02:00
|
|
|
this.localeSystem = localeSystem;
|
2018-08-23 12:56:24 +02:00
|
|
|
this.databaseSystem = databaseSystem;
|
|
|
|
this.cacheSystem = cacheSystem;
|
|
|
|
this.listenerSystem = listenerSystem;
|
|
|
|
this.taskSystem = taskSystem;
|
|
|
|
this.serverInfo = serverInfo;
|
|
|
|
this.webServerSystem = webServerSystem;
|
2018-08-29 09:58:29 +02:00
|
|
|
this.processing = processing;
|
2018-09-09 13:26:02 +02:00
|
|
|
this.importSystem = importSystem;
|
2018-08-23 12:56:24 +02:00
|
|
|
this.exportSystem = exportSystem;
|
2019-08-30 11:36:38 +02:00
|
|
|
this.deliveryUtilities = deliveryUtilities;
|
2019-09-21 11:17:04 +02:00
|
|
|
this.logger = logger;
|
2020-05-14 15:57:29 +02:00
|
|
|
this.errorLogger = errorLogger;
|
2024-03-09 13:43:41 +01:00
|
|
|
this.apiServices = apiServices;
|
2019-09-21 16:06:27 +02:00
|
|
|
|
2022-05-07 08:59:23 +02:00
|
|
|
logger.info("§2");
|
2021-03-09 10:36:07 +01:00
|
|
|
logger.info("§2 ██▌");
|
|
|
|
logger.info("§2 ██▌ ██▌");
|
|
|
|
logger.info("§2 ██▌██▌██▌██▌ §2Player Analytics");
|
|
|
|
logger.info("§2 ██▌██▌██▌██▌ §fv" + versionChecker.getCurrentVersion());
|
2022-05-07 08:59:23 +02:00
|
|
|
logger.info("§2");
|
2018-01-11 15:19:30 +01:00
|
|
|
}
|
|
|
|
|
2022-05-29 16:08:50 +02:00
|
|
|
/**
|
|
|
|
* Enables only the systems that are required for {@link com.djrapitops.plan.commands.PlanCommand}.
|
2022-07-15 07:21:23 +02:00
|
|
|
*
|
2022-05-29 16:08:50 +02:00
|
|
|
* @see #enableOtherThanCommands()
|
|
|
|
*/
|
|
|
|
public void enableForCommands() {
|
|
|
|
enableSystems(configSystem);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enables the rest of the systems that are not enabled in {@link #enableForCommands()}.
|
|
|
|
*/
|
|
|
|
public void enableOtherThanCommands() {
|
2024-03-09 13:43:41 +01:00
|
|
|
apiServices.register();
|
2020-02-12 22:53:02 +01:00
|
|
|
|
2018-08-06 10:21:33 +02:00
|
|
|
enableSystems(
|
2023-08-20 10:56:13 +02:00
|
|
|
processing,
|
2018-09-29 11:44:56 +02:00
|
|
|
files,
|
2018-07-28 17:31:07 +02:00
|
|
|
localeSystem,
|
2020-03-02 12:43:30 +01:00
|
|
|
versionChecker,
|
2018-01-13 13:15:35 +01:00
|
|
|
databaseSystem,
|
2019-04-23 18:51:07 +02:00
|
|
|
webServerSystem,
|
2018-01-18 16:26:37 +01:00
|
|
|
serverInfo,
|
2019-04-23 18:15:18 +02:00
|
|
|
importSystem,
|
|
|
|
exportSystem,
|
2018-01-17 10:10:28 +01:00
|
|
|
cacheSystem,
|
2018-01-13 13:15:35 +01:00
|
|
|
listenerSystem,
|
2019-08-14 17:42:58 +02:00
|
|
|
taskSystem
|
2018-08-06 10:21:33 +02:00
|
|
|
);
|
2019-09-21 11:17:04 +02:00
|
|
|
|
|
|
|
// Disables Webserver if Proxy is detected in the database
|
|
|
|
if (serverInfo.getServer().isNotProxy()) {
|
|
|
|
processing.submitNonCritical(new NonProxyWebserverDisableChecker(
|
2023-10-10 09:03:50 +02:00
|
|
|
configSystem.getConfig(), localeSystem.getLocale(), webServerSystem.getAddresses(), webServerSystem, logger, errorLogger
|
2019-09-21 11:17:04 +02:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2024-03-09 13:43:41 +01:00
|
|
|
apiServices.registerExtensions();
|
2018-12-18 17:01:58 +01:00
|
|
|
enabled = true;
|
2022-05-07 08:59:23 +02:00
|
|
|
|
|
|
|
String javaVersion = System.getProperty("java.specification.version");
|
|
|
|
if ("1.8".equals(javaVersion) || "9".equals(javaVersion) || "10".equals(javaVersion)
|
|
|
|
) {
|
|
|
|
logger.warn("! ------- Deprecation warning ------- !");
|
|
|
|
logger.warn("Plan version 5.5 will require Java 11 or newer,");
|
|
|
|
logger.warn("consider updating your JVM as soon as possible.");
|
|
|
|
logger.warn("! ----------------------------------- !");
|
|
|
|
}
|
2018-08-06 10:21:33 +02:00
|
|
|
}
|
|
|
|
|
2022-05-29 16:08:50 +02:00
|
|
|
@Override
|
|
|
|
public void enable() {
|
|
|
|
enableForCommands();
|
|
|
|
enableOtherThanCommands();
|
|
|
|
}
|
|
|
|
|
2020-11-05 22:16:01 +01:00
|
|
|
private void enableSystems(SubSystem... systems) {
|
2018-01-13 13:15:35 +01:00
|
|
|
for (SubSystem system : systems) {
|
|
|
|
system.enable();
|
|
|
|
}
|
2018-01-11 15:19:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void disable() {
|
2018-12-18 17:01:58 +01:00
|
|
|
enabled = false;
|
2022-02-02 16:36:20 +01:00
|
|
|
Formatters.clearSingleton();
|
2022-07-15 07:49:48 +02:00
|
|
|
|
2024-03-09 13:43:41 +01:00
|
|
|
apiServices.disableExtensionDataUpdates();
|
2022-07-15 07:49:48 +02:00
|
|
|
|
2018-08-06 10:21:33 +02:00
|
|
|
disableSystems(
|
2018-02-10 10:00:53 +01:00
|
|
|
taskSystem,
|
2018-01-17 10:10:28 +01:00
|
|
|
cacheSystem,
|
2018-01-13 13:15:35 +01:00
|
|
|
listenerSystem,
|
2018-11-21 09:02:57 +01:00
|
|
|
importSystem,
|
2018-08-18 20:53:33 +02:00
|
|
|
exportSystem,
|
2018-04-01 12:53:33 +02:00
|
|
|
processing,
|
2018-01-13 13:15:35 +01:00
|
|
|
databaseSystem,
|
2018-01-17 10:10:28 +01:00
|
|
|
webServerSystem,
|
2018-01-18 16:26:37 +01:00
|
|
|
serverInfo,
|
2018-07-28 17:31:07 +02:00
|
|
|
localeSystem,
|
2018-01-13 13:15:35 +01:00
|
|
|
configSystem,
|
2018-09-29 11:44:56 +02:00
|
|
|
files,
|
2020-03-02 12:43:30 +01:00
|
|
|
versionChecker
|
2018-08-06 10:21:33 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void disableSystems(SubSystem... systems) {
|
2018-01-13 13:15:35 +01:00
|
|
|
for (SubSystem system : systems) {
|
2018-01-27 16:30:44 +01:00
|
|
|
try {
|
|
|
|
if (system != null) {
|
|
|
|
system.disable();
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
2021-03-09 10:36:07 +01:00
|
|
|
errorLogger.warn(e, ErrorContext.builder().related("Disabling PlanSystem: " + system).build());
|
2018-01-13 13:15:35 +01:00
|
|
|
}
|
|
|
|
}
|
2018-01-11 15:19:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Accessor methods.
|
|
|
|
|
2020-03-02 12:43:30 +01:00
|
|
|
public VersionChecker getVersionChecker() {
|
|
|
|
return versionChecker;
|
2018-01-11 15:19:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public ConfigSystem getConfigSystem() {
|
|
|
|
return configSystem;
|
|
|
|
}
|
|
|
|
|
2018-09-24 18:41:11 +02:00
|
|
|
public PlanFiles getPlanFiles() {
|
2018-09-29 11:44:56 +02:00
|
|
|
return files;
|
2018-01-11 15:19:30 +01:00
|
|
|
}
|
2018-01-13 12:12:49 +01:00
|
|
|
|
|
|
|
public DBSystem getDatabaseSystem() {
|
|
|
|
return databaseSystem;
|
|
|
|
}
|
2018-01-13 12:46:32 +01:00
|
|
|
|
|
|
|
public ListenerSystem getListenerSystem() {
|
|
|
|
return listenerSystem;
|
|
|
|
}
|
2018-01-13 12:51:52 +01:00
|
|
|
|
|
|
|
public TaskSystem getTaskSystem() {
|
|
|
|
return taskSystem;
|
|
|
|
}
|
2018-01-15 19:15:44 +01:00
|
|
|
|
|
|
|
public WebServerSystem getWebServerSystem() {
|
|
|
|
return webServerSystem;
|
|
|
|
}
|
|
|
|
|
2018-09-09 13:26:02 +02:00
|
|
|
public ImportSystem getImportSystem() {
|
|
|
|
return importSystem;
|
|
|
|
}
|
|
|
|
|
|
|
|
public ExportSystem getExportSystem() {
|
|
|
|
return exportSystem;
|
|
|
|
}
|
|
|
|
|
2018-01-15 19:15:44 +01:00
|
|
|
public ServerInfo getServerInfo() {
|
2018-01-18 16:26:37 +01:00
|
|
|
return serverInfo;
|
2018-01-15 19:15:44 +01:00
|
|
|
}
|
2018-01-17 10:10:28 +01:00
|
|
|
|
|
|
|
public CacheSystem getCacheSystem() {
|
|
|
|
return cacheSystem;
|
|
|
|
}
|
|
|
|
|
2018-04-01 12:53:33 +02:00
|
|
|
public Processing getProcessing() {
|
|
|
|
return processing;
|
|
|
|
}
|
2018-05-25 11:26:14 +02:00
|
|
|
|
2018-07-28 17:31:07 +02:00
|
|
|
public LocaleSystem getLocaleSystem() {
|
|
|
|
return localeSystem;
|
|
|
|
}
|
2018-11-11 19:50:46 +01:00
|
|
|
|
2019-08-30 11:36:38 +02:00
|
|
|
public DeliveryUtilities getDeliveryUtilities() {
|
|
|
|
return deliveryUtilities;
|
2018-11-11 19:50:46 +01:00
|
|
|
}
|
2018-12-18 17:01:58 +01:00
|
|
|
|
|
|
|
public boolean isEnabled() {
|
2018-12-20 12:50:40 +01:00
|
|
|
return enabled;
|
2018-12-18 17:01:58 +01:00
|
|
|
}
|
2019-03-20 16:17:23 +01:00
|
|
|
|
2024-03-09 13:43:41 +01:00
|
|
|
public ApiServices getApiServices() {
|
|
|
|
return apiServices;
|
2022-10-29 07:23:16 +02:00
|
|
|
}
|
|
|
|
|
2021-07-18 09:43:38 +02:00
|
|
|
public static long getServerEnableTime() {
|
|
|
|
return SERVER_ENABLE_TIME;
|
|
|
|
}
|
2022-05-29 16:08:50 +02:00
|
|
|
}
|