Interface Key

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

    public interface Key
    extends java.lang.Comparable<Key>, net.kyori.examination.Examinable, Namespaced, Keyed
    An identifying object used to fetch and/or store unique objects.

    A key consists of:

    namespace
    in most cases this should be your plugin or organization name
    value
    what this key leads to, e.g "translations" or "entity.firework_rocket.blast"

    Valid characters for namespaces are [a-z0-9_.-].

    Valid characters for values are [a-z0-9/._-].

    Some examples of possible custom keys:

    • my_plugin:translations
    • my_plugin:weapon.amazing-weapon_damage-attribute
    • my_organization:music.song_1
    • my_organization:item.magic_button
    Since:
    4.0.0
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static char DEFAULT_SEPARATOR
      The default namespace and value separator.
      static java.lang.String MINECRAFT_NAMESPACE
      The namespace for Minecraft.
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      static boolean allowedInNamespace​(char character)
      Checks if value is a valid character in a namespace.
      static boolean allowedInValue​(char character)
      Checks if value is a valid character in a value.
      @NotNull java.lang.String asString()
      Returns the string representation of this key.
      static @NotNull java.util.Comparator<? super Key> comparator()
      Gets the comparator.
      default int compareTo​(@NotNull Key that)  
      default @NotNull java.util.stream.Stream<? extends net.kyori.examination.ExaminableProperty> examinableProperties()  
      default @NotNull Key key()
      Gets the key.
      static @NotNull Key key​(@NotNull java.lang.String string)
      Creates a key.
      static @NotNull Key key​(@NotNull java.lang.String string, char character)
      Creates a key.
      static @NotNull Key key​(@NotNull java.lang.String namespace, @NotNull java.lang.String value)
      Creates a key.
      static @NotNull Key key​(@NotNull Namespaced namespaced, @NotNull java.lang.String value)
      Creates a key.
      @NotNull java.lang.String namespace()
      Gets the namespace.
      static boolean parseable​(@Nullable java.lang.String string)
      Checks if string can be parsed into a Key.
      static boolean parseableNamespace​(@NotNull java.lang.String namespace)
      Checks if value is a valid namespace.
      static boolean parseableValue​(@NotNull java.lang.String value)
      Checks if value is a valid value.
      @NotNull java.lang.String value()
      Gets the value.
      • Methods inherited from interface net.kyori.examination.Examinable

        examinableName, examine
    • Field Detail

      • MINECRAFT_NAMESPACE

        static final java.lang.String MINECRAFT_NAMESPACE
        The namespace for Minecraft.
        Since:
        4.0.0
        See Also:
        Constant Field Values
      • DEFAULT_SEPARATOR

        static final char DEFAULT_SEPARATOR
        The default namespace and value separator.
        Since:
        4.12.0
        See Also:
        Constant Field Values
    • Method Detail

      • key

        @NotNull
        static @NotNull Key key​(@NotNull
                                @NotNull java.lang.String string)
        Creates a key.

        This will parse string as a key, using : as a separator between the namespace and the value.

        The namespace is optional. If you do not provide one (for example, if you provide just player or :player as the string) then MINECRAFT_NAMESPACE will be used as a namespace and string will be used as the value, removing the colon if necessary.

        Parameters:
        string - the string
        Returns:
        the key
        Throws:
        InvalidKeyException - if the namespace or value contains an invalid character
        Since:
        4.0.0
      • key

        @NotNull
        static @NotNull Key key​(@NotNull
                                @NotNull java.lang.String string,
                                char character)
        Creates a key.

        This will parse string as a key, using character as a separator between the namespace and the value.

        The namespace is optional. If you do not provide one (for example, if you provide player or character + "player" as the string) then MINECRAFT_NAMESPACE will be used as a namespace and string will be used as the value, removing the provided separator character if necessary.

        Parameters:
        string - the string
        character - the character that separates the namespace from the value
        Returns:
        the key
        Throws:
        InvalidKeyException - if the namespace or value contains an invalid character
        Since:
        4.0.0
      • key

        @NotNull
        static @NotNull Key key​(@NotNull
                                @NotNull Namespaced namespaced,
                                @NotNull
                                @NotNull java.lang.String value)
        Creates a key.
        Parameters:
        namespaced - the namespace source
        value - the value
        Returns:
        the key
        Throws:
        InvalidKeyException - if the namespace or value contains an invalid character
        Since:
        4.4.0
      • key

        @NotNull
        static @NotNull Key key​(@NotNull
                                @NotNull java.lang.String namespace,
                                @NotNull
                                @NotNull java.lang.String value)
        Creates a key.
        Parameters:
        namespace - the namespace
        value - the value
        Returns:
        the key
        Throws:
        InvalidKeyException - if the namespace or value contains an invalid character
        Since:
        4.0.0
      • comparator

        @NotNull
        static @NotNull java.util.Comparator<? super Key> comparator()
        Gets the comparator.

        The value is compared first, followed by the namespace.

        Returns:
        a comparator for keys
        Since:
        4.10.0
      • parseable

        static boolean parseable​(@Nullable
                                 @Nullable java.lang.String string)
        Checks if string can be parsed into a Key.
        Parameters:
        string - the input string
        Returns:
        true if string can be parsed into a Key, false otherwise
        Since:
        4.12.0
      • parseableNamespace

        static boolean parseableNamespace​(@NotNull
                                          @NotNull java.lang.String namespace)
        Checks if value is a valid namespace.
        Parameters:
        namespace - the string to check
        Returns:
        true if value is a valid namespace, false otherwise
        Since:
        4.12.0
      • parseableValue

        static boolean parseableValue​(@NotNull
                                      @NotNull java.lang.String value)
        Checks if value is a valid value.
        Parameters:
        value - the string to check
        Returns:
        true if value is a valid value, false otherwise
        Since:
        4.12.0
      • allowedInNamespace

        static boolean allowedInNamespace​(char character)
        Checks if value is a valid character in a namespace.
        Parameters:
        character - the character to check
        Returns:
        true if value is a valid character in a namespace, false otherwise
        Since:
        4.12.0
      • allowedInValue

        static boolean allowedInValue​(char character)
        Checks if value is a valid character in a value.
        Parameters:
        character - the character to check
        Returns:
        true if value is a valid character in a value, false otherwise
        Since:
        4.12.0
      • namespace

        @NotNull
        @NotNull java.lang.String namespace()
        Gets the namespace.
        Specified by:
        namespace in interface Namespaced
        Returns:
        the namespace
        Since:
        4.0.0
      • value

        @NotNull
        @NotNull java.lang.String value()
        Gets the value.
        Returns:
        the value
        Since:
        4.0.0
      • asString

        @NotNull
        @NotNull java.lang.String asString()
        Returns the string representation of this key.
        Returns:
        the string representation
        Since:
        4.0.0
      • examinableProperties

        @NotNull
        default @NotNull java.util.stream.Stream<? extends net.kyori.examination.ExaminableProperty> examinableProperties()
        Specified by:
        examinableProperties in interface net.kyori.examination.Examinable
      • compareTo

        default int compareTo​(@NotNull
                              @NotNull Key that)
        Specified by:
        compareTo in interface java.lang.Comparable<Key>
      • key

        @NotNull
        default @NotNull Key key()
        Description copied from interface: Keyed
        Gets the key.
        Specified by:
        key in interface Keyed
        Returns:
        the key