mirror of
https://github.com/Auxilor/EcoEnchants.git
synced 2025-02-03 02:21:21 +01:00
commit
9ef586ad56
@ -1,10 +1,12 @@
|
|||||||
package com.willfp.ecoenchants.enchantments;
|
package com.willfp.ecoenchants.enchantments;
|
||||||
|
|
||||||
import com.earth2me.essentials.Enchantments;
|
import com.earth2me.essentials.Enchantments;
|
||||||
|
import com.earth2me.essentials.Essentials;
|
||||||
import com.willfp.ecoenchants.Main;
|
import com.willfp.ecoenchants.Main;
|
||||||
import com.willfp.ecoenchants.config.ConfigManager;
|
import com.willfp.ecoenchants.config.ConfigManager;
|
||||||
import com.willfp.ecoenchants.config.configs.EnchantmentConfig;
|
import com.willfp.ecoenchants.config.configs.EnchantmentConfig;
|
||||||
import com.willfp.ecoenchants.nms.Target;
|
import com.willfp.ecoenchants.nms.Target;
|
||||||
|
import com.willfp.ecoenchants.util.EssentialsUtils;
|
||||||
import org.apache.commons.lang.WordUtils;
|
import org.apache.commons.lang.WordUtils;
|
||||||
import org.apache.commons.lang.reflect.FieldUtils;
|
import org.apache.commons.lang.reflect.FieldUtils;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@ -102,9 +104,12 @@ public abstract class EcoEnchant extends Enchantment implements Listener {
|
|||||||
Enchantment.registerEnchantment(this);
|
Enchantment.registerEnchantment(this);
|
||||||
|
|
||||||
if(Main.hasEssentials) {
|
if(Main.hasEssentials) {
|
||||||
Map<String, Enchantment> essentialsMap = (Map<String, Enchantment>) FieldUtils.readDeclaredStaticField(Enchantments.class, "ENCHANTMENTS", true);
|
Map<String, Enchantment> essentialsMap = EssentialsUtils.getEnchantmentsMap();
|
||||||
essentialsMap.remove(this.getName());
|
if (essentialsMap != null) {
|
||||||
essentialsMap.put(this.getName(), this);
|
String key = this.getKey().getKey();
|
||||||
|
essentialsMap.remove(key);
|
||||||
|
essentialsMap.put(key, this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (NoSuchFieldException | IllegalAccessException ignored) {}
|
} catch (NoSuchFieldException | IllegalAccessException ignored) {}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,37 @@
|
|||||||
|
package com.willfp.ecoenchants.util;
|
||||||
|
|
||||||
|
import com.earth2me.essentials.Enchantments;
|
||||||
|
import org.apache.commons.lang.reflect.FieldUtils;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.enchantments.Enchantment;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class EssentialsUtils {
|
||||||
|
private static Map<String, Enchantment> essentialsEnchantmentsMap;
|
||||||
|
private static boolean hasCheckedEnchantmentsMap;
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public static Map<String, Enchantment> getEnchantmentsMap() {
|
||||||
|
if (hasCheckedEnchantmentsMap) return essentialsEnchantmentsMap;
|
||||||
|
|
||||||
|
if (Bukkit.getPluginManager().isPluginEnabled("Essentials")) {
|
||||||
|
try {
|
||||||
|
Class<?> essEnchantmentsClass = Enchantments.class;
|
||||||
|
|
||||||
|
Object enchantments = FieldUtils.readDeclaredStaticField(essEnchantmentsClass, "ENCHANTMENTS", true);
|
||||||
|
if (enchantments instanceof Map) {
|
||||||
|
hasCheckedEnchantmentsMap = true;
|
||||||
|
//noinspection unchecked - we know the type of it
|
||||||
|
return essentialsEnchantmentsMap = (Map<String, Enchantment>) enchantments;
|
||||||
|
}
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
hasCheckedEnchantmentsMap = true;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
hasCheckedEnchantmentsMap = true;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user