@ -1,7 +1,9 @@
|
||||
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;
|
||||
@ -44,7 +46,11 @@ public final class InputParsingHelper {
|
||||
*/
|
||||
public static @Nullable Enchantment matchEnchantment(@NotNull String input) {
|
||||
try {
|
||||
return Enchantment.getByKey(NamespacedKey.minecraft(
|
||||
Registry<Enchantment> enchantments = Bukkit.getRegistry(Enchantment.class);
|
||||
if (enchantments == null) {
|
||||
throw new RuntimeException("Unable to get enchantment registry");
|
||||
}
|
||||
return enchantments.get(NamespacedKey.minecraft(
|
||||
input.replace("-", "_").replace(" ", "_").toLowerCase()));
|
||||
} catch (IllegalArgumentException exception) {
|
||||
//Invalid characters, such as : will normally throw an illegal argument exception
|
||||
|
Reference in New Issue
Block a user