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) * incrementEXPONENTIAL- Exponential scaling: base * multiplier^(level - 1)DIMINISHING- Diminishing returns: max * (level / (level + factor))CONSTANT- Constant value at all levelsSTEPPED- Stepped values with interpolationDECAYING- 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 Summary
Modifier and TypeMethodDescription@NotNull LevelScalingGets a scaling algorithm by name with the specified parameters.@NotNull Optional<ScalingAlgorithmMetadata> getMetadata(@NotNull String name) Gets the metadata for a registered algorithm.Gets all registered algorithm names.booleanhasAlgorithm(@NotNull String name) Checks if an algorithm with the specified name is registered.voidregister(@NotNull String name, @NotNull ScalingAlgorithm algorithm) Registers a custom scaling algorithm with a unique name.booleanunregister(@NotNull String name) Unregisters a custom algorithm by name.
-
Method Details
-
register
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 nullIllegalStateException- if an algorithm with this name already exists- Since:
- 0.2.0
-
get
Gets a scaling algorithm by name with the specified parameters.The algorithm creates a
LevelScalinginstance 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
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
Gets all registered algorithm names.- Returns:
- an unmodifiable set of all algorithm names
- Since:
- 0.2.0
-
getMetadata
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
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
-