mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-04 23:48:42 +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 FormatType formatType; // can be null, NumberProvider
|
||||||
private final boolean isPlayerName; // default false, StringProvider
|
private final boolean isPlayerName; // default false, StringProvider
|
||||||
private final Color tableColor; // can be null, TableProvider
|
private final Color tableColor; // can be null, TableProvider
|
||||||
|
private final boolean percentage; // affects where doubles are stored
|
||||||
|
|
||||||
private ProviderInformation(ProviderInformation.Builder builder) {
|
private ProviderInformation(ProviderInformation.Builder builder) {
|
||||||
super(builder.name, builder.text, builder.description, builder.icon, builder.priority);
|
super(builder.name, builder.text, builder.description, builder.icon, builder.priority);
|
||||||
@ -54,6 +55,7 @@ public class ProviderInformation extends ExtensionDescriptive {
|
|||||||
formatType = builder.formatType;
|
formatType = builder.formatType;
|
||||||
isPlayerName = builder.isPlayerName;
|
isPlayerName = builder.isPlayerName;
|
||||||
tableColor = builder.tableColor;
|
tableColor = builder.tableColor;
|
||||||
|
percentage = builder.percentage;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ProviderInformation.Builder builder(String pluginName) {
|
public static ProviderInformation.Builder builder(String pluginName) {
|
||||||
@ -124,6 +126,10 @@ public class ProviderInformation extends ExtensionDescriptive {
|
|||||||
return tableColor;
|
return tableColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isPercentage() {
|
||||||
|
return percentage;
|
||||||
|
}
|
||||||
|
|
||||||
public static class Builder {
|
public static class Builder {
|
||||||
private final String pluginName;
|
private final String pluginName;
|
||||||
private String name;
|
private String name;
|
||||||
@ -139,6 +145,7 @@ public class ProviderInformation extends ExtensionDescriptive {
|
|||||||
private FormatType formatType; // can be null, NumberProvider
|
private FormatType formatType; // can be null, NumberProvider
|
||||||
private boolean isPlayerName = false; // default false, StringProvider
|
private boolean isPlayerName = false; // default false, StringProvider
|
||||||
private Color tableColor; // can be null, TableProvider
|
private Color tableColor; // can be null, TableProvider
|
||||||
|
private boolean percentage; // affects where doubles are stored
|
||||||
|
|
||||||
public Builder(String pluginName) {
|
public Builder(String pluginName) {
|
||||||
this.pluginName = pluginName;
|
this.pluginName = pluginName;
|
||||||
@ -209,6 +216,11 @@ public class ProviderInformation extends ExtensionDescriptive {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Builder setAsPercentage() {
|
||||||
|
percentage = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public ProviderInformation build() {
|
public ProviderInformation build() {
|
||||||
return new ProviderInformation(this);
|
return new ProviderInformation(this);
|
||||||
}
|
}
|
||||||
|
@ -24,16 +24,14 @@ import com.djrapitops.plan.extension.implementation.ProviderInformation;
|
|||||||
import java.lang.reflect.Method;
|
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
|
* @author Rsl1122
|
||||||
*/
|
*/
|
||||||
public class PercentageDataProvider extends DataProvider<Double> {
|
public class PercentageDataProvider {
|
||||||
|
|
||||||
// TODO Remove need for instanceof PercentageDataProvider
|
private PercentageDataProvider() {
|
||||||
|
// Static method class
|
||||||
private PercentageDataProvider(ProviderInformation providerInformation, MethodWrapper<Double> methodWrapper) {
|
|
||||||
super(providerInformation, methodWrapper);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void placeToDataProviders(
|
public static void placeToDataProviders(
|
||||||
@ -52,10 +50,11 @@ public class PercentageDataProvider extends DataProvider<Double> {
|
|||||||
).setShowInPlayersTable(annotation.showInPlayerTable())
|
).setShowInPlayersTable(annotation.showInPlayerTable())
|
||||||
.setCondition(condition)
|
.setCondition(condition)
|
||||||
.setTab(tab)
|
.setTab(tab)
|
||||||
|
.setAsPercentage()
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
MethodWrapper<Double> methodWrapper = new MethodWrapper<>(method, Double.class);
|
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.DataProvider;
|
||||||
import com.djrapitops.plan.extension.implementation.providers.Parameters;
|
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.sql.tables.ExtensionProviderTable;
|
||||||
import com.djrapitops.plan.storage.database.transactions.ExecStatement;
|
import com.djrapitops.plan.storage.database.transactions.ExecStatement;
|
||||||
import com.djrapitops.plan.storage.database.transactions.Executable;
|
import com.djrapitops.plan.storage.database.transactions.Executable;
|
||||||
@ -57,7 +56,7 @@ public class StorePlayerDoubleResultTransaction extends ThrowawayTransaction {
|
|||||||
this.serverUUID = parameters.getServerUUID();
|
this.serverUUID = parameters.getServerUUID();
|
||||||
this.playerUUID = parameters.getPlayerUUID();
|
this.playerUUID = parameters.getPlayerUUID();
|
||||||
this.value = value;
|
this.value = value;
|
||||||
this.percentage = provider instanceof PercentageDataProvider;
|
this.percentage = provider.getProviderInformation().isPercentage();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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.DataProvider;
|
||||||
import com.djrapitops.plan.extension.implementation.providers.Parameters;
|
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.sql.tables.ExtensionProviderTable;
|
||||||
import com.djrapitops.plan.storage.database.transactions.ExecStatement;
|
import com.djrapitops.plan.storage.database.transactions.ExecStatement;
|
||||||
import com.djrapitops.plan.storage.database.transactions.Executable;
|
import com.djrapitops.plan.storage.database.transactions.Executable;
|
||||||
@ -50,7 +49,7 @@ public class StoreServerDoubleResultTransaction extends ThrowawayTransaction {
|
|||||||
this.providerName = provider.getProviderInformation().getName();
|
this.providerName = provider.getProviderInformation().getName();
|
||||||
this.serverUUID = parameters.getServerUUID();
|
this.serverUUID = parameters.getServerUUID();
|
||||||
this.value = value;
|
this.value = value;
|
||||||
this.percentage = provider instanceof PercentageDataProvider;
|
this.percentage = provider.getProviderInformation().isPercentage();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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.*;
|
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
|
* @author Rsl1122
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user