From 7bb9ce4769fd5597691df2c96c6ba883ae34777f Mon Sep 17 00:00:00 2001 From: Jake Moore Date: Wed, 6 Dec 2023 02:35:28 -0800 Subject: [PATCH] 2.2.0.1 -Fixes incompatibility on 1.8 with NamespacedKey Took 3 minutes --- .../command/type/TypeEnchantment.java | 12 +++--------- .../kamicommon/util/nms/NMS_Methods.java | 17 +++++++++++++++++ .../kamicommon/util/nms/NMS_Methods_1_13.java | 7 +------ 3 files changed, 21 insertions(+), 15 deletions(-) create mode 100644 src/main/java/com/kamikazejam/kamicommon/util/nms/NMS_Methods.java diff --git a/src/main/java/com/kamikazejam/kamicommon/command/type/TypeEnchantment.java b/src/main/java/com/kamikazejam/kamicommon/command/type/TypeEnchantment.java index 9b1f340b..0b56abf0 100644 --- a/src/main/java/com/kamikazejam/kamicommon/command/type/TypeEnchantment.java +++ b/src/main/java/com/kamikazejam/kamicommon/command/type/TypeEnchantment.java @@ -5,7 +5,7 @@ import com.kamikazejam.kamicommon.util.collections.KamiList; import com.kamikazejam.kamicommon.util.collections.KamiMap; import com.kamikazejam.kamicommon.util.collections.KamiSet; -import com.kamikazejam.kamicommon.util.nms.NMS_Methods_1_13; +import com.kamikazejam.kamicommon.util.nms.NMS_Methods; import org.bukkit.ChatColor; import org.bukkit.enchantments.Enchantment; import org.jetbrains.annotations.NotNull; @@ -66,14 +66,8 @@ public class TypeEnchantment extends TypeAbstractChoice { "swift_sneak", new KamiList<>("Swift Sneak", "SWIFT_SNEAK", "SwiftSneak") ); - @SuppressWarnings("deprecation") public static @NotNull String enchantmentToKey(@NotNull Enchantment enchantment) { - // If after 1.13, we have access to namespaced keys - if (NmsManager.getFormattedNmsDouble() >= 1130) { - return NMS_Methods_1_13.getNamespaced(enchantment); - }else { - return "minecraft:" + enchantment.getName().toLowerCase(); - } + return NMS_Methods.getNamespaced(enchantment); } // -------------------------------------------- // @@ -116,7 +110,7 @@ public Set getNamesInner(Enchantment enchantment) { // If after 1.13, we have access to namespaced keys if (NmsManager.getFormattedNmsDouble() >= 1130) { - raws.add(NMS_Methods_1_13.getNamespaced(enchantment)); + raws.add(enchantmentToKey(enchantment)); } for (String raw : raws) { diff --git a/src/main/java/com/kamikazejam/kamicommon/util/nms/NMS_Methods.java b/src/main/java/com/kamikazejam/kamicommon/util/nms/NMS_Methods.java new file mode 100644 index 00000000..22fda488 --- /dev/null +++ b/src/main/java/com/kamikazejam/kamicommon/util/nms/NMS_Methods.java @@ -0,0 +1,17 @@ +package com.kamikazejam.kamicommon.util.nms; + +import com.kamikazejam.kamicommon.nms.NmsManager; +import org.bukkit.enchantments.Enchantment; + +@SuppressWarnings("unused") +public class NMS_Methods { + @SuppressWarnings("deprecation") + public static String getNamespaced(Enchantment enchantment) { + // If after 1.13, we have access to namespaced keys + if (NmsManager.getFormattedNmsDouble() >= 1130) { + return NMS_Methods_1_13.getNamespaced(enchantment); + }else { + return "minecraft:" + enchantment.getName().toLowerCase(); + } + } +} diff --git a/src/main/java/com/kamikazejam/kamicommon/util/nms/NMS_Methods_1_13.java b/src/main/java/com/kamikazejam/kamicommon/util/nms/NMS_Methods_1_13.java index e811ea2f..c2ec25fc 100644 --- a/src/main/java/com/kamikazejam/kamicommon/util/nms/NMS_Methods_1_13.java +++ b/src/main/java/com/kamikazejam/kamicommon/util/nms/NMS_Methods_1_13.java @@ -1,15 +1,10 @@ package com.kamikazejam.kamicommon.util.nms; -import org.bukkit.NamespacedKey; import org.bukkit.enchantments.Enchantment; @SuppressWarnings("unused") public class NMS_Methods_1_13 { - public static String getNamespaced(Enchantment enchantment) { + static String getNamespaced(Enchantment enchantment) { return enchantment.getKey().getKey(); } - - public static Enchantment getEnchantmentByKey(String key) { - return Enchantment.getByKey(NamespacedKey.minecraft(key)); - } }