mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-17 21:51:25 +01:00
Renamed DataProviderExtractor to ExtensionWrapper
This makes the purpose of the class more clear, as it has methods that are not related to extracting DataProvider objects.
This commit is contained in:
parent
6a0c25edd5
commit
0a1c20c070
@ -21,8 +21,8 @@ import com.djrapitops.plan.delivery.webserver.cache.DataID;
|
||||
import com.djrapitops.plan.delivery.webserver.cache.JSONCache;
|
||||
import com.djrapitops.plan.exceptions.DataExtensionMethodCallException;
|
||||
import com.djrapitops.plan.extension.implementation.CallerImplementation;
|
||||
import com.djrapitops.plan.extension.implementation.DataProviderExtractor;
|
||||
import com.djrapitops.plan.extension.implementation.ExtensionRegister;
|
||||
import com.djrapitops.plan.extension.implementation.ExtensionWrapper;
|
||||
import com.djrapitops.plan.extension.implementation.providers.gathering.ProviderValueGatherer;
|
||||
import com.djrapitops.plan.identification.ServerInfo;
|
||||
import com.djrapitops.plan.processing.Processing;
|
||||
@ -93,7 +93,7 @@ public class ExtensionServiceImplementation implements ExtensionService {
|
||||
|
||||
@Override
|
||||
public Optional<Caller> register(DataExtension extension) {
|
||||
DataProviderExtractor extractor = new DataProviderExtractor(extension);
|
||||
ExtensionWrapper extractor = new ExtensionWrapper(extension);
|
||||
String pluginName = extractor.getPluginName();
|
||||
|
||||
if (shouldNotAllowRegistration(pluginName)) return Optional.empty();
|
||||
@ -102,7 +102,7 @@ public class ExtensionServiceImplementation implements ExtensionService {
|
||||
logger.warn("DataExtension API implementation mistake for " + pluginName + ": " + warning);
|
||||
}
|
||||
|
||||
ProviderValueGatherer gatherer = new ProviderValueGatherer(extension, extractor, dbSystem, serverInfo);
|
||||
ProviderValueGatherer gatherer = new ProviderValueGatherer(extractor, dbSystem, serverInfo);
|
||||
gatherer.storeExtensionInformation();
|
||||
extensionGatherers.put(pluginName, gatherer);
|
||||
|
||||
@ -114,7 +114,7 @@ public class ExtensionServiceImplementation implements ExtensionService {
|
||||
|
||||
@Override
|
||||
public void unregister(DataExtension extension) {
|
||||
DataProviderExtractor extractor = new DataProviderExtractor(extension);
|
||||
ExtensionWrapper extractor = new ExtensionWrapper(extension);
|
||||
String pluginName = extractor.getPluginName();
|
||||
if (extensionGatherers.remove(pluginName) != null) {
|
||||
logger.getDebugLogger().logOn(DebugChannels.DATA_EXTENSIONS, pluginName + " extension unregistered.");
|
||||
|
@ -16,6 +16,7 @@
|
||||
*/
|
||||
package com.djrapitops.plan.extension.implementation;
|
||||
|
||||
import com.djrapitops.plan.extension.CallEvents;
|
||||
import com.djrapitops.plan.extension.DataExtension;
|
||||
import com.djrapitops.plan.extension.annotation.*;
|
||||
import com.djrapitops.plan.extension.extractor.ExtensionExtractor;
|
||||
@ -35,25 +36,29 @@ import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Extracts objects that can be used to obtain data to store in the database.
|
||||
* Represents information defined in a {@link DataExtension} class.
|
||||
* <p>
|
||||
* Extracts objects that can be used to obtain data from a {@link DataExtension}.
|
||||
* <p>
|
||||
* Goal of this class is to abstract away DataExtension API annotations so that they will not be needed outside when calling methods.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class DataProviderExtractor {
|
||||
public class ExtensionWrapper {
|
||||
|
||||
private final ExtensionExtractor extractor;
|
||||
private final DataProviders providers;
|
||||
private final DataExtension extension;
|
||||
|
||||
/**
|
||||
* Create a DataProviderExtractor.
|
||||
* Create an ExtensionWrapper.
|
||||
*
|
||||
* @param extension DataExtension to extract information from.
|
||||
* @throws IllegalArgumentException If something is badly wrong with the specified extension class annotations.
|
||||
*/
|
||||
public DataProviderExtractor(DataExtension extension) {
|
||||
extractor = new ExtensionExtractor(extension);
|
||||
public ExtensionWrapper(DataExtension extension) {
|
||||
this.extension = extension;
|
||||
extractor = new ExtensionExtractor(this.extension);
|
||||
|
||||
extractor.extractAnnotationInformation();
|
||||
|
||||
@ -61,6 +66,14 @@ public class DataProviderExtractor {
|
||||
extractProviders();
|
||||
}
|
||||
|
||||
public CallEvents[] getCallEvents() {
|
||||
return extension.callExtensionMethodsOn();
|
||||
}
|
||||
|
||||
public DataExtension getExtension() {
|
||||
return extension;
|
||||
}
|
||||
|
||||
public String getPluginName() {
|
||||
return extractor.getPluginInfo().name();
|
||||
}
|
@ -50,7 +50,7 @@ public interface Parameters {
|
||||
class ServerParameters implements Parameters {
|
||||
private final UUID serverUUID;
|
||||
|
||||
public ServerParameters(UUID serverUUID) {
|
||||
private ServerParameters(UUID serverUUID) {
|
||||
this.serverUUID = serverUUID;
|
||||
}
|
||||
|
||||
@ -74,7 +74,7 @@ public interface Parameters {
|
||||
private final UUID playerUUID;
|
||||
private final String playerName;
|
||||
|
||||
public PlayerParameters(UUID serverUUID, UUID playerUUID, String playerName) {
|
||||
private PlayerParameters(UUID serverUUID, UUID playerUUID, String playerName) {
|
||||
this.serverUUID = serverUUID;
|
||||
this.playerUUID = playerUUID;
|
||||
this.playerName = playerName;
|
||||
@ -108,7 +108,7 @@ public interface Parameters {
|
||||
private final UUID serverUUID;
|
||||
private final String groupName;
|
||||
|
||||
public GroupParameters(UUID serverUUID, String groupName) {
|
||||
private GroupParameters(UUID serverUUID, String groupName) {
|
||||
this.serverUUID = serverUUID;
|
||||
this.groupName = groupName;
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ package com.djrapitops.plan.extension.implementation.providers.gathering;
|
||||
|
||||
import com.djrapitops.plan.exceptions.DataExtensionMethodCallException;
|
||||
import com.djrapitops.plan.extension.DataExtension;
|
||||
import com.djrapitops.plan.extension.implementation.ExtensionWrapper;
|
||||
import com.djrapitops.plan.extension.implementation.ProviderInformation;
|
||||
import com.djrapitops.plan.extension.implementation.providers.DataProvider;
|
||||
import com.djrapitops.plan.extension.implementation.providers.DataProviders;
|
||||
@ -50,15 +51,15 @@ class BooleanProviderValueGatherer {
|
||||
private final DataProviders dataProviders;
|
||||
|
||||
BooleanProviderValueGatherer(
|
||||
String pluginName, DataExtension extension,
|
||||
String pluginName,
|
||||
UUID serverUUID, Database database,
|
||||
DataProviders dataProviders
|
||||
ExtensionWrapper extensionWrapper
|
||||
) {
|
||||
this.pluginName = pluginName;
|
||||
this.extension = extension;
|
||||
this.extension = extensionWrapper.getExtension();
|
||||
this.serverUUID = serverUUID;
|
||||
this.database = database;
|
||||
this.dataProviders = dataProviders;
|
||||
this.dataProviders = extensionWrapper.getProviders();
|
||||
}
|
||||
|
||||
Conditions gatherBooleanDataOfPlayer(UUID playerUUID, String playerName) {
|
||||
|
@ -17,9 +17,8 @@
|
||||
package com.djrapitops.plan.extension.implementation.providers.gathering;
|
||||
|
||||
import com.djrapitops.plan.extension.CallEvents;
|
||||
import com.djrapitops.plan.extension.DataExtension;
|
||||
import com.djrapitops.plan.extension.icon.Icon;
|
||||
import com.djrapitops.plan.extension.implementation.DataProviderExtractor;
|
||||
import com.djrapitops.plan.extension.implementation.ExtensionWrapper;
|
||||
import com.djrapitops.plan.extension.implementation.ProviderInformation;
|
||||
import com.djrapitops.plan.extension.implementation.TabInformation;
|
||||
import com.djrapitops.plan.extension.implementation.providers.DataProvider;
|
||||
@ -45,10 +44,8 @@ import java.util.UUID;
|
||||
*/
|
||||
public class ProviderValueGatherer {
|
||||
|
||||
private final DataExtension extension;
|
||||
|
||||
private final CallEvents[] callEvents;
|
||||
private final DataProviderExtractor extractor;
|
||||
private final ExtensionWrapper extensionWrapper;
|
||||
private final DBSystem dbSystem;
|
||||
private final ServerInfo serverInfo;
|
||||
|
||||
@ -64,26 +61,24 @@ public class ProviderValueGatherer {
|
||||
private final Gatherer<String[]> playerGroupGatherer;
|
||||
|
||||
public ProviderValueGatherer(
|
||||
DataExtension extension,
|
||||
DataProviderExtractor extractor,
|
||||
ExtensionWrapper extension,
|
||||
DBSystem dbSystem,
|
||||
ServerInfo serverInfo
|
||||
) {
|
||||
this.extension = extension;
|
||||
this.callEvents = this.extension.callExtensionMethodsOn();
|
||||
this.extractor = extractor;
|
||||
this.callEvents = extension.getCallEvents();
|
||||
this.extensionWrapper = extension;
|
||||
this.dbSystem = dbSystem;
|
||||
this.serverInfo = serverInfo;
|
||||
|
||||
String pluginName = extractor.getPluginName();
|
||||
String pluginName = extension.getPluginName();
|
||||
UUID serverUUID = serverInfo.getServerUUID();
|
||||
Database database = dbSystem.getDatabase();
|
||||
dataProviders = extractor.getProviders();
|
||||
dataProviders = extension.getProviders();
|
||||
booleanGatherer = new BooleanProviderValueGatherer(
|
||||
pluginName, extension, serverUUID, database, dataProviders
|
||||
pluginName, serverUUID, database, extension
|
||||
);
|
||||
tableGatherer = new TableProviderValueGatherer(
|
||||
pluginName, extension, serverUUID, database, dataProviders
|
||||
pluginName, serverUUID, database, extension
|
||||
);
|
||||
|
||||
serverNumberGatherer = new Gatherer<>(
|
||||
@ -126,12 +121,12 @@ public class ProviderValueGatherer {
|
||||
}
|
||||
|
||||
public String getPluginName() {
|
||||
return extractor.getPluginName();
|
||||
return extensionWrapper.getPluginName();
|
||||
}
|
||||
|
||||
public void storeExtensionInformation() {
|
||||
String pluginName = extractor.getPluginName();
|
||||
Icon pluginIcon = extractor.getPluginIcon();
|
||||
String pluginName = extensionWrapper.getPluginName();
|
||||
Icon pluginIcon = extensionWrapper.getPluginIcon();
|
||||
|
||||
long time = System.currentTimeMillis();
|
||||
UUID serverUUID = serverInfo.getServerUUID();
|
||||
@ -139,12 +134,12 @@ public class ProviderValueGatherer {
|
||||
Database database = dbSystem.getDatabase();
|
||||
database.executeTransaction(new StoreIconTransaction(pluginIcon));
|
||||
database.executeTransaction(new StorePluginTransaction(pluginName, time, serverUUID, pluginIcon));
|
||||
for (TabInformation tab : extractor.getPluginTabs()) {
|
||||
for (TabInformation tab : extensionWrapper.getPluginTabs()) {
|
||||
database.executeTransaction(new StoreIconTransaction(tab.getTabIcon()));
|
||||
database.executeTransaction(new StoreTabInformationTransaction(pluginName, serverUUID, tab));
|
||||
}
|
||||
|
||||
database.executeTransaction(new RemoveInvalidResultsTransaction(pluginName, serverUUID, extractor.getInvalidatedMethods()));
|
||||
database.executeTransaction(new RemoveInvalidResultsTransaction(pluginName, serverUUID, extensionWrapper.getInvalidatedMethods()));
|
||||
}
|
||||
|
||||
public void updateValues(UUID playerUUID, String playerName) {
|
||||
@ -195,7 +190,7 @@ public class ProviderValueGatherer {
|
||||
return; // Condition not fulfilled
|
||||
}
|
||||
|
||||
T result = provider.getMethod().callMethod(extension, parameters);
|
||||
T result = provider.getMethod().callMethod(extensionWrapper.getExtension(), parameters);
|
||||
if (result == null) {
|
||||
return; // Error during method call
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ package com.djrapitops.plan.extension.implementation.providers.gathering;
|
||||
import com.djrapitops.plan.exceptions.DataExtensionMethodCallException;
|
||||
import com.djrapitops.plan.extension.DataExtension;
|
||||
import com.djrapitops.plan.extension.icon.Icon;
|
||||
import com.djrapitops.plan.extension.implementation.ExtensionWrapper;
|
||||
import com.djrapitops.plan.extension.implementation.ProviderInformation;
|
||||
import com.djrapitops.plan.extension.implementation.providers.DataProvider;
|
||||
import com.djrapitops.plan.extension.implementation.providers.DataProviders;
|
||||
@ -53,15 +54,15 @@ class TableProviderValueGatherer {
|
||||
private final DataProviders dataProviders;
|
||||
|
||||
TableProviderValueGatherer(
|
||||
String pluginName, DataExtension extension,
|
||||
String pluginName,
|
||||
UUID serverUUID, Database database,
|
||||
DataProviders dataProviders
|
||||
ExtensionWrapper extensionWrapper
|
||||
) {
|
||||
this.pluginName = pluginName;
|
||||
this.extension = extension;
|
||||
this.extension = extensionWrapper.getExtension();
|
||||
this.serverUUID = serverUUID;
|
||||
this.database = database;
|
||||
this.dataProviders = dataProviders;
|
||||
this.dataProviders = extensionWrapper.getProviders();
|
||||
}
|
||||
|
||||
void gatherTableDataOfPlayer(UUID playerUUID, String playerName, Conditions conditions) {
|
||||
|
Loading…
Reference in New Issue
Block a user