Interface ResourceKey

  • All Superinterfaces:
    java.lang.Comparable<Key>, net.kyori.examination.Examinable, Key, Keyed, Namespaced

    public interface ResourceKey
    extends Key
    An object representation of a location or pointer to resources. The key can be represented as a String by Object.toString(). The key is built with two parts:
    1. The Namespace
    2. The Value
    Normally, the namespace is lowercased and likewise, so is the value. This is a uniform format for all uses of ResourceKey, including but not restricted to DataRegistrations, ConfigurationNodes, DataTranslators, and DataSerializables.

    Note that the methods minecraft(String) and sponge(String) should only be used by the implementations for creating new keys and usage by plugins may result in a crash condition by the implementation.

    • Field Detail

      • BRIGADIER_NAMESPACE

        static final java.lang.String BRIGADIER_NAMESPACE
        The brigadier namespace.
        See Also:
        Constant Field Values
      • MINECRAFT_NAMESPACE

        static final java.lang.String MINECRAFT_NAMESPACE
        The minecraft namespace.
        See Also:
        Constant Field Values
      • SPONGE_NAMESPACE

        static final java.lang.String SPONGE_NAMESPACE
        The sponge namespace.
        See Also:
        Constant Field Values
    • Method Detail

      • brigadier

        static @NonNull ResourceKey brigadier​(java.lang.String value)
        Creates a resource key with a namespace of brigadier.
        Parameters:
        value - The value
        Returns:
        A new resource key
      • minecraft

        static @NonNull ResourceKey minecraft​(java.lang.String value)
        Creates a resource key with a namespace of minecraft.
        Parameters:
        value - The value
        Returns:
        A new resource key
      • sponge

        static @NonNull ResourceKey sponge​(java.lang.String value)
        Creates a resource key with a namespace of sponge.
        Parameters:
        value - The value
        Returns:
        A new resource key
      • builder

        static ResourceKey.Builder builder()
        Creates a new ResourceKey.Builder for creating ResourceKeys. The builder can be used for creating keys based on PluginContainers, Objects of plugins, and String namespaces.
        Returns:
        The new builder instance
      • of

        static ResourceKey of​(java.lang.String namespace,
                              java.lang.String value)
        Creates a resource key.
        Parameters:
        namespace - The namespace
        value - The value
        Returns:
        A new resource key
      • of

        static ResourceKey of​(org.spongepowered.plugin.PluginContainer plugin,
                              java.lang.String value)
        Creates a resource key.
        Parameters:
        plugin - The plugin
        value - The value
        Returns:
        A new resource key
      • resolve

        static ResourceKey resolve​(java.lang.String formatted)
        Resolves a resource key from a string.

        If no namespace is found in formatted then MINECRAFT_NAMESPACE will be the namespace.

        Parameters:
        formatted - The formatted string to parse
        Returns:
        A new resource key
      • formatted

        default java.lang.String formatted()
        Gets this key as a formatted value.

        It is up to the implementation to determine the formatting. In vanilla Minecraft, keys are formatted as "namespace:value". For example, "minecraft:carrot".

        Returns:
        The key, formatted
      • asString

        default java.lang.String asString()
        Specified by:
        asString in interface Key
      • compareTo

        default int compareTo​(Key o)
        Specified by:
        compareTo in interface java.lang.Comparable<Key>
        Specified by:
        compareTo in interface Key