mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 08:14:00 +02:00
commit
58b2910350
3 changed files with 92 additions and 13 deletions
|
|
@ -22,7 +22,7 @@ plugins {
|
||||||
}
|
}
|
||||||
|
|
||||||
group = "xyz.alexcrea"
|
group = "xyz.alexcrea"
|
||||||
version = "1.15.9"
|
version = "1.15.10"
|
||||||
|
|
||||||
val isDevBuild = System.getenv("SMALL_COMMIT_HASH") != null
|
val isDevBuild = System.getenv("SMALL_COMMIT_HASH") != null
|
||||||
val isPreRelease = System.getenv("IS_GITHUB_PRERELEASE") == "true"
|
val isPreRelease = System.getenv("IS_GITHUB_PRERELEASE") == "true"
|
||||||
|
|
|
||||||
|
|
@ -5,31 +5,32 @@ import org.bukkit.inventory.ItemStack;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import su.nightexpress.excellentenchants.api.enchantment.CustomEnchantment;
|
import su.nightexpress.excellentenchants.api.enchantment.CustomEnchantment;
|
||||||
import su.nightexpress.excellentenchants.api.item.ItemSet;
|
import su.nightexpress.excellentenchants.api.item.ItemSet;
|
||||||
import su.nightexpress.excellentenchants.api.wrapper.EnchantDefinition;
|
|
||||||
import xyz.alexcrea.cuanvil.enchant.AdditionalTestEnchantment;
|
import xyz.alexcrea.cuanvil.enchant.AdditionalTestEnchantment;
|
||||||
import xyz.alexcrea.cuanvil.enchant.CAEnchantment;
|
import xyz.alexcrea.cuanvil.enchant.CAEnchantment;
|
||||||
import xyz.alexcrea.cuanvil.enchant.EnchantmentRarity;
|
import xyz.alexcrea.cuanvil.enchant.EnchantmentRarity;
|
||||||
|
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class CAEEV5Enchantment extends CABukkitEnchantment implements AdditionalTestEnchantment {
|
public class CAEEV5Enchantment extends CABukkitEnchantment implements AdditionalTestEnchantment {
|
||||||
|
|
||||||
@NotNull CustomEnchantment eeenchantment;
|
@NotNull CustomEnchantment eeenchantment;
|
||||||
@NotNull EnchantDefinition definition;
|
@NotNull Object definition;
|
||||||
|
|
||||||
public CAEEV5Enchantment(@NotNull CustomEnchantment enchantment) {
|
public CAEEV5Enchantment(@NotNull CustomEnchantment enchantment) {
|
||||||
super(enchantment.getBukkitEnchantment(), EnchantmentRarity.getRarity(enchantment.getDefinition().getAnvilCost()));
|
super(enchantment.getBukkitEnchantment(), EnchantmentRarity.getRarity(getAnvilCost(enchantment)));
|
||||||
this.eeenchantment = enchantment;
|
this.eeenchantment = enchantment;
|
||||||
this.definition = enchantment.getDefinition();
|
this.definition = getDefinition(enchantment);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isEnchantConflict(@NotNull Map<CAEnchantment, Integer> enchantments, @NotNull Material itemMat) {
|
public boolean isEnchantConflict(@NotNull Map<CAEnchantment, Integer> enchantments, @NotNull Material itemMat) {
|
||||||
if (!definition.hasConflicts()) return false;
|
if (!hasConflicts()) return false;
|
||||||
|
|
||||||
Set<String> conflicts = definition.getExclusiveSet();
|
Set<String> conflicts = getExclusiveSet();
|
||||||
|
|
||||||
for (CAEnchantment caEnchantment : enchantments.keySet()) {
|
for (CAEnchantment caEnchantment : enchantments.keySet()) {
|
||||||
if (conflicts.contains(caEnchantment.getName())) return true;
|
if (conflicts.contains(caEnchantment.getName())) return true;
|
||||||
|
|
@ -52,4 +53,74 @@ public class CAEEV5Enchantment extends CABukkitEnchantment implements Additional
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static final Method getDefinitonMethod;
|
||||||
|
|
||||||
|
private static final Method getAnvilCostMethod;
|
||||||
|
private static final Method hasConflictsMethod;
|
||||||
|
private static final Method getExclusiveSetMethod;
|
||||||
|
static {
|
||||||
|
var enchClazz = CustomEnchantment.class;
|
||||||
|
try {
|
||||||
|
getDefinitonMethod = enchClazz.getDeclaredMethod("getDefinition");
|
||||||
|
} catch (NoSuchMethodException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
Class<?> definitionClazz;
|
||||||
|
try {
|
||||||
|
definitionClazz = Class.forName("su.nightexpress.excellentenchants.api.EnchantDefinition");
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
try {
|
||||||
|
definitionClazz = Class.forName("su.nightexpress.excellentenchants.api.wrapper.EnchantDefinition");
|
||||||
|
} catch (ClassNotFoundException ex) {
|
||||||
|
throw new RuntimeException(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now definition methods
|
||||||
|
try {
|
||||||
|
getAnvilCostMethod = definitionClazz.getDeclaredMethod("getAnvilCost");
|
||||||
|
hasConflictsMethod = definitionClazz.getDeclaredMethod("hasConflicts");
|
||||||
|
getExclusiveSetMethod = definitionClazz.getDeclaredMethod("getExclusiveSet");
|
||||||
|
} catch (NoSuchMethodException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Object getDefinition(CustomEnchantment enchantment) {
|
||||||
|
try {
|
||||||
|
return getDefinitonMethod.invoke(enchantment);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int getAnvilCost(CustomEnchantment enchantment) {
|
||||||
|
try {
|
||||||
|
return (int) getAnvilCostMethod.invoke(getDefinition(enchantment));
|
||||||
|
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean hasConflicts() {
|
||||||
|
try {
|
||||||
|
return (boolean) hasConflictsMethod.invoke(definition);
|
||||||
|
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private Set<String> getExclusiveSet() {
|
||||||
|
try {
|
||||||
|
return (Set<String>) getExclusiveSetMethod.invoke(definition);
|
||||||
|
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -163,8 +163,8 @@ class ExcellentEnchantsDependency {
|
||||||
}
|
}
|
||||||
|
|
||||||
when (listenerVersion) {
|
when (listenerVersion) {
|
||||||
|
ListenerVersion.V5_3,
|
||||||
ListenerVersion.V5,
|
ListenerVersion.V5,
|
||||||
ListenerVersion.V5_3
|
|
||||||
-> this.usedAnvilListener = v5AnvilListener!!
|
-> this.usedAnvilListener = v5AnvilListener!!
|
||||||
ListenerVersion.PRE_V5 -> this.usedAnvilListener = preV5AnvilListener!!
|
ListenerVersion.PRE_V5 -> this.usedAnvilListener = preV5AnvilListener!!
|
||||||
ListenerVersion.LEGACY -> this.usedAnvilListener = legacyAnvilListener!!
|
ListenerVersion.LEGACY -> this.usedAnvilListener = legacyAnvilListener!!
|
||||||
|
|
@ -184,11 +184,19 @@ class ExcellentEnchantsDependency {
|
||||||
)
|
)
|
||||||
this.handleRechargeMethod.setAccessible(true)
|
this.handleRechargeMethod.setAccessible(true)
|
||||||
|
|
||||||
this.handleCombineMethod = this.usedAnvilListener.javaClass.getDeclaredMethod(
|
try {
|
||||||
"handleCombine",
|
this.handleCombineMethod = this.usedAnvilListener.javaClass.getDeclaredMethod(
|
||||||
PrepareAnvilEvent::class.java, ItemStack::class.java, ItemStack::class.java, ItemStack::class.java
|
"anvilCombine",
|
||||||
)
|
PrepareAnvilEvent::class.java, ItemStack::class.java, ItemStack::class.java, ItemStack::class.java
|
||||||
this.handleCombineMethod.setAccessible(true)
|
)
|
||||||
|
this.handleCombineMethod.setAccessible(true)
|
||||||
|
} catch (_: NoSuchMethodException) {
|
||||||
|
this.handleCombineMethod = this.usedAnvilListener.javaClass.getDeclaredMethod(
|
||||||
|
"handleCombine",
|
||||||
|
PrepareAnvilEvent::class.java, ItemStack::class.java, ItemStack::class.java, ItemStack::class.java
|
||||||
|
)
|
||||||
|
this.handleCombineMethod.setAccessible(true)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue