File tree Expand file tree Collapse file tree
modules/library/src/main/java/top/mrxiaom/pluginbase/utils Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package top .mrxiaom .pluginbase .utils ;
22
33import org .bukkit .Keyed ;
4+ import org .bukkit .NamespacedKey ;
45import org .bukkit .Registry ;
6+ import org .jetbrains .annotations .NotNull ;
7+ import org .jetbrains .annotations .Nullable ;
58
69public class RegistryUtils {
710 @ SuppressWarnings ("unchecked" )
811 public static <T > T fromType (Class <T > type , String s ) {
912 Registry <?> registry = RegistryConverter .fromType (type );
1013 if (registry != null ) {
11- Keyed matched = registry . match (s );
14+ Keyed matched = match (registry , s );
1215 if (/*matched != null && */ type .isInstance (matched )) {
1316 return (T ) matched ;
1417 }
15- Keyed newerMatched = registry . match (s .replace ('_' , '.' ));
18+ Keyed newerMatched = match (registry , s .replace ('_' , '.' ));
1619 if (/*newerMatched != null && */ type .isInstance (matched )) {
1720 return (T ) newerMatched ;
1821 }
1922 }
2023 return null ;
2124 }
25+
26+ @ Nullable
27+ public static <T extends Keyed > T match (@ NotNull Registry <T > registry , @ NotNull String input ) {
28+ String filtered = input .toLowerCase ().replaceAll ("\\ s+" , "_" );
29+ NamespacedKey namespacedKey = NamespacedKey .fromString (filtered );
30+ return (namespacedKey != null ) ? registry .get (namespacedKey ) : null ;
31+ }
2232}
You can’t perform that action at this time.
0 commit comments