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

@@ -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";
}
}