Package wtf.choco.arrows.util
Class NamespacedKeyUtil
java.lang.Object
wtf.choco.arrows.util.NamespacedKeyUtil
public final class NamespacedKeyUtil extends Object
A utility class to better handle
NamespacedKey
objects.- Author:
- Parker Hawke - Choco
-
Method Summary
Modifier and Type Method Description static @Nullable org.bukkit.NamespacedKey
fromString(@NotNull String key, @Nullable org.bukkit.plugin.Plugin defaultNamespace)
Get a NamespacedKey from the supplied string with a default namespace if a namespace is not defined.static boolean
isValidKey(String string)
Check whether or not the provided string is a valid key for aNamespacedKey
.
-
Method Details
-
fromString
@Nullable public static @Nullable org.bukkit.NamespacedKey fromString(@NotNull @NotNull String key, @Nullable @Nullable org.bukkit.plugin.Plugin defaultNamespace)Get a NamespacedKey from the supplied string with a default namespace if a namespace is not defined. This is a utility method meant to fetch a NamespacedKey from user input. Please note that casing does matter and any instance of uppercase characters will be considered invalid. The input contract is as follows:fromString("foo", plugin) -> "plugin:foo" fromString("foo:bar", plugin) -> "foo:bar" fromString("foo", null) -> "minecraft:foo" fromString("Foo", plugin) -> null fromString(":fOO", plugin) -> null fromString("foo:bar:bazz", plugin) -> null fromString("", plugin) -> null
- Parameters:
key
- the key to convert to a NamespacedKeydefaultNamespace
- the default namespace to use if none was supplied. If null, the minecraft namespace will be used- Returns:
- the created NamespacedKey. null if invalid key
-
isValidKey
Check whether or not the provided string is a valid key for aNamespacedKey
.- Parameters:
string
- the string to check- Returns:
- true if valid, false otherwise
-