mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-02 14:37:45 +01:00
Removed need of instanceof PercentageDataProvider
This commit is contained in:
parent
3e734ec505
commit
43f18c78aa
@ -42,6 +42,7 @@ public class ProviderInformation extends ExtensionDescriptive {
|
||||
private final FormatType formatType; // can be null, NumberProvider
|
||||
private final boolean isPlayerName; // default false, StringProvider
|
||||
private final Color tableColor; // can be null, TableProvider
|
||||
private final boolean percentage; // affects where doubles are stored
|
||||
|
||||
private ProviderInformation(ProviderInformation.Builder builder) {
|
||||
super(builder.name, builder.text, builder.description, builder.icon, builder.priority);
|
||||
@ -54,6 +55,7 @@ public class ProviderInformation extends ExtensionDescriptive {
|
||||
formatType = builder.formatType;
|
||||
isPlayerName = builder.isPlayerName;
|
||||
tableColor = builder.tableColor;
|
||||
percentage = builder.percentage;
|
||||
}
|
||||
|
||||
public static ProviderInformation.Builder builder(String pluginName) {
|
||||
@ -124,6 +126,10 @@ public class ProviderInformation extends ExtensionDescriptive {
|
||||
return tableColor;
|
||||
}
|
||||
|
||||
public boolean isPercentage() {
|
||||
return percentage;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private final String pluginName;
|
||||
private String name;
|
||||
@ -139,6 +145,7 @@ public class ProviderInformation extends ExtensionDescriptive {
|
||||
private FormatType formatType; // can be null, NumberProvider
|
||||
private boolean isPlayerName = false; // default false, StringProvider
|
||||
private Color tableColor; // can be null, TableProvider
|
||||
private boolean percentage; // affects where doubles are stored
|
||||
|
||||
public Builder(String pluginName) {
|
||||
this.pluginName = pluginName;
|
||||
@ -209,6 +216,11 @@ public class ProviderInformation extends ExtensionDescriptive {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setAsPercentage() {
|
||||
percentage = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ProviderInformation build() {
|
||||
return new ProviderInformation(this);
|
||||
}
|
||||
|
@ -24,16 +24,14 @@ import com.djrapitops.plan.extension.implementation.ProviderInformation;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* Represents a DataExtension API method annotated with {@link PercentageProvider} annotation.
|
||||
* Contains code that acts on {@link PercentageProvider} annotations.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class PercentageDataProvider extends DataProvider<Double> {
|
||||
public class PercentageDataProvider {
|
||||
|
||||
// TODO Remove need for instanceof PercentageDataProvider
|
||||
|
||||
private PercentageDataProvider(ProviderInformation providerInformation, MethodWrapper<Double> methodWrapper) {
|
||||
super(providerInformation, methodWrapper);
|
||||
private PercentageDataProvider() {
|
||||
// Static method class
|
||||
}
|
||||
|
||||
public static void placeToDataProviders(
|
||||
@ -52,10 +50,11 @@ public class PercentageDataProvider extends DataProvider<Double> {
|
||||
).setShowInPlayersTable(annotation.showInPlayerTable())
|
||||
.setCondition(condition)
|
||||
.setTab(tab)
|
||||
.setAsPercentage()
|
||||
.build();
|
||||
|
||||
MethodWrapper<Double> methodWrapper = new MethodWrapper<>(method, Double.class);
|
||||
|
||||
dataProviders.put(new PercentageDataProvider(information, methodWrapper));
|
||||
dataProviders.put(new DataProvider<>(information, methodWrapper));
|
||||
}
|
||||
}
|
@ -18,7 +18,6 @@ package com.djrapitops.plan.extension.implementation.storage.transactions.result
|
||||
|
||||
import com.djrapitops.plan.extension.implementation.providers.DataProvider;
|
||||
import com.djrapitops.plan.extension.implementation.providers.Parameters;
|
||||
import com.djrapitops.plan.extension.implementation.providers.PercentageDataProvider;
|
||||
import com.djrapitops.plan.storage.database.sql.tables.ExtensionProviderTable;
|
||||
import com.djrapitops.plan.storage.database.transactions.ExecStatement;
|
||||
import com.djrapitops.plan.storage.database.transactions.Executable;
|
||||
@ -57,7 +56,7 @@ public class StorePlayerDoubleResultTransaction extends ThrowawayTransaction {
|
||||
this.serverUUID = parameters.getServerUUID();
|
||||
this.playerUUID = parameters.getPlayerUUID();
|
||||
this.value = value;
|
||||
this.percentage = provider instanceof PercentageDataProvider;
|
||||
this.percentage = provider.getProviderInformation().isPercentage();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -18,7 +18,6 @@ package com.djrapitops.plan.extension.implementation.storage.transactions.result
|
||||
|
||||
import com.djrapitops.plan.extension.implementation.providers.DataProvider;
|
||||
import com.djrapitops.plan.extension.implementation.providers.Parameters;
|
||||
import com.djrapitops.plan.extension.implementation.providers.PercentageDataProvider;
|
||||
import com.djrapitops.plan.storage.database.sql.tables.ExtensionProviderTable;
|
||||
import com.djrapitops.plan.storage.database.transactions.ExecStatement;
|
||||
import com.djrapitops.plan.storage.database.transactions.Executable;
|
||||
@ -50,7 +49,7 @@ public class StoreServerDoubleResultTransaction extends ThrowawayTransaction {
|
||||
this.providerName = provider.getProviderInformation().getName();
|
||||
this.serverUUID = parameters.getServerUUID();
|
||||
this.value = value;
|
||||
this.percentage = provider instanceof PercentageDataProvider;
|
||||
this.percentage = provider.getProviderInformation().isPercentage();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -31,7 +31,7 @@ import static com.djrapitops.plan.storage.database.sql.building.Sql.WHERE;
|
||||
import static com.djrapitops.plan.storage.database.sql.tables.ExtensionServerValueTable.*;
|
||||
|
||||
/**
|
||||
* Transaction to store method result of a {@link com.djrapitops.plan.extension.implementation.providers.PercentageDataProvider}.
|
||||
* Transaction to store Extension String data for a server.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user