Allows specifying the material tag prefix
All checks were successful
EpicKnarvik97/KnarLib/pipeline/head This commit looks good
All checks were successful
EpicKnarvik97/KnarLib/pipeline/head This commit looks good
This commit is contained in:
parent
94d74e7794
commit
46f85d37ab
@ -29,16 +29,18 @@ public final class MaterialHelper {
|
||||
* Loads the materials specified in the given list
|
||||
*
|
||||
* @param materials <p>The list of material strings to load</p>
|
||||
* @param tagPrefix <p>The prefix differentiating a tag from a material</p>
|
||||
* @param logger <p>The logger to use for logging parsing errors</p>
|
||||
*/
|
||||
public static @NotNull Set<Material> loadMaterialList(@NotNull List<?> materials, @NotNull Logger logger) {
|
||||
public static @NotNull Set<Material> loadMaterialList(@NotNull List<?> materials, @NotNull String tagPrefix,
|
||||
@NotNull Logger logger) {
|
||||
Set<Material> parsedMaterials = new HashSet<>();
|
||||
for (Object value : materials) {
|
||||
if (!(value instanceof String string)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
parsedMaterials.addAll(loadMaterialString(string, logger));
|
||||
parsedMaterials.addAll(loadMaterialString(string, tagPrefix, logger));
|
||||
}
|
||||
return parsedMaterials;
|
||||
}
|
||||
@ -47,13 +49,15 @@ public final class MaterialHelper {
|
||||
* Parses a string representing a material or a material tag
|
||||
*
|
||||
* @param materialString <p>The material string to parse</p>
|
||||
* @param tagPrefix <p>The prefix differentiating a tag from a material</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 @NotNull Set<Material> loadMaterialString(@NotNull String materialString, @NotNull Logger logger) {
|
||||
public static @NotNull Set<Material> loadMaterialString(@NotNull String materialString, @NotNull String tagPrefix,
|
||||
@NotNull Logger logger) {
|
||||
Set<Material> parsedMaterials = new HashSet<>();
|
||||
// Try to parse a material tag first
|
||||
if (parseMaterialTag(parsedMaterials, materialString, logger)) {
|
||||
if (parseMaterialTag(parsedMaterials, materialString, tagPrefix, logger)) {
|
||||
return parsedMaterials;
|
||||
}
|
||||
|
||||
@ -73,12 +77,13 @@ public final class MaterialHelper {
|
||||
*
|
||||
* @param targetSet <p>The set all parsed materials should be added to</p>
|
||||
* @param materialName <p>The material name that might be a material tag</p>
|
||||
* @param tagPrefix <p>The prefix differentiating a tag from a material</p>
|
||||
* @param logger <p>The logger to use for logging parsing errors</p>
|
||||
* @return <p>True if a tag was found</p>
|
||||
*/
|
||||
private static boolean parseMaterialTag(@NotNull Set<Material> targetSet, @NotNull String materialName,
|
||||
@NotNull Logger logger) {
|
||||
Pattern pattern = Pattern.compile("^\\+([a-zA-Z_]+)");
|
||||
@NotNull String tagPrefix, @NotNull Logger logger) {
|
||||
Pattern pattern = Pattern.compile("^" + Pattern.quote(tagPrefix) + "([a-zA-Z_]+)");
|
||||
Matcher matcher = pattern.matcher(materialName);
|
||||
if (matcher.find()) {
|
||||
// The material is a material tag
|
||||
|
Loading…
Reference in New Issue
Block a user