package net.knarcraft.blacksmith.util; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.NamespacedKey; import org.bukkit.Registry; import org.bukkit.enchantments.Enchantment; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; /** * A helper class for parsing input into proper object types */ public final class InputParsingHelper { private InputParsingHelper() { } /** * Gets whether the input is an "empty" value treated as null * * @param input
The input to check
* @returnTrue if the value is empty
*/ public static boolean isEmpty(@Nullable String input) { return input == null || input.equalsIgnoreCase("null") || input.equals("\"\"") || input.isBlank() || input.equals("-1"); } /** * Tries to find the material matching the given input string * * @param inputThe string to match to a material
* @returnThe material matching the string, or null if not found
*/ public static @Nullable Material matchMaterial(@NotNull String input) { return Material.matchMaterial(input.replace("-", "_")); } /** * Tries to find the enchantment matching the given input string * * @param inputThe string to match to an enchantment
* @returnThe enchantment matching the string, or null if not found
*/ public static @Nullable Enchantment matchEnchantment(@NotNull String input) { try { RegistryThe input to RegExIfy
* @returnThe converted input
*/ public static @NotNull String regExIfy(@NotNull String input) { return input.replace("*", ".*").toUpperCase().replace("-", "_"); } }