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 a NamespacedKey.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 NamespacedKey
      defaultNamespace - 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

      public static boolean isValidKey​(String string)
      Check whether or not the provided string is a valid key for a NamespacedKey.
      Parameters:
      string - the string to check
      Returns:
      true if valid, false otherwise