Interface Key
- All Superinterfaces:
Comparable<Key>, Keyed, Namespaced
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
FieldsModifier and TypeFieldDescriptionstatic final charThe default namespace and value separator.static final StringThe namespace for Minecraft. -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanallowedInNamespace(char character) Checks ifvalueis a valid character in a namespace.static booleanallowedInValue(char character) Checks ifvalueis a valid character in a value.default StringReturns the string representation of this key in minimal form.asString()Returns the string representation of this key.static OptionalIntcheckNamespace(String namespace) Checks ifvalueis a valid namespace.static OptionalIntcheckValue(String value) Checks ifvalueis a valid value.static Comparator<? super Key> Gets the comparator.default intdefault Keykey()Gets the key.static KeyCreates a key.static KeyCreates a key.static KeyCreates a key.static Keykey(Namespaced namespaced, String value) Creates a key.Gets the namespace.static booleanChecks ifstringcan be parsed into aKey.static booleanparseableNamespace(String namespace) Checks ifvalueis a valid namespace.static booleanparseableValue(String value) Checks ifvalueis a valid value.value()Gets the value.
-
Field Details
-
MINECRAFT_NAMESPACE
-
DEFAULT_SEPARATOR
static final char DEFAULT_SEPARATORThe default namespace and value separator.- Since:
- 4.12.0
- See Also:
-
-
Method Details
-
key
Creates a key.This will parse
stringas 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
playeror:playeras the string) thenMINECRAFT_NAMESPACEwill be used as a namespace andstringwill 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
Creates a key.This will parse
stringas a key, usingcharacteras a separator between the namespace and the value.The namespace is optional. If you do not provide one (for example, if you provide
playerorcharacter + "player"as the string) thenMINECRAFT_NAMESPACEwill be used as a namespace andstringwill be used as the value, removing the provided separator character if necessary.- Parameters:
string- the stringcharacter- 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
Creates a key.- Parameters:
namespaced- the namespace sourcevalue- the value- Returns:
- the key
- Throws:
InvalidKeyException- if the namespace or value contains an invalid character- Since:
- 4.4.0
-
key
Creates a key.- Parameters:
namespace- the namespacevalue- the value- Returns:
- the key
- Throws:
InvalidKeyException- if the namespace or value contains an invalid character- Since:
- 4.0.0
-
comparator
- Returns:
- a comparator for keys
- Since:
- 4.10.0
-
parseable
-
parseableNamespace
Checks ifvalueis a valid namespace.- Parameters:
namespace- the string to check- Returns:
trueifvalueis a valid namespace,falseotherwise- Since:
- 4.12.0
-
checkNamespace
Checks ifvalueis a valid namespace.- Parameters:
namespace- the string to check- Returns:
OptionalInt.empty()ifvalueis a valid namespace, otherwise anOptionalIntcontaining the index of an invalid character- Since:
- 4.14.0
-
parseableValue
Checks ifvalueis a valid value.- Parameters:
value- the string to check- Returns:
trueifvalueis a valid value,falseotherwise- Since:
- 4.12.0
-
checkValue
Checks ifvalueis a valid value.- Parameters:
value- the string to check- Returns:
OptionalInt.empty()ifvalueis a valid value, otherwise anOptionalIntcontaining the index of an invalid character- Since:
- 4.14.0
-
allowedInNamespace
static boolean allowedInNamespace(char character) Checks ifvalueis a valid character in a namespace.- Parameters:
character- the character to check- Returns:
trueifvalueis a valid character in a namespace,falseotherwise- Since:
- 4.12.0
-
allowedInValue
static boolean allowedInValue(char character) Checks ifvalueis a valid character in a value.- Parameters:
character- the character to check- Returns:
trueifvalueis a valid character in a value,falseotherwise- Since:
- 4.12.0
-
namespace
Gets the namespace.- Specified by:
namespacein interfaceNamespaced- Returns:
- the namespace
- Since:
- 4.0.0
-
value
-
asString
String asString()Returns the string representation of this key.- Returns:
- the string representation
- Since:
- 4.0.0
-
asMinimalString
Returns the string representation of this key in minimal form.If the
namespace()of this key isMINECRAFT_NAMESPACE, only thevalue()will be returned.- Returns:
- the string representation
- Since:
- 4.15.0
-
compareTo
- Specified by:
compareToin interfaceComparable<Key>
-
key
-