Added Registry.tryFitPattern
This commit is contained in:
@@ -108,4 +108,18 @@ public class Registry<T extends Registrable> {
|
||||
public Set<T> values() {
|
||||
return Set.copyOf(registry.values());
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to fit a string to the ID pattern.
|
||||
*
|
||||
* @param string The string.
|
||||
* @return The string in lowercase, but with all spaces, dots, and dashes replaced with underscores.
|
||||
*/
|
||||
@NotNull
|
||||
public static String tryFitPattern(@NotNull final String string) {
|
||||
return string.replace(" ", "_")
|
||||
.replace(".", "_")
|
||||
.replace("-", "_")
|
||||
.toLowerCase();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
@file:JvmName("RegistryExtensions")
|
||||
|
||||
package com.willfp.eco.core.registry
|
||||
|
||||
/** @see Registry.tryFitPattern */
|
||||
fun String.tryFitRegistryPattern(): String =
|
||||
Registry.tryFitPattern(this)
|
||||
Reference in New Issue
Block a user