Updates Spigot, and fixes depreciated code

This commit is contained in:
2024-05-04 02:46:46 +02:00
parent 44f8bb36b0
commit 7e5525bd00
13 changed files with 38 additions and 338 deletions

@ -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