Skip to content

Commit

Permalink
update(getMaterial): Adding a normalisation for classic namespace. (#…
Browse files Browse the repository at this point in the history
…2851)

Co-authored-by: NebraskyTheWolf <[email protected]>
  • Loading branch information
NebraskyTheWolf and NebraskyTheWolf committed Dec 24, 2023
1 parent 4e7ae91 commit ba88df4
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/main/java/org/bukkit/Material.java
Original file line number Diff line number Diff line change
Expand Up @@ -4605,7 +4605,23 @@ public static Material getMaterial(@NotNull String name, boolean legacyName) {
return Bukkit.getUnsafe().fromLegacy(match);
}

return BY_NAME.get(name);
return BY_NAME.get(normalize(name));
}

/**
* Attempts to normalise the input namespace 'modid:example_material'
* To the MohistMC format 'MODID_EXAMPLE_MATERIAL'
*
* @param namespace 'modid:example_material'
* @return normalized namespace
*/
public static String normalize(String namespace) {
String normalized = namespace;

if (namespace.indexOf(':') != -1 && !namespace.startsWith("minecraft"))
normalized = normalized.replace(':', '_').toUpperCase();

return normalized;
}

/**
Expand Down

0 comments on commit ba88df4

Please sign in to comment.