Files
Blacksmith/src/main/java/net/knarcraft/blacksmith/util/InputParsingHelper.java
EpicKnarvik97 cc7d66f270 Fixes several bugs and problems
Fixes getting the name of enchantments
Fixes inconsistencies in material and enchantment name-checking
Allows using "null" or "-1" to unset per-material or per-enchantment configuration options
Fixes a bug where basePrice was set to a material name instead of the price for the material being displayed
Adds missing tab-completion for material/enchantment costs
Prevents inconsistencies in deciding if a value is null
2022-10-24 13:57:58 +02:00

48 lines
1.4 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() {
}
/**
* Gets whether the input is an "empty" value treated as null
*
* @param input <p>The input to check</p>
* @return <p>True if the value is empty</p>
*/
public static boolean isEmpty(String input) {
return input == null || input.equalsIgnoreCase("null") || input.equals("\"\"") ||
input.trim().isEmpty() || input.equals("-1");
}
/**
* 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("-", "_")));
}
}