Package org.skriptlang.skript.lang.entry
Class EntryValidator.EntryValidatorBuilder
java.lang.Object
org.skriptlang.skript.lang.entry.EntryValidator.EntryValidatorBuilder
- Enclosing class:
EntryValidator
A utility builder for creating an entry validator that can be used to parse and validate a
SectionNode
.- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
The default separator used for allKeyValueEntryData
. -
Method Summary
Modifier and TypeMethodDescriptionAdds a newKeyValueEntryData
to this validator that returns the raw, unhandled String value.addEntryData
(EntryData<?> entryData) A method to add customEntryData
to a validator.addSection
(String key, boolean optional) Adds a new, potentially optionalSectionEntryData
to this validator.build()
entrySeparator
(String separator) Updates the separator to be used when creating KeyValue entries.missingRequiredEntryMessage
(Function<String, String> missingRequiredEntryMessage) A function to be applied when a required Node is missing during validation.unexpectedEntryMessage
(Function<String, String> unexpectedEntryMessage) A function to be applied when an unexpected Node is encountered during validation.unexpectedNodeTester
(Predicate<Node> unexpectedNodeTester) A predicate to be supplied for checking whether a Node should be allowed even as an entry not declared in the entry data map.
-
Field Details
-
DEFAULT_ENTRY_SEPARATOR
The default separator used for allKeyValueEntryData
.- See Also:
-
-
Method Details
-
entrySeparator
Updates the separator to be used when creating KeyValue entries. Please note that this will not update the separator for already registered KeyValue entries.- Parameters:
separator
- The new separator for KeyValue entries.- Returns:
- The builder instance.
-
unexpectedNodeTester
public EntryValidator.EntryValidatorBuilder unexpectedNodeTester(Predicate<Node> unexpectedNodeTester) A predicate to be supplied for checking whether a Node should be allowed even as an entry not declared in the entry data map. The default behavior is that the predicate returns true for every Node tested.- Parameters:
unexpectedNodeTester
- The predicate to use.- Returns:
- The builder instance.
-
unexpectedEntryMessage
public EntryValidator.EntryValidatorBuilder unexpectedEntryMessage(Function<String, String> unexpectedEntryMessage) A function to be applied when an unexpected Node is encountered during validation. A String representing the user input (the Node's key) goes in, and an error message to output comes out.- Parameters:
unexpectedEntryMessage
- The function to use.- Returns:
- The builder instance.
-
missingRequiredEntryMessage
public EntryValidator.EntryValidatorBuilder missingRequiredEntryMessage(Function<String, String> missingRequiredEntryMessage) A function to be applied when a required Node is missing during validation. A String representing the key of the missing entry goes in, and an error message to output comes out.- Parameters:
missingRequiredEntryMessage
- The function to use.- Returns:
- The builder instance.
-
addEntry
public EntryValidator.EntryValidatorBuilder addEntry(String key, @Nullable @Nullable String defaultValue, boolean optional) Adds a newKeyValueEntryData
to this validator that returns the raw, unhandled String value. The added entry is optional and will use the provided default value as a backup.- Parameters:
key
- The key of the entry.defaultValue
- The default value of this entry to use if the user does not include this entry.- Returns:
- The builder instance.
-
addSection
Adds a new, potentially optionalSectionEntryData
to this validator.- Parameters:
key
- The key of the section entry.optional
- Whether this section entry should be optional.- Returns:
- The builder instance.
-
addEntryData
A method to add customEntryData
to a validator. Custom entry data should be preferred when the default methods included in this builder are not expansive enough. Please note that for customKeyValueEntryData
implementations, the default entry separator value of this builder will not be used. Instead,DEFAULT_ENTRY_SEPARATOR
will be used.- Parameters:
entryData
- The custom entry data to include in this validator.- Returns:
- The builder instance.
-
build
- Returns:
- The final, built entry validator.
-