Updates Spigot, and fixes depreciated code
All checks were successful
EpicKnarvik97/Blacksmith/pipeline/head This commit looks good

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

View File

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

View File

@ -3,7 +3,9 @@ package net.knarcraft.blacksmith.util;
import net.knarcraft.blacksmith.config.SettingValueType;
import net.knarcraft.blacksmith.config.SmithPreset;
import net.knarcraft.blacksmith.config.SmithPresetFilter;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.Registry;
import org.bukkit.enchantments.Enchantment;
import org.jetbrains.annotations.NotNull;
@ -82,8 +84,13 @@ public final class TabCompleteValuesHelper {
* @return <p>A complete list of enchantments</p>
*/
private static @NotNull List<String> getAllEnchantments() {
Registry<Enchantment> enchantmentRegistry = Bukkit.getRegistry(Enchantment.class);
if (enchantmentRegistry == null) {
throw new RuntimeException("Unable to get the enchantment registry");
}
List<String> enchantments = new ArrayList<>();
for (Enchantment enchantment : Enchantment.values()) {
for (Enchantment enchantment : enchantmentRegistry) {
enchantments.add(enchantment.getKey().getKey());
}
return enchantments;