mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
Partially implemented eco enchant compatibility.
This commit is contained in:
parent
2e29e7f04e
commit
19806773a6
18 changed files with 143 additions and 35 deletions
|
|
@ -449,7 +449,7 @@ class AnvilEventListener(private val packetManager: PacketManager) : Listener {
|
|||
)
|
||||
resultEnchsKeys.remove(enchantment.key)
|
||||
|
||||
if (ConflictType.BIG_CONFLICT == conflictType) {
|
||||
if (ConflictType.ENCHANTMENT_CONFLICT == conflictType) {
|
||||
illegalPenalty += ConfigOptions.sacrificeIllegalCost
|
||||
CustomAnvil.verboseLog("Big conflict. Adding illegal price penalty")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ object DependencyManager {
|
|||
|
||||
lateinit var packetManager: PacketManager
|
||||
var enchantmentSquaredCompatibility: EnchantmentSquaredDependency? = null
|
||||
var ecoEnchantCompatibility: EcoEnchantDependency? = null
|
||||
|
||||
fun loadDependency(){
|
||||
val pluginManager = Bukkit.getPluginManager()
|
||||
|
|
@ -24,11 +25,17 @@ object DependencyManager {
|
|||
enchantmentSquaredCompatibility!!.disableAnvilListener()
|
||||
}
|
||||
|
||||
// EcoEnchants dependency
|
||||
if(pluginManager.isPluginEnabled("EcoEnchants")){
|
||||
ecoEnchantCompatibility = EcoEnchantDependency(pluginManager.getPlugin("EcoEnchants")!!)
|
||||
ecoEnchantCompatibility!!.disableAnvilListener()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun handleConfigChanges() {
|
||||
|
||||
enchantmentSquaredCompatibility?.registerPluginConfiguration()
|
||||
ecoEnchantCompatibility?.registerEnchantments()
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,31 @@
|
|||
package xyz.alexcrea.cuanvil.dependency
|
||||
|
||||
import com.willfp.ecoenchants.enchant.EcoEnchants
|
||||
import io.delilaheve.CustomAnvil
|
||||
import org.bukkit.event.inventory.PrepareAnvilEvent
|
||||
import org.bukkit.plugin.Plugin
|
||||
import xyz.alexcrea.cuanvil.enchant.CAEnchantment
|
||||
import xyz.alexcrea.cuanvil.enchant.CAEnchantmentRegistry
|
||||
import xyz.alexcrea.cuanvil.enchant.wrapped.CAEcoEnchant
|
||||
|
||||
class EcoEnchantDependency(private val ecoEnchantPlugin: Plugin) {
|
||||
|
||||
init {
|
||||
CustomAnvil.instance.logger.info("Eco Enchant Detected !")
|
||||
}
|
||||
|
||||
fun disableAnvilListener(){
|
||||
PrepareAnvilEvent.getHandlerList().unregister(this.ecoEnchantPlugin)
|
||||
}
|
||||
|
||||
fun registerEnchantments() {
|
||||
val registery = CAEnchantmentRegistry.getInstance()
|
||||
for (ecoEnchant in EcoEnchants.values()) {
|
||||
val enchantments: CAEnchantment = CAEcoEnchant(ecoEnchant)
|
||||
|
||||
registery.unregister(registery.getByKey(ecoEnchant.enchantment.key)) // As
|
||||
registery.register(enchantments)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -15,17 +15,19 @@ import java.util.*
|
|||
|
||||
class EnchantmentSquaredDependency(private val enchantmentSquaredPlugin: Plugin) {
|
||||
|
||||
fun disableAnvilListener(){
|
||||
PrepareAnvilEvent.getHandlerList().unregister(this.enchantmentSquaredPlugin)
|
||||
|
||||
init {
|
||||
CustomAnvil.instance.logger.info("Enchantment Squared Detected !")
|
||||
CustomAnvil.instance.logger.info("Please be aware that Custom Anvil is bypassing Enchantment Squared ")
|
||||
CustomAnvil.instance.logger.info(
|
||||
"compatible_with, " +
|
||||
"disable_anvil, " +
|
||||
"incompatible_vanilla_enchantments, " +
|
||||
"incompatible_custom_enchantments and max_level " +
|
||||
"configuration values.")
|
||||
"disable_anvil, " +
|
||||
"incompatible_vanilla_enchantments, " +
|
||||
"incompatible_custom_enchantments and max_level " +
|
||||
"configuration values.")
|
||||
}
|
||||
|
||||
fun disableAnvilListener(){
|
||||
PrepareAnvilEvent.getHandlerList().unregister(this.enchantmentSquaredPlugin)
|
||||
}
|
||||
|
||||
fun registerEnchantments(){
|
||||
|
|
@ -118,7 +120,7 @@ class EnchantmentSquaredDependency(private val enchantmentSquaredPlugin: Plugin)
|
|||
|
||||
if(!groupConfig.isConfigurationSection("hoes")){
|
||||
groupConfig["hoes.type"] = "include"
|
||||
groupConfig["hoes.items"] = listOf("wooden_hoe", "stone_ho", "iron_hoe", "diamond_hoe", "golden_hoe", "netherite_hoe")
|
||||
groupConfig["hoes.items"] = listOf("wooden_hoe", "stone_hoe", "iron_hoe", "diamond_hoe", "golden_hoe", "netherite_hoe")
|
||||
}
|
||||
|
||||
if(!groupConfig.isConfigurationSection("shield")){
|
||||
|
|
@ -220,5 +222,5 @@ class EnchantmentSquaredDependency(private val enchantmentSquaredPlugin: Plugin)
|
|||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -148,7 +148,7 @@ class EnchantConflictManager {
|
|||
fun isConflicting(appliedEnchants: Map<CAEnchantment, Int>, item: ItemStack, newEnchant: CAEnchantment): ConflictType {
|
||||
val mat = item.type
|
||||
CustomAnvil.verboseLog("Testing conflict for ${newEnchant.key} on ${mat.key}")
|
||||
val conflictList = newEnchant.conflicts;
|
||||
val conflictList = newEnchant.conflicts
|
||||
|
||||
var result = ConflictType.NO_CONFLICT
|
||||
for (conflict in conflictList) {
|
||||
|
|
@ -157,17 +157,17 @@ class EnchantConflictManager {
|
|||
CustomAnvil.verboseLog("Was against $conflict and conflicting: ${!allowed} ")
|
||||
if (!allowed) {
|
||||
if (conflict.getEnchants().size <= 1) {
|
||||
result = ConflictType.SMALL_CONFLICT
|
||||
result = ConflictType.ITEM_CONFLICT
|
||||
CustomAnvil.verboseLog("Small conflict, continuing")
|
||||
} else {
|
||||
CustomAnvil.verboseLog("Big conflict, probably stoping")
|
||||
return ConflictType.BIG_CONFLICT
|
||||
return ConflictType.ENCHANTMENT_CONFLICT
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Test conflict with other conflict system.
|
||||
val otherConflict = newEnchant.testConflict(appliedEnchants, mat, reEnchantSupplier(item, appliedEnchants))
|
||||
val otherConflict = newEnchant.testOtherConflicts(appliedEnchants, mat, reEnchantSupplier(item, appliedEnchants))
|
||||
|
||||
return result.getWorstConflict(otherConflict)
|
||||
}
|
||||
|
|
@ -181,7 +181,7 @@ class EnchantConflictManager {
|
|||
enchantment -> enchantment.key.addEnchantmentUnsafe(item, enchantment.value)
|
||||
}
|
||||
|
||||
return@Supplier newItem;
|
||||
return@Supplier newItem
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -199,13 +199,13 @@ enum class ConflictType(private val importance: Int) {
|
|||
/**
|
||||
* Inform that the anvil process should not change the current applied enchantment.
|
||||
*/
|
||||
SMALL_CONFLICT(1),
|
||||
ITEM_CONFLICT(1),
|
||||
|
||||
/**
|
||||
* Inform that the anvil process should not change the current applied enchantment.
|
||||
* Also add sacrificeIllegalCost for every enchantment marked as big conflict.
|
||||
*/
|
||||
BIG_CONFLICT(2);
|
||||
ENCHANTMENT_CONFLICT(2);
|
||||
|
||||
fun getWorstConflict(otherConflict: ConflictType): ConflictType {
|
||||
return if(this.importance > otherConflict.importance) this
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue