Added essentials integration

This commit is contained in:
Auxilor
2020-08-28 21:52:09 +01:00
parent 6fb18325f1
commit e785c9350c
6 changed files with 31 additions and 0 deletions

View File

@@ -35,6 +35,11 @@ public class Main extends JavaPlugin {
*/
public static boolean hasAE;
/**
* Has Essentials?
*/
public static boolean hasEssentials;
/**
* ProtocolLib
*/

View File

@@ -1,9 +1,12 @@
package com.willfp.ecoenchants.enchantments;
import com.earth2me.essentials.Enchantments;
import com.willfp.ecoenchants.Main;
import com.willfp.ecoenchants.config.ConfigManager;
import com.willfp.ecoenchants.config.configs.EnchantmentConfig;
import com.willfp.ecoenchants.nms.Target;
import org.apache.commons.lang.WordUtils;
import org.apache.commons.lang.reflect.FieldUtils;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.enchantments.Enchantment;
@@ -14,6 +17,7 @@ import org.bukkit.inventory.ItemStack;
import java.lang.reflect.Field;
import java.util.*;
@SuppressWarnings("unchecked")
public abstract class EcoEnchant extends Enchantment implements Listener {
private String name;
private String description;
@@ -96,6 +100,12 @@ public abstract class EcoEnchant extends Enchantment implements Listener {
f.setAccessible(false);
Enchantment.registerEnchantment(this);
if(Main.hasEssentials) {
Map<String, Enchantment> essentialsMap = (Map<String, Enchantment>) FieldUtils.readDeclaredStaticField(Enchantments.class, "ENCHANTMENTS", true);
essentialsMap.remove(this.getName());
essentialsMap.put(this.getName(), this);
}
} catch (NoSuchFieldException | IllegalAccessException ignored) {}
}

View File

@@ -147,6 +147,10 @@ public class Loader {
if(Main.hasAE) Bukkit.getLogger().info("AdvancedEnchantments: §aENABLED");
else Bukkit.getLogger().info("AdvancedEnchantments: §9DISABLED");
Main.hasEssentials = Bukkit.getPluginManager().isPluginEnabled("Essentials");
if(Main.hasEssentials) Bukkit.getLogger().info("Essentials: §aENABLED");
else Bukkit.getLogger().info("Essentials: §9DISABLED");
Bukkit.getLogger().info("");
Bukkit.getLogger().info("Loading Anticheat Integrations...");