mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
use reflection to support pre v5
This commit is contained in:
parent
d92a97781c
commit
b1fd64351a
6 changed files with 24 additions and 6 deletions
|
|
@ -7,8 +7,9 @@ import su.nightexpress.excellentenchants.api.enchantment.CustomEnchantment;
|
|||
import su.nightexpress.excellentenchants.api.enchantment.Definition;
|
||||
import xyz.alexcrea.cuanvil.enchant.AdditionalTestEnchantment;
|
||||
import xyz.alexcrea.cuanvil.enchant.CAEnchantment;
|
||||
import xyz.alexcrea.cuanvil.enchant.EnchantmentRarity;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
|
|
@ -20,10 +21,23 @@ public class CAEEPreV5Enchantment extends CABukkitEnchantment implements Additio
|
|||
public CAEEPreV5Enchantment(@NotNull CustomEnchantment enchantment) {
|
||||
super(enchantment.getBukkitEnchantment(), getRarity(enchantment.getBukkitEnchantment()));
|
||||
this.eeenchantment = enchantment;
|
||||
this.definition = (Definition) enchantment.getDefinition();
|
||||
try {
|
||||
this.definition = (Definition) getDefinition.invoke(enchantment);
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private final static Method getDefinition;
|
||||
static {
|
||||
try {
|
||||
getDefinition = CustomEnchantment.class.getMethod("getDefinition");
|
||||
} catch (NoSuchMethodException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnchantConflict(@NotNull Map<CAEnchantment, Integer> enchantments, @NotNull Material itemMat) {
|
||||
if (!definition.hasConflicts()) return false;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue