mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-02-11 20:00:46 +00:00
Fix Enchantments on 1.12.2 and lower
This commit is contained in:
parent
8225e51867
commit
727d473319
1 changed files with 12 additions and 5 deletions
|
@ -1,7 +1,5 @@
|
||||||
package com.earth2me.essentials;
|
package com.earth2me.essentials;
|
||||||
|
|
||||||
import com.earth2me.essentials.utils.NumberUtil;
|
|
||||||
|
|
||||||
import org.bukkit.NamespacedKey;
|
import org.bukkit.NamespacedKey;
|
||||||
import org.bukkit.enchantments.Enchantment;
|
import org.bukkit.enchantments.Enchantment;
|
||||||
|
|
||||||
|
@ -15,6 +13,7 @@ import java.util.Set;
|
||||||
public class Enchantments {
|
public class Enchantments {
|
||||||
private static final Map<String, Enchantment> ENCHANTMENTS = new HashMap<String, Enchantment>();
|
private static final Map<String, Enchantment> ENCHANTMENTS = new HashMap<String, Enchantment>();
|
||||||
private static final Map<String, Enchantment> ALIASENCHANTMENTS = new HashMap<String, Enchantment>();
|
private static final Map<String, Enchantment> ALIASENCHANTMENTS = new HashMap<String, Enchantment>();
|
||||||
|
private static boolean isFlat;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
ENCHANTMENTS.put("alldamage", Enchantment.DAMAGE_ALL);
|
ENCHANTMENTS.put("alldamage", Enchantment.DAMAGE_ALL);
|
||||||
|
@ -231,14 +230,22 @@ public class Enchantments {
|
||||||
ALIASENCHANTMENTS.put("channel", channelling);
|
ALIASENCHANTMENTS.put("channel", channelling);
|
||||||
}
|
}
|
||||||
} catch (IllegalArgumentException ignored) {}
|
} catch (IllegalArgumentException ignored) {}
|
||||||
|
|
||||||
|
try {
|
||||||
|
Class<?> namespacedKeyClass = Class.forName("org.bukkit.NamespacedKey");
|
||||||
|
Class<?> enchantmentClass = Class.forName("org.bukkit.enchantments.Enchantment");
|
||||||
|
enchantmentClass.getDeclaredMethod("getByKey", namespacedKeyClass);
|
||||||
|
isFlat = true;
|
||||||
|
} catch (ClassNotFoundException | NoSuchMethodException e) {
|
||||||
|
isFlat = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Enchantment getByName(String name) {
|
public static Enchantment getByName(String name) {
|
||||||
Enchantment enchantment = null;
|
Enchantment enchantment = null;
|
||||||
try {
|
if (isFlat) { // 1.13+ only
|
||||||
// 1.13+ only
|
|
||||||
enchantment = Enchantment.getByKey(NamespacedKey.minecraft(name.toLowerCase()));
|
enchantment = Enchantment.getByKey(NamespacedKey.minecraft(name.toLowerCase()));
|
||||||
} catch (NoSuchMethodError ignored) {}
|
}
|
||||||
|
|
||||||
if (enchantment == null) {
|
if (enchantment == null) {
|
||||||
enchantment = Enchantment.getByName(name.toUpperCase());
|
enchantment = Enchantment.getByName(name.toUpperCase());
|
||||||
|
|
Loading…
Reference in a new issue