Interface EnchantmentDefinition.Builder
- All Known Implementing Classes:
EnchantmentDefinitionBuilder
- Enclosing interface:
EnchantmentDefinition
All properties must be set before calling build(), except
for optional properties which have sensible defaults.
Required Properties:
key(NamespacedKey)- the unique identifierdisplayName(Component)- the display nameminLevel(int)andmaxLevel(int)- level boundsscaling(LevelScaling)- the scaling formulaapplicable(Material...)- valid materials
- Since:
- 0.1.0
-
Method Summary
Modifier and TypeMethodDescription@NotNull EnchantmentDefinition.Builderapplicable(@NotNull Set<org.bukkit.Material> materials) Sets applicable materials from a set.@NotNull EnchantmentDefinition.Builderapplicable(@NotNull org.bukkit.Material... materials) Sets applicable materials from a varargs list.@NotNull EnchantmentDefinitionbuild()Builds and returns the enchantment definition.@NotNull EnchantmentDefinition.BuilderconflictsWith(@NotNull org.bukkit.NamespacedKey key) Adds a conflicting enchantment key.@NotNull EnchantmentDefinition.BuilderconflictsWith(@NotNull org.bukkit.NamespacedKey... keys) Adds multiple conflicting enchantment keys.@NotNull EnchantmentDefinition.Buildercurse()Marks this enchantment as a curse (convenience method).@NotNull EnchantmentDefinition.Buildercurse(boolean curse) Sets whether this is a curse enchantment.@NotNull EnchantmentDefinition.Builderdescription(@Nullable net.kyori.adventure.text.Component description) Sets the optional description for lore display.@NotNull EnchantmentDefinition.Builderdiscoverable(boolean discoverable) Sets whether this enchantment appears in loot tables.@NotNull EnchantmentDefinition.BuilderdisplayName(@NotNull net.kyori.adventure.text.Component name) Sets the display name shown to players.@NotNull EnchantmentDefinition.BuildereffectHandler(@Nullable EnchantmentEffectHandler handler) Sets the effect handler for this enchantment.Gets all validation errors for the current builder state.default booleanisValid()Checks if the current builder state is valid.@NotNull EnchantmentDefinition.Builderkey(@NotNull org.bukkit.NamespacedKey key) Sets the unique namespaced key for this enchantment.@NotNull EnchantmentDefinition.BuildermaxLevel(int maxLevel) Sets the maximum valid level.@NotNull EnchantmentDefinition.BuilderminLevel(int minLevel) Sets the minimum valid level.@NotNull EnchantmentDefinition.Builderrarity(@NotNull EnchantmentDefinition.Rarity rarity) Sets the rarity tier.@NotNull EnchantmentDefinition.Builderscaling(@NotNull LevelScaling scaling) Sets the scaling formula using aLevelScalinginstance.default @NotNull EnchantmentDefinition.BuilderSets the scaling formula using a registered algorithm by name.@NotNull EnchantmentDefinition.BuilderSets a custom scaling formula using a lambda.@NotNull EnchantmentDefinition.Buildertradeable(boolean tradeable) Sets whether this enchantment is tradeable with villagers.default voidvalidate()Validates the current builder state without building.
-
Method Details
-
key
Sets the unique namespaced key for this enchantment.- Parameters:
key- the enchantment key (must not be null)- Returns:
- this builder for chaining
- Since:
- 0.1.0
-
displayName
@NotNull @NotNull EnchantmentDefinition.Builder displayName(@NotNull @NotNull net.kyori.adventure.text.Component name) Sets the display name shown to players.- Parameters:
name- the display name (must not be null)- Returns:
- this builder for chaining
- Since:
- 0.1.0
-
description
@NotNull @NotNull EnchantmentDefinition.Builder description(@Nullable @Nullable net.kyori.adventure.text.Component description) Sets the optional description for lore display.- Parameters:
description- the description, or null for none- Returns:
- this builder for chaining
- Since:
- 0.1.0
-
minLevel
Sets the minimum valid level.- Parameters:
minLevel- the minimum level (must be >= 1)- Returns:
- this builder for chaining
- Since:
- 0.1.0
-
maxLevel
Sets the maximum valid level.- Parameters:
maxLevel- the maximum level (must be >= minLevel)- Returns:
- this builder for chaining
- Since:
- 0.1.0
-
scaling
Sets the scaling formula using aLevelScalinginstance.- Parameters:
scaling- the scaling formula (must not be null)- Returns:
- this builder for chaining
- Since:
- 0.1.0
-
scaling
@NotNull @NotNull EnchantmentDefinition.Builder scaling(@NotNull @NotNull Function<Integer, Double> formula) Sets a custom scaling formula using a lambda.- Parameters:
formula- the formula function (must not be null)- Returns:
- this builder for chaining
- Since:
- 0.1.0
-
scaling
@NotNull default @NotNull EnchantmentDefinition.Builder scaling(@NotNull @NotNull String algorithmName, double... params) Sets the scaling formula using a registered algorithm by name.Uses the
ScalingAlgorithmRegistryto look up the algorithm and create a configuredLevelScalinginstance.Example:
.scaling("LINEAR", 1.0, 0.5) // base=1.0, increment=0.5 .scaling("EXPONENTIAL", 1.0, 1.2) // base=1.0, multiplier=1.2 .scaling("CONSTANT", 5.0) // value=5.0 at all levels- Parameters:
algorithmName- the algorithm name (must not be null, case-insensitive)params- the algorithm-specific parameters- Returns:
- this builder for chaining
- Throws:
IllegalArgumentException- if algorithm not found or parameters invalid- Since:
- 0.2.0
- See Also:
-
applicable
@NotNull @NotNull EnchantmentDefinition.Builder applicable(@NotNull @NotNull org.bukkit.Material... materials) Sets applicable materials from a varargs list.- Parameters:
materials- the materials (must not be null)- Returns:
- this builder for chaining
- Since:
- 0.1.0
-
applicable
@NotNull @NotNull EnchantmentDefinition.Builder applicable(@NotNull @NotNull Set<org.bukkit.Material> materials) Sets applicable materials from a set.- Parameters:
materials- the material set (must not be null)- Returns:
- this builder for chaining
- Since:
- 0.1.0
-
curse
Sets whether this is a curse enchantment.- Parameters:
curse- true for curse enchantments- Returns:
- this builder for chaining
- Since:
- 0.1.0
-
curse
Marks this enchantment as a curse (convenience method).- Returns:
- this builder for chaining
- Since:
- 0.1.0
-
tradeable
Sets whether this enchantment is tradeable with villagers.- Parameters:
tradeable- true if tradeable- Returns:
- this builder for chaining
- Since:
- 0.1.0
-
discoverable
Sets whether this enchantment appears in loot tables.- Parameters:
discoverable- true if discoverable- Returns:
- this builder for chaining
- Since:
- 0.1.0
-
rarity
@NotNull @NotNull EnchantmentDefinition.Builder rarity(@NotNull @NotNull EnchantmentDefinition.Rarity rarity) Sets the rarity tier.- Parameters:
rarity- the rarity (must not be null)- Returns:
- this builder for chaining
- Since:
- 0.1.0
-
effectHandler
@NotNull @NotNull EnchantmentDefinition.Builder effectHandler(@Nullable @Nullable EnchantmentEffectHandler handler) Sets the effect handler for this enchantment.- Parameters:
handler- the effect handler, or null for no effects- Returns:
- this builder for chaining
- Since:
- 0.1.0
-
conflictsWith
@NotNull @NotNull EnchantmentDefinition.Builder conflictsWith(@NotNull @NotNull org.bukkit.NamespacedKey key) Adds a conflicting enchantment key.- Parameters:
key- the conflicting enchantment key (must not be null)- Returns:
- this builder for chaining
- Since:
- 0.1.0
-
conflictsWith
@NotNull @NotNull EnchantmentDefinition.Builder conflictsWith(@NotNull @NotNull org.bukkit.NamespacedKey... keys) Adds multiple conflicting enchantment keys.- Parameters:
keys- the conflicting keys (must not be null)- Returns:
- this builder for chaining
- Since:
- 0.1.0
-
build
Builds and returns the enchantment definition.- Returns:
- the completed definition
- Throws:
IllegalStateException- if required properties are not set- Since:
- 0.1.0
-
validate
default void validate()Validates the current builder state without building.This method performs the same validation as
build()but provides detailed error information without actually creating the enchantment definition. Use this for pre-build validation when you need to check configuration before attempting to build.Default Behavior: The default implementation calls
getValidationErrors()and throws an exception if any non-warning errors exist. Override in implementations for custom validation.- Throws:
IllegalStateException- if validation fails, with detailed error message- Since:
- 0.2.0
-
isValid
default boolean isValid()Checks if the current builder state is valid.This is a non-throwing alternative to
validate(). Returns true only if all validation rules pass and the enchantment can be built successfully.Default Behavior: Returns true if
getValidationErrors()returns no non-warning errors.- Returns:
- true if valid, false if validation errors exist
- Since:
- 0.2.0
-
getValidationErrors
Gets all validation errors for the current builder state.Returns a list of detailed error messages describing what validation rules are currently violated. An empty list indicates the builder is in a valid state.
Validation checks include:
- Required fields: key, displayName, scaling, applicable materials
- Level bounds: minLevel >= 1, maxLevel >= minLevel
- Material set: non-empty set of applicable materials
- Conflicts: no self-conflicts (enchantment cannot conflict with itself)
- Cross-property: warnings for curse + tradeable combinations
Default Behavior: Returns an empty list. Override in implementations to provide actual validation logic.
- Returns:
- unmodifiable list of validation error and warning messages (empty if valid)
- Since:
- 0.2.0
-