mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-12-29 12:37:40 +01:00
Fix MetaValueSelector NPE
This commit is contained in:
parent
d319d8dc52
commit
acdc259771
@ -23,7 +23,7 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.common.cacheddata.result;
|
||||
package net.luckperms.api.cacheddata;
|
||||
|
||||
import net.luckperms.api.node.Node;
|
||||
|
||||
@ -33,6 +33,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
* Represents the result of a cached data lookup
|
||||
*
|
||||
* @param <T> the result type
|
||||
* @since 5.4
|
||||
*/
|
||||
public interface Result<T, N extends Node> {
|
||||
|
@ -25,6 +25,7 @@
|
||||
|
||||
package net.luckperms.api.query.meta;
|
||||
|
||||
import net.luckperms.api.cacheddata.Result;
|
||||
import net.luckperms.api.node.types.MetaNode;
|
||||
import net.luckperms.api.query.OptionKey;
|
||||
|
||||
@ -54,6 +55,6 @@ public interface MetaValueSelector {
|
||||
* @param values the values, in the order in which they were accumulated.
|
||||
* @return the selected value
|
||||
*/
|
||||
@NonNull MetaNode selectValue(@NonNull String key, @NonNull List<MetaNode> values);
|
||||
@NonNull Result<String, MetaNode> selectValue(@NonNull String key, @NonNull List<? extends Result<String, MetaNode>> values);
|
||||
|
||||
}
|
||||
|
@ -25,6 +25,7 @@
|
||||
|
||||
package me.lucko.luckperms.common.cacheddata.result;
|
||||
|
||||
import net.luckperms.api.cacheddata.Result;
|
||||
import net.luckperms.api.node.Node;
|
||||
import net.luckperms.api.node.types.ChatMetaNode;
|
||||
import net.luckperms.api.node.types.MetaNode;
|
||||
|
@ -28,6 +28,7 @@ package me.lucko.luckperms.common.cacheddata.result;
|
||||
import me.lucko.luckperms.common.calculator.PermissionCalculator;
|
||||
import me.lucko.luckperms.common.calculator.processor.PermissionProcessor;
|
||||
|
||||
import net.luckperms.api.cacheddata.Result;
|
||||
import net.luckperms.api.node.Node;
|
||||
import net.luckperms.api.util.Tristate;
|
||||
|
||||
|
@ -40,6 +40,7 @@ import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.verbose.event.CheckOrigin;
|
||||
|
||||
import net.luckperms.api.cacheddata.CachedMetaData;
|
||||
import net.luckperms.api.cacheddata.Result;
|
||||
import net.luckperms.api.metastacking.MetaStackDefinition;
|
||||
import net.luckperms.api.node.types.ChatMetaNode;
|
||||
import net.luckperms.api.node.types.MetaNode;
|
||||
@ -92,12 +93,12 @@ public class MetaCache extends UsageTracked implements CachedMetaData {
|
||||
continue;
|
||||
}
|
||||
|
||||
MetaNode selected = metaValueSelector.selectValue(e.getKey(), Lists.transform(e.getValue(), StringResult::node));
|
||||
Result<String, MetaNode> selected = metaValueSelector.selectValue(e.getKey(), e.getValue());
|
||||
if (selected == null) {
|
||||
throw new NullPointerException(metaValueSelector + " returned null");
|
||||
}
|
||||
|
||||
builder.put(e.getKey(), StringResult.of(selected));
|
||||
builder.put(e.getKey(), (StringResult<MetaNode>) selected);
|
||||
}
|
||||
this.flattenedMeta = builder.build();
|
||||
this.meta = new LowerCaseMetaMap(meta);
|
||||
|
@ -25,6 +25,7 @@
|
||||
|
||||
package me.lucko.luckperms.common.cacheddata.type;
|
||||
|
||||
import net.luckperms.api.cacheddata.Result;
|
||||
import net.luckperms.api.node.types.MetaNode;
|
||||
import net.luckperms.api.query.meta.MetaValueSelector;
|
||||
|
||||
@ -44,7 +45,7 @@ public class SimpleMetaValueSelector implements MetaValueSelector {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull MetaNode selectValue(@NonNull String key, @NonNull List<MetaNode> values) {
|
||||
public @NonNull Result<String, MetaNode> selectValue(@NonNull String key, @NonNull List<? extends Result<String, MetaNode>> values) {
|
||||
switch (values.size()) {
|
||||
case 0:
|
||||
throw new IllegalArgumentException("values is empty");
|
||||
@ -58,7 +59,7 @@ public class SimpleMetaValueSelector implements MetaValueSelector {
|
||||
public enum Strategy {
|
||||
INHERITANCE {
|
||||
@Override
|
||||
public MetaNode select(List<MetaNode> values) {
|
||||
public Result<String, MetaNode> select(List<? extends Result<String, MetaNode>> values) {
|
||||
return values.get(0);
|
||||
}
|
||||
},
|
||||
@ -66,7 +67,7 @@ public class SimpleMetaValueSelector implements MetaValueSelector {
|
||||
private final DoubleSelectionPredicate selection = (value, current) -> value > current;
|
||||
|
||||
@Override
|
||||
public MetaNode select(List<MetaNode> values) {
|
||||
public Result<String, MetaNode> select(List<? extends Result<String, MetaNode>> values) {
|
||||
return selectNumber(values, this.selection);
|
||||
}
|
||||
},
|
||||
@ -74,12 +75,12 @@ public class SimpleMetaValueSelector implements MetaValueSelector {
|
||||
private final DoubleSelectionPredicate selection = (value, current) -> value < current;
|
||||
|
||||
@Override
|
||||
public MetaNode select(List<MetaNode> values) {
|
||||
public Result<String, MetaNode> select(List<? extends Result<String, MetaNode>> values) {
|
||||
return selectNumber(values, this.selection);
|
||||
}
|
||||
};
|
||||
|
||||
public abstract MetaNode select(List<MetaNode> values);
|
||||
public abstract Result<String, MetaNode> select(List<? extends Result<String, MetaNode>> values);
|
||||
|
||||
public static Strategy parse(String s) {
|
||||
try {
|
||||
@ -95,16 +96,15 @@ public class SimpleMetaValueSelector implements MetaValueSelector {
|
||||
boolean shouldSelect(double value, double current);
|
||||
}
|
||||
|
||||
private static MetaNode selectNumber(List<MetaNode> values, DoubleSelectionPredicate selection) {
|
||||
private static Result<String, MetaNode> selectNumber(List<? extends Result<String, MetaNode>> values, DoubleSelectionPredicate selection) {
|
||||
double current = 0;
|
||||
MetaNode selected = null;
|
||||
Result<String, MetaNode> selected = null;
|
||||
|
||||
for (MetaNode node : values) {
|
||||
String value = node.getMetaValue();
|
||||
for (Result<String, MetaNode> result : values) {
|
||||
try {
|
||||
double parse = Double.parseDouble(value);
|
||||
double parse = Double.parseDouble(result.result());
|
||||
if (selected == null || selection.shouldSelect(parse, current)) {
|
||||
selected = node;
|
||||
selected = result;
|
||||
current = parse;
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
|
@ -27,7 +27,6 @@ package me.lucko.luckperms.common.verbose;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import me.lucko.luckperms.common.cacheddata.result.Result;
|
||||
import me.lucko.luckperms.common.cacheddata.result.TristateResult;
|
||||
import me.lucko.luckperms.common.http.AbstractHttpClient;
|
||||
import me.lucko.luckperms.common.http.BytebinClient;
|
||||
@ -47,6 +46,7 @@ import me.lucko.luckperms.common.verbose.event.VerboseEvent;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.ComponentLike;
|
||||
import net.kyori.adventure.text.event.HoverEvent;
|
||||
import net.luckperms.api.cacheddata.Result;
|
||||
import net.luckperms.api.node.Node;
|
||||
import net.luckperms.api.node.types.MetaNode;
|
||||
import net.luckperms.api.query.QueryMode;
|
||||
|
@ -27,13 +27,13 @@ package me.lucko.luckperms.common.verbose.event;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import me.lucko.luckperms.common.cacheddata.result.Result;
|
||||
import me.lucko.luckperms.common.util.StackTracePrinter;
|
||||
import me.lucko.luckperms.common.util.gson.JArray;
|
||||
import me.lucko.luckperms.common.util.gson.JObject;
|
||||
import me.lucko.luckperms.common.verbose.VerboseCheckTarget;
|
||||
import me.lucko.luckperms.common.verbose.expression.BooleanExpressionCompiler.VariableEvaluator;
|
||||
|
||||
import net.luckperms.api.cacheddata.Result;
|
||||
import net.luckperms.api.context.Context;
|
||||
import net.luckperms.api.query.QueryMode;
|
||||
import net.luckperms.api.query.QueryOptions;
|
||||
|
Loading…
Reference in New Issue
Block a user