diff --git a/api/src/main/java/net/luckperms/api/cacheddata/CachedMetaData.java b/api/src/main/java/net/luckperms/api/cacheddata/CachedMetaData.java index 57c18bb3e..646fb6f34 100644 --- a/api/src/main/java/net/luckperms/api/cacheddata/CachedMetaData.java +++ b/api/src/main/java/net/luckperms/api/cacheddata/CachedMetaData.java @@ -33,7 +33,9 @@ import org.jetbrains.annotations.Unmodifiable; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.SortedMap; +import java.util.function.Function; /** * Holds cached meta lookup data for a specific set of contexts. @@ -46,7 +48,37 @@ public interface CachedMetaData extends CachedData { * @param key the key * @return the value */ - @Nullable String getMetaValue(String key); + @Nullable String getMetaValue(@NonNull String key); + + /** + * Gets a value for the given meta key, and runs it through the given {@code transformer}. + * + *
If no such meta value exists, an {@link Optional#empty() empty optional} is returned. + * (the transformer will never be passed a null argument)
+ * + *The transformer is allowed to throw {@link IllegalArgumentException} or return null. This + * will also result in an {@link Optional#empty() empty optional} being returned.
+ * + *For example, to parse and return an integer meta value, use:
+ *+ * + * @param key the key + * @param valueTransformer the transformer used to transform the value + * @param+ * getMetaValue("my-int-val", Integer::parseInt).orElse(0); + *