Updated Essentials Integration

This commit is contained in:
Auxilor 2020-08-29 16:19:35 +01:00
parent aa66fc8357
commit f6bcbc7322
7 changed files with 59 additions and 12 deletions

View File

@ -30,11 +30,6 @@ public class EcoEnchantsPlugin extends JavaPlugin {
*/
public static String newVersion;
/**
* Has Essentials?
*/
public static boolean hasEssentials;
/**
* ProtocolLib
*/

View File

@ -100,10 +100,6 @@ public abstract class EcoEnchant extends Enchantment implements Listener {
f.setAccessible(false);
Enchantment.registerEnchantment(this);
if(EcoEnchantsPlugin.hasEssentials) {
((Map<String, Enchantment>) FieldUtils.readDeclaredStaticField(Enchantments.class, "ENCHANTMENTS", true)).put(this.getKey().getKey(), this);
}
} catch (NoSuchFieldException | IllegalAccessException ignored) {}
}

View File

@ -4,6 +4,7 @@ import com.willfp.ecoenchants.enchantments.ecoenchants.artifact.*;
import com.willfp.ecoenchants.enchantments.ecoenchants.curse.*;
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.*;
import com.willfp.ecoenchants.enchantments.ecoenchants.special.*;
import com.willfp.ecoenchants.integrations.essentials.EssentialsManager;
import org.bukkit.NamespacedKey;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;
@ -289,6 +290,7 @@ public class EcoEnchants {
for (EcoEnchant ecoEnchant : new HashSet<>(getAll())) {
ecoEnchant.update();
}
EssentialsManager.registerEnchantments();
}
/**

View File

@ -0,0 +1,16 @@
package com.willfp.ecoenchants.integrations.essentials;
import java.util.HashSet;
import java.util.Set;
public class EssentialsManager {
private static final Set<EssentialsWrapper> registered = new HashSet<>();
public static void registerAntigrief(EssentialsWrapper essentials) {
registered.add(essentials);
}
public static void registerEnchantments() {
registered.forEach((EssentialsWrapper::registerAllEnchantments));
}
}

View File

@ -0,0 +1,7 @@
package com.willfp.ecoenchants.integrations.essentials;
import com.willfp.ecoenchants.integrations.Integration;
public interface EssentialsWrapper extends Integration {
void registerAllEnchantments();
}

View File

@ -0,0 +1,26 @@
package com.willfp.ecoenchants.integrations.essentials.plugins;
import com.earth2me.essentials.Enchantments;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.integrations.essentials.EssentialsWrapper;
import org.apache.commons.lang.reflect.FieldUtils;
import org.bukkit.enchantments.Enchantment;
import java.util.Map;
@SuppressWarnings("unchecked")
public class IntegrationEssentials implements EssentialsWrapper {
@Override
public void registerAllEnchantments() {
try {
for (Enchantment enchantment : EcoEnchants.getAll()) {
((Map<String, Enchantment>) FieldUtils.readDeclaredStaticField(Enchantments.class, "ENCHANTMENTS", true)).put(enchantment.getKey().getKey(), enchantment);
}
} catch (IllegalAccessException ignored) {}
}
@Override
public String getPluginName() {
return "Essentials";
}
}

View File

@ -25,6 +25,8 @@ import com.willfp.ecoenchants.integrations.anticheat.plugins.AnticheatAAC;
import com.willfp.ecoenchants.integrations.anticheat.plugins.AnticheatMatrix;
import com.willfp.ecoenchants.integrations.antigrief.AntigriefManager;
import com.willfp.ecoenchants.integrations.antigrief.plugins.*;
import com.willfp.ecoenchants.integrations.essentials.EssentialsManager;
import com.willfp.ecoenchants.integrations.essentials.plugins.IntegrationEssentials;
import com.willfp.ecoenchants.listeners.EnchantingListeners;
import com.willfp.ecoenchants.listeners.PlayerJoinListener;
import com.willfp.ecoenchants.listeners.VillagerListeners;
@ -143,9 +145,12 @@ public class Loader {
Bukkit.getLogger().info("Lands: §9DISABLED");
}
EcoEnchantsPlugin.hasEssentials = Bukkit.getPluginManager().isPluginEnabled("Essentials");
if(EcoEnchantsPlugin.hasEssentials) Bukkit.getLogger().info("Essentials: §aENABLED");
else Bukkit.getLogger().info("Essentials: §9DISABLED");
if(Bukkit.getPluginManager().isPluginEnabled("Essentials")) {
EssentialsManager.registerAntigrief(new IntegrationEssentials());
Bukkit.getLogger().info("Essentials: §aENABLED");
} else {
Bukkit.getLogger().info("Essentials: §9DISABLED");
}
if(Bukkit.getPluginManager().isPluginEnabled("AAC")) {
AnticheatManager.registerAnticheat(new AnticheatAAC());