Interface ScalingAlgorithmRegistry

All Known Implementing Classes:
ScalingAlgorithmRegistryImpl

public interface ScalingAlgorithmRegistry
Registry for named scaling algorithms.

This registry allows developers to register and use named scaling algorithms that can be retrieved by name and instantiated with parameters. Built-in algorithms are pre-registered on startup.

Built-in Algorithms:

  • LINEAR - Linear scaling: base + (level - 1) * increment
  • EXPONENTIAL - Exponential scaling: base * multiplier^(level - 1)
  • DIMINISHING - Diminishing returns: max * (level / (level + factor))
  • CONSTANT - Constant value at all levels
  • STEPPED - Stepped values with interpolation
  • DECAYING - Exponential decay: max * (1 - decayFactor^level)

Usage Examples:


 // Using built-in algorithm
 EnchantmentDefinition def = EnchantmentDefinition.builder()
     .key(key)
     .displayName(name)
     .minLevel(1)
     .maxLevel(5)
     .scaling("LINEAR", 1.0, 0.5)  // base=1.0, increment=0.5
     .applicable(Material.DIAMOND_SWORD)
     .build();

 // Registering custom algorithm
 registry.register("CUSTOM", new ScalingAlgorithm() {
     public LevelScaling create(double... params) {
         return level -> params[0] * Math.log(level + params[1]);
     }
     public String getDescription() { return "Logarithmic scaling"; }
     public int getParameterCount() { return 2; }
     public String[] getParameterNames() { return new String[]{"coefficient", "offset"}; }
 });
 

Thread Safety: All registry operations are thread-safe.

Since:
0.2.0
See Also:
  • Method Details

    • register

      void register(@NotNull @NotNull String name, @NotNull @NotNull ScalingAlgorithm algorithm)
      Registers a custom scaling algorithm with a unique name.

      The algorithm name must be unique and non-empty. Attempting to register an algorithm with a name that already exists will throw an exception.

      Parameters:
      name - the unique algorithm name (must not be null or empty)
      algorithm - the algorithm implementation (must not be null)
      Throws:
      IllegalArgumentException - if name is null/empty or algorithm is null
      IllegalStateException - if an algorithm with this name already exists
      Since:
      0.2.0
    • get

      @NotNull @NotNull LevelScaling get(@NotNull @NotNull String name, double... params)
      Gets a scaling algorithm by name with the specified parameters.

      The algorithm creates a LevelScaling instance configured with the provided parameters. The parameters are validated to ensure they produce finite values.

      Parameters:
      name - the algorithm name (must not be null or empty)
      params - the algorithm-specific parameters
      Returns:
      a configured LevelScaling instance
      Throws:
      IllegalArgumentException - if algorithm not found or parameters invalid
      Since:
      0.2.0
    • hasAlgorithm

      boolean hasAlgorithm(@NotNull @NotNull String name)
      Checks if an algorithm with the specified name is registered.
      Parameters:
      name - the algorithm name to check (must not be null)
      Returns:
      true if the algorithm exists
      Since:
      0.2.0
    • getRegisteredNames

      @NotNull @NotNull Set<String> getRegisteredNames()
      Gets all registered algorithm names.
      Returns:
      an unmodifiable set of all algorithm names
      Since:
      0.2.0
    • getMetadata

      @NotNull @NotNull Optional<ScalingAlgorithmMetadata> getMetadata(@NotNull @NotNull String name)
      Gets the metadata for a registered algorithm.
      Parameters:
      name - the algorithm name (must not be null)
      Returns:
      the algorithm metadata if found, empty otherwise
      Since:
      0.2.0
    • unregister

      boolean unregister(@NotNull @NotNull String name)
      Unregisters a custom algorithm by name.

      Built-in algorithms cannot be unregistered. Attempting to unregister a built-in algorithm will return false.

      Parameters:
      name - the algorithm name to unregister (must not be null)
      Returns:
      true if the algorithm was unregistered, false if not found or built-in
      Since:
      0.2.0