Adds method for parsing a material without tag support
All checks were successful
EpicKnarvik97/KnarLib/pipeline/head This commit looks good
KnarCraft/KnarLib/pipeline/head This commit looks good

This commit is contained in:
Kristian Knarvik 2023-07-10 13:15:23 +02:00
parent 223c70b28e
commit 5c3c3045eb

View File

@ -6,6 +6,7 @@ import org.bukkit.Material;
import org.bukkit.NamespacedKey; import org.bukkit.NamespacedKey;
import org.bukkit.Tag; import org.bukkit.Tag;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
@ -62,14 +63,31 @@ public final class MaterialHelper {
} }
// Try to parse a material name // Try to parse a material name
Material matched = Material.matchMaterial(materialString); Material matched = loadMaterialString(materialString, logger);
if (matched != null) { if (matched != null) {
parsedMaterials.add(matched); parsedMaterials.add(matched);
}
return parsedMaterials;
}
/**
* Parses a string representing a material
*
* @param materialString <p>The material string to parse</p>
* @param logger <p>The logger to use for logging parsing errors</p>
* @return <p>The materials defined by the material string, or an empty list if none were found</p>
*/
public static @Nullable Material loadMaterialString(@NotNull String materialString, @NotNull Logger logger) {
// Try to parse a material name
Material matched = Material.matchMaterial(materialString.replace("-", "_"));
if (matched != null) {
return matched;
} else { } else {
logger.log(Level.WARNING, StringFormatter.replacePlaceholder("Unable to parse material: {material}", logger.log(Level.WARNING, StringFormatter.replacePlaceholder("Unable to parse material: {material}",
"{material}", materialString)); "{material}", materialString));
return null;
} }
return parsedMaterials;
} }
/** /**