Refactored code of DataProvider

Some optional values from different providers
were not included in ProviderInformation,
which lead to unnecessary instanceof usage and
weird static methods.

Added the optional info to ProviderInformation
and created a Builder, making much cleaner code
and removing those odd ball methods.

- Also fixed StoreProviderTransaction having
  insert of Icon and Tab in wrong order
This commit is contained in:
Rsl1122 2019-12-25 11:11:24 +02:00
parent 2c19e0e980
commit ee9a9ba7d8
15 changed files with 305 additions and 217 deletions

View File

@ -30,15 +30,15 @@ import java.util.Optional;
*/
public class MethodAnnotations {
private final Map<Class, Map<Method, Annotation>> byAnnotationType;
private final Map<Class<?>, Map<Method, Annotation>> byAnnotationType;
public MethodAnnotations() {
byAnnotationType = new HashMap<>();
}
public static boolean hasAnyOf(Method method, Class... annotationClasses) {
public static boolean hasAnyOf(Method method, Class<?>... annotationClasses) {
for (Annotation annotation : method.getAnnotations()) {
for (Class annotationClass : annotationClasses) {
for (Class<?> annotationClass : annotationClasses) {
if (annotationClass.isAssignableFrom(annotation.getClass())) {
return true;
}

View File

@ -128,17 +128,19 @@ public class DataProviderExtractor {
}
private <T extends Annotation> void extractProviders(PluginInfo pluginInfo, Map<Method, Tab> tabs, Map<Method, Conditional> conditions, Class<T> ofKind, DataProviderFactory<T> factory) {
String pluginName = extractor.getPluginInfo().name();
for (Map.Entry<Method, T> entry : extractor.getMethodAnnotations().getMethodAnnotations(ofKind).entrySet()) {
Method method = entry.getKey();
T annotation = entry.getValue();
Optional<Conditional> conditional = Optional.ofNullable(conditions.get(method));
Conditional conditional = conditions.get(method);
Optional<Tab> tab = Optional.ofNullable(tabs.get(method));
factory.placeToDataProviders(
providers, method, annotation,
conditional.orElse(null),
conditional,
tab.map(Tab::value).orElse(null),
pluginInfo.name()
pluginName
);
}
}

View File

@ -16,7 +16,9 @@
*/
package com.djrapitops.plan.extension.implementation;
import com.djrapitops.plan.extension.FormatType;
import com.djrapitops.plan.extension.annotation.Conditional;
import com.djrapitops.plan.extension.icon.Color;
import com.djrapitops.plan.extension.icon.Icon;
import com.djrapitops.plan.extension.implementation.results.ExtensionDescriptive;
import org.apache.commons.lang3.StringUtils;
@ -35,15 +37,27 @@ public class ProviderInformation extends ExtensionDescriptive {
private final boolean showInPlayersTable;
private final String tab; // can be null
private final Conditional condition; // can be null
private final boolean hidden; // default false, BooleanProvider
private final String providedCondition; // can be null, BooleanProvider
private final FormatType formatType; // can be null, NumberProvider
private final boolean isPlayerName; // default false, StringProvider
private final Color tableColor; // can be null, TableProvider
public ProviderInformation(
String pluginName, String name, String text, String description, Icon icon, int priority, boolean showInPlayersTable, String tab, Conditional condition
) {
super(name, text, description, icon, priority);
this.pluginName = pluginName;
this.showInPlayersTable = showInPlayersTable;
this.tab = tab;
this.condition = condition;
private ProviderInformation(ProviderInformation.Builder builder) {
super(builder.name, builder.text, builder.description, builder.icon, builder.priority);
pluginName = builder.pluginName;
showInPlayersTable = builder.showInPlayersTable;
tab = builder.tab;
condition = builder.condition;
hidden = builder.hidden;
providedCondition = builder.providedCondition;
formatType = builder.formatType;
isPlayerName = builder.isPlayerName;
tableColor = builder.tableColor;
}
public static ProviderInformation.Builder builder(String pluginName) {
return new ProviderInformation.Builder(pluginName);
}
public String getPluginName() {
@ -54,6 +68,22 @@ public class ProviderInformation extends ExtensionDescriptive {
return showInPlayersTable;
}
public boolean isHidden() {
return hidden;
}
public String getProvidedCondition() {
return providedCondition;
}
public Optional<FormatType> getFormatType() {
return Optional.ofNullable(formatType);
}
public boolean isPlayerName() {
return isPlayerName;
}
public Optional<String> getTab() {
return tab == null || tab.isEmpty()
? Optional.empty()
@ -89,4 +119,98 @@ public class ProviderInformation extends ExtensionDescriptive {
public int hashCode() {
return Objects.hash(super.hashCode(), pluginName, tab, condition);
}
public Color getTableColor() {
return tableColor;
}
public static class Builder {
private final String pluginName;
private String name;
private String text;
private String description;
private Icon icon;
private int priority;
private boolean showInPlayersTable = false;
private String tab; // can be null
private Conditional condition; // can be null
private boolean hidden = false; // default false, BooleanProvider
private String providedCondition; // can be null, BooleanProvider
private FormatType formatType; // can be null, NumberProvider
private boolean isPlayerName = false; // default false, StringProvider
private Color tableColor; // can be null, TableProvider
public Builder(String pluginName) {
this.pluginName = pluginName;
}
public Builder setName(String name) {
this.name = name;
return this;
}
public Builder setText(String text) {
this.text = text;
return this;
}
public Builder setDescription(String description) {
this.description = description;
return this;
}
public Builder setIcon(Icon icon) {
this.icon = icon;
return this;
}
public Builder setPriority(int priority) {
this.priority = priority;
return this;
}
public Builder setShowInPlayersTable(boolean showInPlayersTable) {
this.showInPlayersTable = showInPlayersTable;
return this;
}
public Builder setTab(String tab) {
this.tab = tab;
return this;
}
public Builder setCondition(Conditional condition) {
this.condition = condition;
return this;
}
public Builder setHidden(boolean hidden) {
this.hidden = hidden;
return this;
}
public Builder setProvidedCondition(String providedCondition) {
this.providedCondition = providedCondition;
return this;
}
public Builder setFormatType(FormatType formatType) {
this.formatType = formatType;
return this;
}
public Builder setPlayerName(boolean playerName) {
isPlayerName = playerName;
return this;
}
public Builder setTableColor(Color tableColor) {
this.tableColor = tableColor;
return this;
}
public ProviderInformation build() {
return new ProviderInformation(this);
}
}
}

View File

@ -20,60 +20,41 @@ import com.djrapitops.plan.extension.annotation.BooleanProvider;
import com.djrapitops.plan.extension.annotation.Conditional;
import com.djrapitops.plan.extension.icon.Icon;
import com.djrapitops.plan.extension.implementation.ProviderInformation;
import org.apache.commons.lang3.StringUtils;
import java.lang.reflect.Method;
import java.util.Optional;
/**
* Represents a DataExtension API method annotated with {@link BooleanProvider} annotation.
* <p>
* Used to obtain data to place in the database.
* Contains code that acts on {@link BooleanProvider} annotations.
*
* @author Rsl1122
*/
public class BooleanDataProvider extends DataProvider<Boolean> {
public class BooleanDataProvider {
private final String providedCondition;
private final boolean hidden;
private BooleanDataProvider(ProviderInformation providerInformation, MethodWrapper<Boolean> method, String providedCondition, boolean hidden) {
super(providerInformation, method);
this.providedCondition = providedCondition;
this.hidden = hidden;
private BooleanDataProvider() {
// Static method class
}
public static void placeToDataProviders(
DataProviders dataProviders, Method method, BooleanProvider annotation,
Conditional condition, String tab, String pluginName
) {
ProviderInformation information = ProviderInformation.builder(pluginName)
.setName(method.getName())
.setText(annotation.text())
.setDescription(annotation.description())
.setPriority(annotation.priority())
.setIcon(new Icon(
annotation.iconFamily(),
annotation.iconName(),
annotation.iconColor())
).setShowInPlayersTable(annotation.showInPlayerTable())
.setCondition(condition)
.setTab(tab)
.setHidden(annotation.hidden())
.setProvidedCondition(annotation.conditionName())
.build();
MethodWrapper<Boolean> methodWrapper = new MethodWrapper<>(method, Boolean.class);
Icon providerIcon = new Icon(annotation.iconFamily(), annotation.iconName(), annotation.iconColor());
ProviderInformation providerInformation = new ProviderInformation(
pluginName, method.getName(), annotation.text(), annotation.description(), providerIcon, annotation.priority(), annotation.showInPlayerTable(), tab, condition
);
dataProviders.put(new BooleanDataProvider(providerInformation, methodWrapper, annotation.conditionName(), annotation.hidden()));
}
public static Optional<String> getProvidedCondition(DataProvider<?> provider) {
if (provider instanceof BooleanDataProvider) {
return ((BooleanDataProvider) provider).getProvidedCondition();
}
return Optional.empty();
}
public Optional<String> getProvidedCondition() {
return providedCondition == null || providedCondition.isEmpty() ? Optional.empty() : Optional.of(StringUtils.truncate(providedCondition, 50));
}
public static boolean isHidden(DataProvider<?> provider) {
return provider instanceof BooleanDataProvider && ((BooleanDataProvider) provider).isHidden();
}
public boolean isHidden() {
return hidden;
dataProviders.put(new DataProvider<>(information, methodWrapper));
}
}

View File

@ -21,11 +21,11 @@ import com.djrapitops.plan.extension.implementation.ProviderInformation;
import java.util.Objects;
/**
* Abstract representation of all values a Provider annotation provides.
* Representation of all values a Provider annotation provides.
*
* @author Rsl1122
*/
public abstract class DataProvider<T> {
public class DataProvider<T> {
private final ProviderInformation providerInformation;
private final MethodWrapper<T> method;

View File

@ -24,29 +24,36 @@ import com.djrapitops.plan.extension.implementation.ProviderInformation;
import java.lang.reflect.Method;
/**
* Represents a DataExtension API method annotated with {@link DoubleProvider} annotation.
* <p>
* Used to obtain data to place in the database.
* Contains code that acts on {@link DoubleProvider} annotations.
*
* @author Rsl1122
*/
public class DoubleDataProvider extends DataProvider<Double> {
public class DoubleDataProvider {
private DoubleDataProvider(ProviderInformation providerInformation, MethodWrapper<Double> methodWrapper) {
super(providerInformation, methodWrapper);
private DoubleDataProvider() {
// Static method class
}
public static void placeToDataProviders(
DataProviders dataProviders, Method method, DoubleProvider annotation,
Conditional condition, String tab, String pluginName
) {
ProviderInformation information = ProviderInformation.builder(pluginName)
.setName(method.getName())
.setText(annotation.text())
.setDescription(annotation.description())
.setPriority(annotation.priority())
.setIcon(new Icon(
annotation.iconFamily(),
annotation.iconName(),
annotation.iconColor())
).setShowInPlayersTable(annotation.showInPlayerTable())
.setCondition(condition)
.setTab(tab)
.build();
MethodWrapper<Double> methodWrapper = new MethodWrapper<>(method, Double.class);
Icon providerIcon = new Icon(annotation.iconFamily(), annotation.iconName(), annotation.iconColor());
ProviderInformation providerInformation = new ProviderInformation(
pluginName, method.getName(), annotation.text(), annotation.description(), providerIcon, annotation.priority(), annotation.showInPlayerTable(), tab, condition
);
dataProviders.put(new DoubleDataProvider(providerInformation, methodWrapper));
dataProviders.put(new DataProvider<>(information, methodWrapper));
}
}

View File

@ -18,36 +18,40 @@ package com.djrapitops.plan.extension.implementation.providers;
import com.djrapitops.plan.extension.annotation.Conditional;
import com.djrapitops.plan.extension.annotation.GroupProvider;
import com.djrapitops.plan.extension.annotation.StringProvider;
import com.djrapitops.plan.extension.icon.Icon;
import com.djrapitops.plan.extension.implementation.ProviderInformation;
import java.lang.reflect.Method;
/**
* Represents a DataExtension API method annotated with {@link StringProvider} annotation.
* <p>
* Used to obtain data to place in the database.
* Contains code that acts on {@link GroupProvider} annotations.
*
* @author Rsl1122
*/
public class GroupDataProvider extends DataProvider<String[]> {
public class GroupDataProvider {
private GroupDataProvider(ProviderInformation providerInformation, MethodWrapper<String[]> methodWrapper) {
super(providerInformation, methodWrapper);
private GroupDataProvider() {
// Static method class
}
public static void placeToDataProviders(
DataProviders dataProviders, Method method, GroupProvider annotation,
Conditional condition, String tab, String pluginName
) {
ProviderInformation information = ProviderInformation.builder(pluginName)
.setName(method.getName())
.setText(annotation.text())
.setPriority(0)
.setIcon(new Icon(
annotation.iconFamily(),
annotation.iconName(),
annotation.groupColor())
).setShowInPlayersTable(true)
.setCondition(condition)
.setTab(tab)
.build();
MethodWrapper<String[]> methodWrapper = new MethodWrapper<>(method, String[].class);
Icon providerIcon = new Icon(annotation.iconFamily(), annotation.iconName(), annotation.groupColor());
ProviderInformation providerInformation = new ProviderInformation(
pluginName, method.getName(), annotation.text(), null, providerIcon, 0, true, tab, condition
);
dataProviders.put(new GroupDataProvider(providerInformation, methodWrapper));
dataProviders.put(new DataProvider<>(information, methodWrapper));
}
}

View File

@ -16,53 +16,44 @@
*/
package com.djrapitops.plan.extension.implementation.providers;
import com.djrapitops.plan.extension.FormatType;
import com.djrapitops.plan.extension.annotation.Conditional;
import com.djrapitops.plan.extension.annotation.NumberProvider;
import com.djrapitops.plan.extension.icon.Icon;
import com.djrapitops.plan.extension.implementation.ProviderInformation;
import java.lang.reflect.Method;
import java.util.Optional;
/**
* Represents a DataExtension API method annotated with {@link NumberProvider} annotation.
* <p>
* Used to obtain data to place in the database.
* Contains code that acts on {@link NumberProvider} annotations.
*
* @author Rsl1122
*/
public class NumberDataProvider extends DataProvider<Long> {
public class NumberDataProvider {
private final FormatType formatType;
private NumberDataProvider(ProviderInformation providerInformation, MethodWrapper<Long> methodWrapper, FormatType formatType) {
super(providerInformation, methodWrapper);
this.formatType = formatType;
private NumberDataProvider() {
// Static method class
}
public static void placeToDataProviders(
DataProviders dataProviders, Method method, NumberProvider annotation,
Conditional condition, String tab, String pluginName
) {
ProviderInformation information = ProviderInformation.builder(pluginName)
.setName(method.getName())
.setText(annotation.text())
.setDescription(annotation.description())
.setPriority(annotation.priority())
.setIcon(new Icon(
annotation.iconFamily(),
annotation.iconName(),
annotation.iconColor())
).setShowInPlayersTable(annotation.showInPlayerTable())
.setCondition(condition)
.setTab(tab)
.setFormatType(annotation.format())
.build();
MethodWrapper<Long> methodWrapper = new MethodWrapper<>(method, Long.class);
Icon providerIcon = new Icon(annotation.iconFamily(), annotation.iconName(), annotation.iconColor());
ProviderInformation providerInformation = new ProviderInformation(
pluginName, method.getName(), annotation.text(), annotation.description(), providerIcon, annotation.priority(), annotation.showInPlayerTable(), tab, condition
);
dataProviders.put(new NumberDataProvider(providerInformation, methodWrapper, annotation.format()));
}
public static Optional<FormatType> getFormatType(DataProvider<?> provider) {
if (provider instanceof NumberDataProvider) {
return Optional.of(((NumberDataProvider) provider).getFormatType());
}
return Optional.empty();
}
public FormatType getFormatType() {
return formatType;
dataProviders.put(new DataProvider<>(information, methodWrapper));
}
}

View File

@ -25,13 +25,13 @@ import java.lang.reflect.Method;
/**
* Represents a DataExtension API method annotated with {@link PercentageProvider} annotation.
* <p>
* Used to obtain data to place in the database.
*
* @author Rsl1122
*/
public class PercentageDataProvider extends DataProvider<Double> {
// TODO Remove need for instanceof in DoubleAndPercentageProviderGatherer
private PercentageDataProvider(ProviderInformation providerInformation, MethodWrapper<Double> methodWrapper) {
super(providerInformation, methodWrapper);
}
@ -40,13 +40,22 @@ public class PercentageDataProvider extends DataProvider<Double> {
DataProviders dataProviders, Method method, PercentageProvider annotation,
Conditional condition, String tab, String pluginName
) {
ProviderInformation information = ProviderInformation.builder(pluginName)
.setName(method.getName())
.setText(annotation.text())
.setDescription(annotation.description())
.setPriority(annotation.priority())
.setIcon(new Icon(
annotation.iconFamily(),
annotation.iconName(),
annotation.iconColor())
).setShowInPlayersTable(annotation.showInPlayerTable())
.setCondition(condition)
.setTab(tab)
.build();
MethodWrapper<Double> methodWrapper = new MethodWrapper<>(method, Double.class);
Icon providerIcon = new Icon(annotation.iconFamily(), annotation.iconName(), annotation.iconColor());
ProviderInformation providerInformation = new ProviderInformation(
pluginName, method.getName(), annotation.text(), annotation.description(), providerIcon, annotation.priority(), annotation.showInPlayerTable(), tab, condition
);
dataProviders.put(new PercentageDataProvider(providerInformation, methodWrapper));
dataProviders.put(new PercentageDataProvider(information, methodWrapper));
}
}

View File

@ -24,45 +24,36 @@ import com.djrapitops.plan.extension.implementation.ProviderInformation;
import java.lang.reflect.Method;
/**
* Represents a DataExtension API method annotated with {@link StringProvider} annotation.
* <p>
* Used to obtain data to place in the database.
* Contains code that acts on {@link StringProvider} annotations.
*
* @author Rsl1122
*/
public class StringDataProvider extends DataProvider<String> {
public class StringDataProvider {
private final boolean playerName;
private StringDataProvider(ProviderInformation providerInformation, MethodWrapper<String> methodWrapper, boolean playerName) {
super(providerInformation, methodWrapper);
this.playerName = playerName;
private StringDataProvider() {
// Static method class
}
public static void placeToDataProviders(
DataProviders dataProviders, Method method, StringProvider annotation,
Conditional condition, String tab, String pluginName
) {
ProviderInformation information = ProviderInformation.builder(pluginName)
.setName(method.getName())
.setText(annotation.text())
.setDescription(annotation.description())
.setPriority(annotation.priority())
.setIcon(new Icon(
annotation.iconFamily(),
annotation.iconName(),
annotation.iconColor())
).setShowInPlayersTable(annotation.showInPlayerTable())
.setCondition(condition)
.setTab(tab)
.setPlayerName(annotation.playerName())
.build();
MethodWrapper<String> methodWrapper = new MethodWrapper<>(method, String.class);
Icon providerIcon = new Icon(annotation.iconFamily(), annotation.iconName(), annotation.iconColor());
ProviderInformation providerInformation = new ProviderInformation(
pluginName, method.getName(), annotation.text(), annotation.description(), providerIcon, annotation.priority(), annotation.showInPlayerTable(), tab, condition
);
boolean playerName = annotation.playerName();
dataProviders.put(new StringDataProvider(providerInformation, methodWrapper, playerName));
}
public static boolean isPlayerName(DataProvider<?> provider) {
if (provider instanceof StringDataProvider) {
return ((StringDataProvider) provider).isPlayerName();
}
return false;
}
public boolean isPlayerName() {
return playerName;
dataProviders.put(new DataProvider<>(information, methodWrapper));
}
}

View File

@ -18,52 +18,38 @@ package com.djrapitops.plan.extension.implementation.providers;
import com.djrapitops.plan.extension.annotation.Conditional;
import com.djrapitops.plan.extension.annotation.TableProvider;
import com.djrapitops.plan.extension.icon.Color;
import com.djrapitops.plan.extension.implementation.ProviderInformation;
import com.djrapitops.plan.extension.table.Table;
import java.lang.reflect.Method;
/**
* Represents a DataExtension API method annotated with {@link com.djrapitops.plan.extension.annotation.TableProvider} annotation.
* Contains code that acts on {@link TableProvider} annotations.
* <p>
* Used to obtain data to place in the database.
* <p>
* Please note that not all {@link ProviderInformation} is present.
* Please note that not all {@link ProviderInformation} is present in this annotation.
*
* @author Rsl1122
*/
public class TableDataProvider extends DataProvider<Table> {
public class TableDataProvider {
private final Color tableColor;
private TableDataProvider(ProviderInformation providerInformation, MethodWrapper<Table> methodWrapper, Color tableColor) {
super(providerInformation, methodWrapper);
this.tableColor = tableColor;
private TableDataProvider() {
// Static method class
}
public static void placeToDataProviders(
DataProviders dataProviders, Method method, TableProvider annotation,
Conditional condition, String tab, String pluginName
) {
ProviderInformation information = ProviderInformation.builder(pluginName)
.setName(method.getName())
.setPriority(0)
.setCondition(condition)
.setTab(tab)
.setTableColor(annotation.tableColor())
.build();
MethodWrapper<Table> methodWrapper = new MethodWrapper<>(method, Table.class);
ProviderInformation providerInformation = new ProviderInformation(
pluginName, method.getName(), null, null, null, 0, false, tab, condition
);
dataProviders.put(new TableDataProvider(providerInformation, methodWrapper, annotation.tableColor()));
dataProviders.put(new DataProvider<>(information, methodWrapper));
}
public static Color getTableColor(DataProvider<Table> provider) {
if (provider instanceof TableDataProvider) {
return ((TableDataProvider) provider).getTableColor();
}
return Color.NONE;
}
public Color getTableColor() {
return tableColor;
}
}

View File

@ -19,7 +19,6 @@ 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.ProviderInformation;
import com.djrapitops.plan.extension.implementation.providers.BooleanDataProvider;
import com.djrapitops.plan.extension.implementation.providers.DataProvider;
import com.djrapitops.plan.extension.implementation.providers.DataProviders;
import com.djrapitops.plan.extension.implementation.providers.MethodWrapper;
@ -112,15 +111,16 @@ class BooleanProviderValueGatherer {
) {
Set<DataProvider<Boolean>> satisfied = new HashSet<>();
for (DataProvider<Boolean> booleanProvider : unsatisifiedProviders) {
ProviderInformation providerInformation = booleanProvider.getProviderInformation();
ProviderInformation information = booleanProvider.getProviderInformation();
Optional<String> condition = providerInformation.getCondition();
Optional<String> condition = information.getCondition();
if (condition.isPresent() && conditions.isNotFulfilled(condition.get())) {
// Condition required by the BooleanProvider is not satisfied
continue;
}
Optional<String> providedCondition = BooleanDataProvider.getProvidedCondition(booleanProvider);
String providedCondition = information.getProvidedCondition();
MethodWrapper<Boolean> method = booleanProvider.getMethod();
Boolean result = getMethodResult(methodCaller.apply(method), method);
if (result == null) {
@ -129,18 +129,18 @@ class BooleanProviderValueGatherer {
continue;
}
if (providedCondition.isPresent()) {
if (providedCondition != null) {
if (result) {
// The condition was fulfilled (true) for this player.
conditions.conditionFulfilled(providedCondition.get());
conditions.conditionFulfilled(providedCondition);
} else {
// The negated condition was fulfilled (false) for this player.
conditions.conditionFulfilled("not_" + providedCondition.get());
conditions.conditionFulfilled("not_" + providedCondition);
}
}
satisfied.add(booleanProvider); // Prevents further attempts to call this provider for this player.
database.executeTransaction(new StoreIconTransaction(providerInformation.getIcon()));
database.executeTransaction(new StoreIconTransaction(information.getIcon()));
database.executeTransaction(new StoreProviderTransaction(booleanProvider, serverUUID));
database.executeTransaction(storeTransactionCreator.apply(method, result));
}

View File

@ -23,7 +23,6 @@ import com.djrapitops.plan.extension.implementation.ProviderInformation;
import com.djrapitops.plan.extension.implementation.providers.DataProvider;
import com.djrapitops.plan.extension.implementation.providers.DataProviders;
import com.djrapitops.plan.extension.implementation.providers.MethodWrapper;
import com.djrapitops.plan.extension.implementation.providers.TableDataProvider;
import com.djrapitops.plan.extension.implementation.storage.transactions.StoreIconTransaction;
import com.djrapitops.plan.extension.implementation.storage.transactions.providers.StoreTableProviderTransaction;
import com.djrapitops.plan.extension.implementation.storage.transactions.results.StorePlayerTableResultTransaction;
@ -109,7 +108,7 @@ class TableProviderValueGatherer {
database.executeTransaction(new StoreIconTransaction(icon));
}
}
database.executeTransaction(new StoreTableProviderTransaction(serverUUID, providerInformation, TableDataProvider.getTableColor(tableProvider), result));
database.executeTransaction(new StoreTableProviderTransaction(serverUUID, providerInformation, result));
database.executeTransaction(storeTransactionCreator.apply(method, result));
}

View File

@ -18,10 +18,7 @@ package com.djrapitops.plan.extension.implementation.storage.transactions.provid
import com.djrapitops.plan.extension.FormatType;
import com.djrapitops.plan.extension.implementation.ProviderInformation;
import com.djrapitops.plan.extension.implementation.providers.BooleanDataProvider;
import com.djrapitops.plan.extension.implementation.providers.DataProvider;
import com.djrapitops.plan.extension.implementation.providers.NumberDataProvider;
import com.djrapitops.plan.extension.implementation.providers.StringDataProvider;
import com.djrapitops.plan.storage.database.sql.building.Sql;
import com.djrapitops.plan.storage.database.sql.tables.ExtensionIconTable;
import com.djrapitops.plan.storage.database.sql.tables.ExtensionPluginTable;
@ -94,15 +91,15 @@ public class StoreProviderTransaction extends ThrowawayTransaction {
Sql.setStringOrNull(statement, 2, info.getDescription().orElse(null));
statement.setInt(3, info.getPriority());
Sql.setStringOrNull(statement, 4, info.getCondition().orElse(null));
ExtensionTabTable.set3TabValuesToStatement(statement, 5, info.getTab().orElse(null), info.getPluginName(), serverUUID);
ExtensionIconTable.set3IconValuesToStatement(statement, 8, info.getIcon());
ExtensionIconTable.set3IconValuesToStatement(statement, 5, info.getIcon());
ExtensionTabTable.set3TabValuesToStatement(statement, 8, info.getTab().orElse(null), info.getPluginName(), serverUUID);
statement.setBoolean(11, info.isShownInPlayersTable());
// Specific provider cases
statement.setBoolean(12, BooleanDataProvider.isHidden(provider));
Sql.setStringOrNull(statement, 13, BooleanDataProvider.getProvidedCondition(provider).orElse(null));
Sql.setStringOrNull(statement, 14, NumberDataProvider.getFormatType(provider).map(FormatType::name).orElse(null));
statement.setBoolean(15, StringDataProvider.isPlayerName(provider));
statement.setBoolean(12, info.isHidden());
Sql.setStringOrNull(statement, 13, info.getProvidedCondition());
Sql.setStringOrNull(statement, 14, info.getFormatType().map(FormatType::name).orElse(null));
statement.setBoolean(15, info.isPlayerName());
// Find appropriate provider
ExtensionPluginTable.set2PluginValuesToStatement(statement, 16, info.getPluginName(), serverUUID);
@ -159,10 +156,10 @@ public class StoreProviderTransaction extends ThrowawayTransaction {
statement.setBoolean(6, info.isShownInPlayersTable());
// Specific provider cases
statement.setBoolean(7, BooleanDataProvider.isHidden(provider));
Sql.setStringOrNull(statement, 8, BooleanDataProvider.getProvidedCondition(provider).orElse(null));
Sql.setStringOrNull(statement, 9, NumberDataProvider.getFormatType(provider).map(FormatType::name).orElse(null));
statement.setBoolean(10, StringDataProvider.isPlayerName(provider));
statement.setBoolean(7, info.isHidden());
Sql.setStringOrNull(statement, 8, info.getProvidedCondition());
Sql.setStringOrNull(statement, 9, info.getFormatType().map(FormatType::name).orElse(null));
statement.setBoolean(10, info.isPlayerName());
// Found for all providers
ExtensionTabTable.set3TabValuesToStatement(statement, 11, info.getTab().orElse(null), info.getPluginName(), serverUUID);

View File

@ -16,7 +16,6 @@
*/
package com.djrapitops.plan.extension.implementation.storage.transactions.providers;
import com.djrapitops.plan.extension.icon.Color;
import com.djrapitops.plan.extension.icon.Icon;
import com.djrapitops.plan.extension.implementation.ProviderInformation;
import com.djrapitops.plan.extension.table.Table;
@ -44,13 +43,11 @@ import static com.djrapitops.plan.storage.database.sql.tables.ExtensionTableProv
public class StoreTableProviderTransaction extends ThrowawayTransaction {
private final UUID serverUUID;
private final ProviderInformation providerInformation;
private final Color tableColor;
private final ProviderInformation information;
private final Table table;
public StoreTableProviderTransaction(UUID serverUUID, ProviderInformation providerInformation, Color tableColor, Table table) {
this.providerInformation = providerInformation;
this.tableColor = tableColor;
public StoreTableProviderTransaction(UUID serverUUID, ProviderInformation information, Table table) {
this.information = information;
this.table = table;
this.serverUUID = serverUUID;
}
@ -93,21 +90,21 @@ public class StoreTableProviderTransaction extends ThrowawayTransaction {
return new ExecStatement(sql) {
@Override
public void prepare(PreparedStatement statement) throws SQLException {
statement.setString(1, tableColor.name());
statement.setString(1, information.getTableColor().name());
setStringOrNull(statement, 2, columns[0]);
setStringOrNull(statement, 3, columns[1]);
setStringOrNull(statement, 4, columns[2]);
setStringOrNull(statement, 5, columns[3]);
setStringOrNull(statement, 6, columns[4]);
setStringOrNull(statement, 7, providerInformation.getCondition().orElse(null));
ExtensionTabTable.set3TabValuesToStatement(statement, 8, providerInformation.getTab().orElse("No Tab"), providerInformation.getPluginName(), serverUUID);
setStringOrNull(statement, 7, information.getCondition().orElse(null));
ExtensionTabTable.set3TabValuesToStatement(statement, 8, information.getTab().orElse("No Tab"), information.getPluginName(), serverUUID);
ExtensionIconTable.set3IconValuesToStatement(statement, 11, icons[0]);
ExtensionIconTable.set3IconValuesToStatement(statement, 14, icons[1]);
ExtensionIconTable.set3IconValuesToStatement(statement, 17, icons[2]);
ExtensionIconTable.set3IconValuesToStatement(statement, 20, icons[3]);
ExtensionIconTable.set3IconValuesToStatement(statement, 23, icons[4]);
statement.setString(26, providerInformation.getName());
ExtensionPluginTable.set2PluginValuesToStatement(statement, 27, providerInformation.getPluginName(), serverUUID);
statement.setString(26, information.getName());
ExtensionPluginTable.set2PluginValuesToStatement(statement, 27, information.getPluginName(), serverUUID);
}
};
}
@ -144,16 +141,16 @@ public class StoreTableProviderTransaction extends ThrowawayTransaction {
return new ExecStatement(sql) {
@Override
public void prepare(PreparedStatement statement) throws SQLException {
statement.setString(1, providerInformation.getName());
statement.setString(2, tableColor.name());
statement.setString(1, information.getName());
statement.setString(2, information.getTableColor().name());
setStringOrNull(statement, 3, columns[0]);
setStringOrNull(statement, 4, columns[1]);
setStringOrNull(statement, 5, columns[2]);
setStringOrNull(statement, 6, columns[3]);
setStringOrNull(statement, 7, columns[4]);
setStringOrNull(statement, 8, providerInformation.getCondition().orElse(null));
ExtensionTabTable.set3TabValuesToStatement(statement, 9, providerInformation.getTab().orElse("No Tab"), providerInformation.getPluginName(), serverUUID);
ExtensionPluginTable.set2PluginValuesToStatement(statement, 12, providerInformation.getPluginName(), serverUUID);
setStringOrNull(statement, 8, information.getCondition().orElse(null));
ExtensionTabTable.set3TabValuesToStatement(statement, 9, information.getTab().orElse("No Tab"), information.getPluginName(), serverUUID);
ExtensionPluginTable.set2PluginValuesToStatement(statement, 12, information.getPluginName(), serverUUID);
ExtensionIconTable.set3IconValuesToStatement(statement, 14, icons[0]);
ExtensionIconTable.set3IconValuesToStatement(statement, 17, icons[1]);
ExtensionIconTable.set3IconValuesToStatement(statement, 20, icons[2]);