mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-14 12:11:23 +01:00
Config enable check for DataExtension registration
This commit is contained in:
parent
e8da008538
commit
0c95a4cc63
@ -38,8 +38,11 @@ public class PluginsConfigSection {
|
||||
}
|
||||
|
||||
public boolean hasSection(PluginData dataSource) {
|
||||
return hasSection(dataSource.getSourcePlugin());
|
||||
}
|
||||
|
||||
public boolean hasSection(String pluginName) {
|
||||
ConfigNode section = getPluginsSection();
|
||||
String pluginName = dataSource.getSourcePlugin();
|
||||
return section.getNode(pluginName + ".Enabled").isPresent();
|
||||
}
|
||||
|
||||
@ -49,8 +52,11 @@ public class PluginsConfigSection {
|
||||
}
|
||||
|
||||
public void createSection(PluginData dataSource) throws IOException {
|
||||
createSection(dataSource.getSourcePlugin());
|
||||
}
|
||||
|
||||
public void createSection(String pluginName) throws IOException {
|
||||
ConfigNode section = getPluginsSection();
|
||||
String pluginName = dataSource.getSourcePlugin();
|
||||
|
||||
section.set(pluginName + ".Enabled", true);
|
||||
section.sort();
|
||||
@ -58,9 +64,11 @@ public class PluginsConfigSection {
|
||||
}
|
||||
|
||||
public boolean isEnabled(PluginData dataSource) {
|
||||
ConfigNode section = getPluginsSection();
|
||||
return isEnabled(dataSource.getSourcePlugin());
|
||||
}
|
||||
|
||||
String pluginName = dataSource.getSourcePlugin();
|
||||
public boolean isEnabled(String pluginName) {
|
||||
ConfigNode section = getPluginsSection();
|
||||
return section.getBoolean(pluginName + ".Enabled");
|
||||
}
|
||||
}
|
||||
|
@ -16,17 +16,20 @@
|
||||
*/
|
||||
package com.djrapitops.plan.extension;
|
||||
|
||||
import com.djrapitops.plan.data.plugin.PluginsConfigSection;
|
||||
import com.djrapitops.plan.extension.implementation.DataProviderExtractor;
|
||||
import com.djrapitops.plan.extension.implementation.ExtensionRegister;
|
||||
import com.djrapitops.plan.extension.implementation.providers.gathering.ProviderValueGatherer;
|
||||
import com.djrapitops.plan.system.database.DBSystem;
|
||||
import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
||||
import com.djrapitops.plugin.logging.L;
|
||||
import com.djrapitops.plugin.logging.console.PluginLogger;
|
||||
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
@ -39,6 +42,7 @@ import java.util.UUID;
|
||||
@Singleton
|
||||
public class ExtensionServiceImplementation implements ExtensionService {
|
||||
|
||||
private final PlanConfig config;
|
||||
private final DBSystem dbSystem;
|
||||
private final ServerInfo serverInfo;
|
||||
private final ExtensionRegister extensionRegister;
|
||||
@ -49,12 +53,14 @@ public class ExtensionServiceImplementation implements ExtensionService {
|
||||
|
||||
@Inject
|
||||
public ExtensionServiceImplementation(
|
||||
PlanConfig config,
|
||||
DBSystem dbSystem,
|
||||
ServerInfo serverInfo,
|
||||
ExtensionRegister extensionRegister,
|
||||
PluginLogger logger,
|
||||
ErrorHandler errorHandler
|
||||
) {
|
||||
this.config = config;
|
||||
this.dbSystem = dbSystem;
|
||||
this.serverInfo = serverInfo;
|
||||
this.extensionRegister = extensionRegister;
|
||||
@ -73,14 +79,38 @@ public class ExtensionServiceImplementation implements ExtensionService {
|
||||
@Override
|
||||
public void register(DataExtension extension) {
|
||||
DataProviderExtractor extractor = new DataProviderExtractor(extension);
|
||||
String pluginName = extractor.getPluginName();
|
||||
|
||||
if (shouldNotAllowRegistration(pluginName)) return;
|
||||
|
||||
for (String warning : extractor.getWarnings()) {
|
||||
logger.warn("DataExtension API implementation mistake for " + extractor.getPluginName() + ": " + warning);
|
||||
logger.warn("DataExtension API implementation mistake for " + pluginName + ": " + warning);
|
||||
}
|
||||
|
||||
ProviderValueGatherer gatherer = new ProviderValueGatherer(extension, extractor, dbSystem, serverInfo, logger);
|
||||
gatherer.storeExtensionInformation();
|
||||
extensionGatherers.put(extractor.getPluginName(), gatherer);
|
||||
extensionGatherers.put(pluginName, gatherer);
|
||||
|
||||
logger.debug(pluginName + " extension registered.");
|
||||
}
|
||||
|
||||
private boolean shouldNotAllowRegistration(String pluginName) {
|
||||
PluginsConfigSection pluginsConfig = config.getPluginsConfigSection();
|
||||
if (pluginsConfig.hasSection(pluginName)) {
|
||||
try {
|
||||
pluginsConfig.createSection(pluginName);
|
||||
} catch (IOException e) {
|
||||
errorHandler.log(L.ERROR, this.getClass(), e);
|
||||
logger.warn("Could not register DataExtension for " + pluginName + " due to " + e.toString());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!pluginsConfig.isEnabled(pluginName)) {
|
||||
logger.debug(pluginName + " extension disabled in the config.");
|
||||
return true;
|
||||
}
|
||||
return false; // Should register.
|
||||
}
|
||||
|
||||
public void updatePlayerValues(UUID playerUUID, String playerName) {
|
||||
@ -88,7 +118,11 @@ public class ExtensionServiceImplementation implements ExtensionService {
|
||||
try {
|
||||
gatherer.getValue().updateValues(playerUUID, playerName);
|
||||
} catch (Exception | NoClassDefFoundError | NoSuchMethodError | NoSuchFieldError e) {
|
||||
logger.warn(gatherer.getKey() + " ran into " + e.getClass().getSimpleName() + " when updating value for '" + playerName + "', reason: '" + e.getMessage() + "', stack trace to follow:");
|
||||
logger.warn(gatherer.getKey() + " ran into (but failed safely) " + e.getClass().getSimpleName() +
|
||||
" when updating value for '" + playerName +
|
||||
"', (You can disable integration with setting 'Plugins." + gatherer.getKey() + ".Enabled')" +
|
||||
" reason: '" + e.getMessage() +
|
||||
"', stack trace to follow:");
|
||||
errorHandler.log(L.WARN, gatherer.getValue().getClass(), e);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user