mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-09-03 18:30:36 +02:00
Implemented BooleanProvider hidden parameter
This commit is contained in:
parent
29e9f0483b
commit
4ea45ad9d9
|
@ -41,14 +41,15 @@ public class ExtensionProviderTable {
|
|||
public static final String DESCRIPTION = "description"; // Can be null
|
||||
public static final String PRIORITY = "priority";
|
||||
public static final String GROUPABLE = "groupable"; // default false
|
||||
public static final String CONDITION = "condition_name"; // Can be null
|
||||
public static final String CONDITION = "condition_name"; // Can be null, related to @Conditional
|
||||
public static final String PLUGIN_ID = "plugin_id";
|
||||
public static final String ICON_ID = "icon_id";
|
||||
public static final String TAB_ID = "tab_id"; // Can be null
|
||||
public static final String TAB_ID = "tab_id"; // Can be null, related to @Tab
|
||||
|
||||
public static final String PROVIDED_CONDITION = "provided_condition"; // Can be null
|
||||
public static final String FORMAT_TYPE = "format_type"; // Can be null
|
||||
public static final String IS_PLAYER_NAME = "player_name"; // default false
|
||||
public static final String HIDDEN = "hidden"; // default false, related to @BooleanProvider
|
||||
public static final String PROVIDED_CONDITION = "provided_condition"; // Can be null, related to @BooleanProvider
|
||||
public static final String FORMAT_TYPE = "format_type"; // Can be null, related to @NumberProvider
|
||||
public static final String IS_PLAYER_NAME = "player_name"; // default false, related to @StringProvider
|
||||
|
||||
public static final String STATEMENT_SELECT_PROVIDER_ID = "(" + SELECT + ID + FROM + TABLE_NAME +
|
||||
WHERE + PROVIDER_NAME + "=?" +
|
||||
|
@ -70,6 +71,7 @@ public class ExtensionProviderTable {
|
|||
.column(CONDITION, Sql.varchar(54)) // 50 + 4 for "not_"
|
||||
.column(PROVIDED_CONDITION, Sql.varchar(50))
|
||||
.column(FORMAT_TYPE, Sql.varchar(25))
|
||||
.column(HIDDEN, BOOL).notNull().defaultValue(false)
|
||||
.column(IS_PLAYER_NAME, BOOL).notNull().defaultValue(false)
|
||||
.column(PLUGIN_ID, INT).notNull()
|
||||
.column(ICON_ID, INT).notNull()
|
||||
|
|
|
@ -35,11 +35,13 @@ import java.util.Optional;
|
|||
public class BooleanDataProvider extends DataProvider<Boolean> {
|
||||
|
||||
private final String providedCondition;
|
||||
private final boolean hidden;
|
||||
|
||||
private BooleanDataProvider(ProviderInformation providerInformation, MethodWrapper<Boolean> method, String providedCondition) {
|
||||
private BooleanDataProvider(ProviderInformation providerInformation, MethodWrapper<Boolean> method, String providedCondition, boolean hidden) {
|
||||
super(providerInformation, method);
|
||||
|
||||
this.providedCondition = providedCondition;
|
||||
this.hidden = hidden;
|
||||
}
|
||||
|
||||
public static void placeToDataProviders(
|
||||
|
@ -53,7 +55,7 @@ public class BooleanDataProvider extends DataProvider<Boolean> {
|
|||
pluginName, method.getName(), annotation.text(), annotation.description(), providerIcon, annotation.priority(), tab, condition
|
||||
);
|
||||
|
||||
dataProviders.put(new BooleanDataProvider(providerInformation, methodWrapper, annotation.conditionName()));
|
||||
dataProviders.put(new BooleanDataProvider(providerInformation, methodWrapper, annotation.conditionName(), annotation.hidden()));
|
||||
}
|
||||
|
||||
public static Optional<String> getProvidedCondition(DataProvider<Boolean> provider) {
|
||||
|
@ -66,4 +68,12 @@ public class BooleanDataProvider extends DataProvider<Boolean> {
|
|||
public Optional<String> getProvidedCondition() {
|
||||
return providedCondition == null || providedCondition.isEmpty() ? Optional.empty() : Optional.of(StringUtils.truncate(providedCondition, 50));
|
||||
}
|
||||
|
||||
public static boolean isHidden(DataProvider<Boolean> provider) {
|
||||
return provider instanceof BooleanDataProvider && ((BooleanDataProvider) provider).isHidden();
|
||||
}
|
||||
|
||||
public boolean isHidden() {
|
||||
return hidden;
|
||||
}
|
||||
}
|
|
@ -81,6 +81,7 @@ class BooleanProviderValueGatherer {
|
|||
}
|
||||
|
||||
Optional<String> providedCondition = BooleanDataProvider.getProvidedCondition(booleanProvider);
|
||||
boolean hidden = BooleanDataProvider.isHidden(booleanProvider);
|
||||
|
||||
MethodWrapper<Boolean> method = booleanProvider.getMethod();
|
||||
Boolean result = getMethodResult(
|
||||
|
@ -104,7 +105,7 @@ class BooleanProviderValueGatherer {
|
|||
|
||||
satisfied.add(booleanProvider); // Prevents further attempts to call this provider for this player.
|
||||
database.executeTransaction(new StoreIconTransaction(providerInformation.getIcon()));
|
||||
database.executeTransaction(new StoreBooleanProviderTransaction(booleanProvider, providedCondition.orElse(null), serverUUID));
|
||||
database.executeTransaction(new StoreBooleanProviderTransaction(booleanProvider, providedCondition.orElse(null), hidden, serverUUID));
|
||||
database.executeTransaction(new StorePlayerBooleanResultTransaction(pluginName, serverUUID, method.getMethodName(), playerUUID, result));
|
||||
}
|
||||
// Remove now satisfied Providers so that they are not called again
|
||||
|
|
|
@ -116,12 +116,14 @@ public class ExtensionPlayerDataQuery implements Query<Map<UUID, List<ExtensionP
|
|||
LEFT_JOIN + ExtensionTabTable.TABLE_NAME + " t1 on t1." + ExtensionTabTable.ID + "=p1." + ExtensionProviderTable.TAB_ID +
|
||||
LEFT_JOIN + ExtensionIconTable.TABLE_NAME + " i1 on i1." + ExtensionIconTable.ID + "=p1." + ExtensionProviderTable.ICON_ID +
|
||||
LEFT_JOIN + ExtensionIconTable.TABLE_NAME + " i2 on i2." + ExtensionIconTable.ID + "=p1." + ExtensionTabTable.ICON_ID +
|
||||
WHERE + ExtensionPlayerValueTable.USER_UUID + "=?";
|
||||
WHERE + ExtensionPlayerValueTable.USER_UUID + "=?" +
|
||||
AND + "p1." + ExtensionProviderTable.HIDDEN + "=?";
|
||||
|
||||
return new QueryStatement<Map<Integer, ExtensionPlayerData.Factory>>(sql, 1000) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setString(1, playerUUID.toString());
|
||||
statement.setBoolean(2, false); // Don't select hidden values
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -42,11 +42,13 @@ import static com.djrapitops.plan.db.sql.tables.ExtensionProviderTable.*;
|
|||
public class StoreBooleanProviderTransaction extends Transaction {
|
||||
|
||||
private final String providedCondition;
|
||||
private final boolean hidden;
|
||||
private final UUID serverUUID;
|
||||
private final ProviderInformation providerInformation;
|
||||
|
||||
public StoreBooleanProviderTransaction(DataProvider<Boolean> booleanProvider, String providedCondition, UUID serverUUID) {
|
||||
public StoreBooleanProviderTransaction(DataProvider<Boolean> booleanProvider, String providedCondition, boolean hidden, UUID serverUUID) {
|
||||
this.providedCondition = providedCondition;
|
||||
this.hidden = hidden;
|
||||
this.serverUUID = serverUUID;
|
||||
this.providerInformation = booleanProvider.getProviderInformation();
|
||||
}
|
||||
|
@ -76,7 +78,8 @@ public class StoreBooleanProviderTransaction extends Transaction {
|
|||
TAB_ID + "=" + ExtensionTabTable.STATEMENT_SELECT_TAB_ID + "," +
|
||||
ICON_ID + "=" + ExtensionIconTable.STATEMENT_SELECT_ICON_ID +
|
||||
WHERE + PLUGIN_ID + "=" + ExtensionPluginTable.STATEMENT_SELECT_PLUGIN_ID +
|
||||
AND + PROVIDER_NAME + "=?";
|
||||
AND + PROVIDER_NAME + "=?," +
|
||||
HIDDEN + "=?";
|
||||
|
||||
return new ExecStatement(sql) {
|
||||
@Override
|
||||
|
@ -102,6 +105,7 @@ public class StoreBooleanProviderTransaction extends Transaction {
|
|||
ExtensionIconTable.set3IconValuesToStatement(statement, 9, providerInformation.getIcon());
|
||||
ExtensionPluginTable.set2PluginValuesToStatement(statement, 12, providerInformation.getPluginName(), serverUUID);
|
||||
statement.setString(14, providerInformation.getName());
|
||||
statement.setBoolean(15, hidden);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -120,7 +124,7 @@ public class StoreBooleanProviderTransaction extends Transaction {
|
|||
") VALUES (?,?,?,?,?,?," +
|
||||
ExtensionTabTable.STATEMENT_SELECT_TAB_ID + "," +
|
||||
ExtensionIconTable.STATEMENT_SELECT_ICON_ID + "," +
|
||||
ExtensionPluginTable.STATEMENT_SELECT_PLUGIN_ID + ")";
|
||||
ExtensionPluginTable.STATEMENT_SELECT_PLUGIN_ID + ", ?)";
|
||||
return new ExecStatement(sql) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
|
@ -145,6 +149,7 @@ public class StoreBooleanProviderTransaction extends Transaction {
|
|||
ExtensionTabTable.set3TabValuesToStatement(statement, 7, providerInformation.getTab().orElse("No Tab"), providerInformation.getPluginName(), serverUUID);
|
||||
ExtensionIconTable.set3IconValuesToStatement(statement, 10, providerInformation.getIcon());
|
||||
ExtensionPluginTable.set2PluginValuesToStatement(statement, 13, providerInformation.getPluginName(), serverUUID);
|
||||
statement.setBoolean(15, hidden);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user