Added Registry.tryFitPattern

This commit is contained in:
Auxilor
2023-03-19 22:00:42 +00:00
parent dc10648c25
commit 1e64815e47
2 changed files with 21 additions and 0 deletions

View File

@@ -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();
}
}

View File

@@ -0,0 +1,7 @@
@file:JvmName("RegistryExtensions")
package com.willfp.eco.core.registry
/** @see Registry.tryFitPattern */
fun String.tryFitRegistryPattern(): String =
Registry.tryFitPattern(this)