diff --git a/paper-api/src/main/java/org/bukkit/Registry.java b/paper-api/src/main/java/org/bukkit/Registry.java index a77320257b..ea80520c19 100644 --- a/paper-api/src/main/java/org/bukkit/Registry.java +++ b/paper-api/src/main/java/org/bukkit/Registry.java @@ -1,5 +1,6 @@ package org.bukkit; +import com.google.common.base.Preconditions; import com.google.common.base.Predicates; import com.google.common.collect.ImmutableMap; import java.util.Arrays; @@ -220,6 +221,24 @@ public interface Registry extends Iterable { @Nullable T get(@NotNull NamespacedKey key); + /** + * Attempts to match the registered object with the given key. + *

+ * This will attempt to find a reasonable match based on the provided input + * and may do so through unspecified means. + * + * @param input non-null input + * @return registered object or null if does not exist + */ + @Nullable + default T match(@NotNull String input) { + Preconditions.checkArgument(input != null, "input must not be null"); + + String filtered = input.toLowerCase().replaceAll("\\s+", "_").replaceAll("\\W", ""); + NamespacedKey namespacedKey = NamespacedKey.fromString(filtered); + return (namespacedKey != null) ? get(namespacedKey) : null; + } + static final class SimpleRegistry & Keyed> implements Registry { private final Map map;