diff --git a/common/src/main/java/me/lucko/luckperms/common/cacheddata/result/Result.java b/api/src/main/java/net/luckperms/api/cacheddata/Result.java similarity index 97% rename from common/src/main/java/me/lucko/luckperms/common/cacheddata/result/Result.java rename to api/src/main/java/net/luckperms/api/cacheddata/Result.java index be4294eea..0f61190f6 100644 --- a/common/src/main/java/me/lucko/luckperms/common/cacheddata/result/Result.java +++ b/api/src/main/java/net/luckperms/api/cacheddata/Result.java @@ -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 the result type + * @since 5.4 */ public interface Result { diff --git a/api/src/main/java/net/luckperms/api/query/meta/MetaValueSelector.java b/api/src/main/java/net/luckperms/api/query/meta/MetaValueSelector.java index a73eac171..c81170971 100644 --- a/api/src/main/java/net/luckperms/api/query/meta/MetaValueSelector.java +++ b/api/src/main/java/net/luckperms/api/query/meta/MetaValueSelector.java @@ -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 values); + @NonNull Result selectValue(@NonNull String key, @NonNull List> values); } diff --git a/common/src/main/java/me/lucko/luckperms/common/cacheddata/result/StringResult.java b/common/src/main/java/me/lucko/luckperms/common/cacheddata/result/StringResult.java index 8efaff7f5..b8567a3b0 100644 --- a/common/src/main/java/me/lucko/luckperms/common/cacheddata/result/StringResult.java +++ b/common/src/main/java/me/lucko/luckperms/common/cacheddata/result/StringResult.java @@ -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; diff --git a/common/src/main/java/me/lucko/luckperms/common/cacheddata/result/TristateResult.java b/common/src/main/java/me/lucko/luckperms/common/cacheddata/result/TristateResult.java index 0df78b645..46886566e 100644 --- a/common/src/main/java/me/lucko/luckperms/common/cacheddata/result/TristateResult.java +++ b/common/src/main/java/me/lucko/luckperms/common/cacheddata/result/TristateResult.java @@ -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; diff --git a/common/src/main/java/me/lucko/luckperms/common/cacheddata/type/MetaCache.java b/common/src/main/java/me/lucko/luckperms/common/cacheddata/type/MetaCache.java index cfde15f96..066d1f03c 100644 --- a/common/src/main/java/me/lucko/luckperms/common/cacheddata/type/MetaCache.java +++ b/common/src/main/java/me/lucko/luckperms/common/cacheddata/type/MetaCache.java @@ -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 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) selected); } this.flattenedMeta = builder.build(); this.meta = new LowerCaseMetaMap(meta); diff --git a/common/src/main/java/me/lucko/luckperms/common/cacheddata/type/SimpleMetaValueSelector.java b/common/src/main/java/me/lucko/luckperms/common/cacheddata/type/SimpleMetaValueSelector.java index c033dd41b..d8cdd1f14 100644 --- a/common/src/main/java/me/lucko/luckperms/common/cacheddata/type/SimpleMetaValueSelector.java +++ b/common/src/main/java/me/lucko/luckperms/common/cacheddata/type/SimpleMetaValueSelector.java @@ -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 values) { + public @NonNull Result selectValue(@NonNull String key, @NonNull List> 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 values) { + public Result select(List> 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 values) { + public Result select(List> 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 values) { + public Result select(List> values) { return selectNumber(values, this.selection); } }; - public abstract MetaNode select(List values); + public abstract Result select(List> 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 values, DoubleSelectionPredicate selection) { + private static Result selectNumber(List> values, DoubleSelectionPredicate selection) { double current = 0; - MetaNode selected = null; + Result selected = null; - for (MetaNode node : values) { - String value = node.getMetaValue(); + for (Result 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) { diff --git a/common/src/main/java/me/lucko/luckperms/common/verbose/VerboseListener.java b/common/src/main/java/me/lucko/luckperms/common/verbose/VerboseListener.java index ef7fd4acb..22c082368 100644 --- a/common/src/main/java/me/lucko/luckperms/common/verbose/VerboseListener.java +++ b/common/src/main/java/me/lucko/luckperms/common/verbose/VerboseListener.java @@ -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; diff --git a/common/src/main/java/me/lucko/luckperms/common/verbose/event/VerboseEvent.java b/common/src/main/java/me/lucko/luckperms/common/verbose/event/VerboseEvent.java index 14f500e06..d1457d178 100644 --- a/common/src/main/java/me/lucko/luckperms/common/verbose/event/VerboseEvent.java +++ b/common/src/main/java/me/lucko/luckperms/common/verbose/event/VerboseEvent.java @@ -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;