Skip to content

Commit

Permalink
2.2.0.1
Browse files Browse the repository at this point in the history
-Fixes incompatibility on 1.8 with NamespacedKey

Took 3 minutes
  • Loading branch information
Jake-Moore committed Dec 6, 2023
1 parent 32c8a0b commit 7bb9ce4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -66,14 +66,8 @@ public class TypeEnchantment extends TypeAbstractChoice<Enchantment> {
"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);
}

// -------------------------------------------- //
Expand Down Expand Up @@ -116,7 +110,7 @@ public Set<String> 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) {
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/com/kamikazejam/kamicommon/util/nms/NMS_Methods.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
Original file line number Diff line number Diff line change
@@ -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));
}
}

0 comments on commit 7bb9ce4

Please sign in to comment.