Updated Essentials Integration
This commit is contained in:
@@ -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));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.willfp.ecoenchants.integrations.essentials;
|
||||
|
||||
import com.willfp.ecoenchants.integrations.Integration;
|
||||
|
||||
public interface EssentialsWrapper extends Integration {
|
||||
void registerAllEnchantments();
|
||||
}
|
||||
@@ -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";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user