Make CompatibleMaterial#getMaterial(String) with null and empty values

XMaterial throws an Exception if provided with `null` or `""`.
We make sure that an empty Optional is returned instead. Mainly for backwards compatibility reasons.
This commit is contained in:
Christian Koop 2023-08-16 17:54:37 +02:00
parent ebd83688d3
commit 8c22f5d141
No known key found for this signature in database
GPG Key ID: 89A8181384E010A3

View File

@ -15,10 +15,14 @@ import java.util.Optional;
public class CompatibleMaterial {
public static Optional<XMaterial> getMaterial(@NotNull Material material) {
return XMaterial.matchXMaterial(material.name());
return getMaterial(material.name());
}
public static Optional<XMaterial> getMaterial(String name) {
if (name == null || name.isEmpty()) {
return Optional.empty();
}
public static Optional<XMaterial> getMaterial(@NotNull String name) {
return XMaterial.matchXMaterial(name);
}