Blacksmith/src/main/java/net/knarcraft/blacksmith/util/InputParsingHelper.java

37 lines
1.0 KiB
Java

package net.knarcraft.blacksmith.util;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.enchantments.Enchantment;
/**
* A helper class for parsing input into proper object types
*/
public final class InputParsingHelper {
private InputParsingHelper() {
}
/**
* Tries to find the material matching the given input string
*
* @param input <p>The string to match to a material</p>
* @return <p>The material matching the string, or null if not found</p>
*/
public static Material matchMaterial(String input) {
return Material.matchMaterial(input.replace("-", "_"));
}
/**
* Tries to find the enchantment matching the given input string
*
* @param input <p>The string to match to an enchantment</p>
* @return <p>The enchantment matching the string, or null if not found</p>
*/
public static Enchantment matchEnchantment(String input) {
return Enchantment.getByKey(NamespacedKey.minecraft(input.replace("-", "_")));
}
}