Class EnchantmentDefinitionBuilder
java.lang.Object
io.artificial.enchantments.internal.EnchantmentDefinitionBuilder
- All Implemented Interfaces:
EnchantmentDefinition.Builder
public final class EnchantmentDefinitionBuilder
extends Object
implements EnchantmentDefinition.Builder
Internal implementation of the EnchantmentDefinition.Builder interface.
This builder provides comprehensive validation for enchantment definitions including level bounds, material sets, conflicts, and cross-property validation. It creates immutable EnchantmentDefinitionImpl instances.
- Since:
- 0.2.0
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new enchantment definition builder. -
Method Summary
Modifier and TypeMethodDescriptionapplicable(@NotNull Set<org.bukkit.Material> materials) Sets applicable materials from a set.applicable(@NotNull org.bukkit.Material... materials) Sets applicable materials from a varargs list.@NotNull EnchantmentDefinitionbuild()Builds and returns the enchantment definition.conflictsWith(@NotNull org.bukkit.NamespacedKey key) Adds a conflicting enchantment key.conflictsWith(@NotNull org.bukkit.NamespacedKey... keys) Adds multiple conflicting enchantment keys.curse()Marks this enchantment as a curse (convenience method).curse(boolean curse) Sets whether this is a curse enchantment.description(@Nullable net.kyori.adventure.text.Component description) Sets the optional description for lore display.discoverable(boolean discoverable) Sets whether this enchantment appears in loot tables.displayName(@NotNull net.kyori.adventure.text.Component name) Sets the display name shown to players.effectHandler(@Nullable EnchantmentEffectHandler handler) Sets the effect handler for this enchantment.Gets all validation errors for the current builder state.key(@NotNull org.bukkit.NamespacedKey key) Sets the unique namespaced key for this enchantment.maxLevel(int maxLevel) Sets the maximum valid level.minLevel(int minLevel) Sets the minimum valid level.rarity(EnchantmentDefinition.Rarity rarity) Sets the rarity tier.scaling(@NotNull LevelScaling scaling) Sets the scaling formula using aLevelScalinginstance.Sets the scaling formula using a registered algorithm by name.Sets a custom scaling formula using a lambda.tradeable(boolean tradeable) Sets whether this enchantment is tradeable with villagers.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.artificial.enchantments.api.EnchantmentDefinition.Builder
isValid, validate
-
Constructor Details
-
EnchantmentDefinitionBuilder
public EnchantmentDefinitionBuilder()Creates a new enchantment definition builder.- Since:
- 0.2.0
-
-
Method Details
-
key
Description copied from interface:EnchantmentDefinition.BuilderSets the unique namespaced key for this enchantment.- Specified by:
keyin interfaceEnchantmentDefinition.Builder- Parameters:
key- the enchantment key (must not be null)- Returns:
- this builder for chaining
-
displayName
@NotNull public EnchantmentDefinition.Builder displayName(@NotNull @NotNull net.kyori.adventure.text.Component name) Description copied from interface:EnchantmentDefinition.BuilderSets the display name shown to players.- Specified by:
displayNamein interfaceEnchantmentDefinition.Builder- Parameters:
name- the display name (must not be null)- Returns:
- this builder for chaining
-
description
@NotNull public EnchantmentDefinition.Builder description(@Nullable @Nullable net.kyori.adventure.text.Component description) Description copied from interface:EnchantmentDefinition.BuilderSets the optional description for lore display.- Specified by:
descriptionin interfaceEnchantmentDefinition.Builder- Parameters:
description- the description, or null for none- Returns:
- this builder for chaining
-
minLevel
Description copied from interface:EnchantmentDefinition.BuilderSets the minimum valid level.- Specified by:
minLevelin interfaceEnchantmentDefinition.Builder- Parameters:
minLevel- the minimum level (must be >= 1)- Returns:
- this builder for chaining
-
maxLevel
Description copied from interface:EnchantmentDefinition.BuilderSets the maximum valid level.- Specified by:
maxLevelin interfaceEnchantmentDefinition.Builder- Parameters:
maxLevel- the maximum level (must be >= minLevel)- Returns:
- this builder for chaining
-
scaling
Description copied from interface:EnchantmentDefinition.BuilderSets the scaling formula using aLevelScalinginstance.- Specified by:
scalingin interfaceEnchantmentDefinition.Builder- Parameters:
scaling- the scaling formula (must not be null)- Returns:
- this builder for chaining
-
scaling
@NotNull public EnchantmentDefinition.Builder scaling(@NotNull @NotNull Function<Integer, Double> formula) Description copied from interface:EnchantmentDefinition.BuilderSets a custom scaling formula using a lambda.- Specified by:
scalingin interfaceEnchantmentDefinition.Builder- Parameters:
formula- the formula function (must not be null)- Returns:
- this builder for chaining
-
scaling
@NotNull public EnchantmentDefinition.Builder scaling(@NotNull @NotNull String algorithmName, double... params) Description copied from interface:EnchantmentDefinition.BuilderSets 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- Specified by:
scalingin interfaceEnchantmentDefinition.Builder- Parameters:
algorithmName- the algorithm name (must not be null, case-insensitive)params- the algorithm-specific parameters- Returns:
- this builder for chaining
- See Also:
-
applicable
@NotNull public EnchantmentDefinition.Builder applicable(@NotNull @NotNull org.bukkit.Material... materials) Description copied from interface:EnchantmentDefinition.BuilderSets applicable materials from a varargs list.- Specified by:
applicablein interfaceEnchantmentDefinition.Builder- Parameters:
materials- the materials (must not be null)- Returns:
- this builder for chaining
-
applicable
@NotNull public EnchantmentDefinition.Builder applicable(@NotNull @NotNull Set<org.bukkit.Material> materials) Description copied from interface:EnchantmentDefinition.BuilderSets applicable materials from a set.- Specified by:
applicablein interfaceEnchantmentDefinition.Builder- Parameters:
materials- the material set (must not be null)- Returns:
- this builder for chaining
-
curse
Description copied from interface:EnchantmentDefinition.BuilderSets whether this is a curse enchantment.- Specified by:
cursein interfaceEnchantmentDefinition.Builder- Parameters:
curse- true for curse enchantments- Returns:
- this builder for chaining
-
curse
Description copied from interface:EnchantmentDefinition.BuilderMarks this enchantment as a curse (convenience method).- Specified by:
cursein interfaceEnchantmentDefinition.Builder- Returns:
- this builder for chaining
-
tradeable
Description copied from interface:EnchantmentDefinition.BuilderSets whether this enchantment is tradeable with villagers.- Specified by:
tradeablein interfaceEnchantmentDefinition.Builder- Parameters:
tradeable- true if tradeable- Returns:
- this builder for chaining
-
discoverable
Description copied from interface:EnchantmentDefinition.BuilderSets whether this enchantment appears in loot tables.- Specified by:
discoverablein interfaceEnchantmentDefinition.Builder- Parameters:
discoverable- true if discoverable- Returns:
- this builder for chaining
-
rarity
Description copied from interface:EnchantmentDefinition.BuilderSets the rarity tier.- Specified by:
rarityin interfaceEnchantmentDefinition.Builder- Parameters:
rarity- the rarity (must not be null)- Returns:
- this builder for chaining
-
effectHandler
@NotNull public EnchantmentDefinition.Builder effectHandler(@Nullable @Nullable EnchantmentEffectHandler handler) Description copied from interface:EnchantmentDefinition.BuilderSets the effect handler for this enchantment.- Specified by:
effectHandlerin interfaceEnchantmentDefinition.Builder- Parameters:
handler- the effect handler, or null for no effects- Returns:
- this builder for chaining
-
conflictsWith
@NotNull public EnchantmentDefinition.Builder conflictsWith(@NotNull @NotNull org.bukkit.NamespacedKey key) Description copied from interface:EnchantmentDefinition.BuilderAdds a conflicting enchantment key.- Specified by:
conflictsWithin interfaceEnchantmentDefinition.Builder- Parameters:
key- the conflicting enchantment key (must not be null)- Returns:
- this builder for chaining
-
conflictsWith
@NotNull public EnchantmentDefinition.Builder conflictsWith(@NotNull @NotNull org.bukkit.NamespacedKey... keys) Description copied from interface:EnchantmentDefinition.BuilderAdds multiple conflicting enchantment keys.- Specified by:
conflictsWithin interfaceEnchantmentDefinition.Builder- Parameters:
keys- the conflicting keys (must not be null)- Returns:
- this builder for chaining
-
getValidationErrors
Description copied from interface:EnchantmentDefinition.BuilderGets 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.
- Specified by:
getValidationErrorsin interfaceEnchantmentDefinition.Builder- Returns:
- unmodifiable list of validation error and warning messages (empty if valid)
-
build
Description copied from interface:EnchantmentDefinition.BuilderBuilds and returns the enchantment definition.- Specified by:
buildin interfaceEnchantmentDefinition.Builder- Returns:
- the completed definition
-