mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
make HavenBags works with CustomAnvil. fix #44
This commit is contained in:
parent
85d2d873eb
commit
84ce0afd2b
5 changed files with 128 additions and 18 deletions
|
|
@ -44,11 +44,14 @@ dependencies {
|
|||
// ExcellentEnchants
|
||||
compileOnly(files("libs/nightcore-2.6.4.jar"))
|
||||
compileOnly(files("libs/ExcellentEnchants-4.2.2.jar"))
|
||||
compileOnly(files("libs/ExcellentEnchants 4.1.0-striped.jar"))
|
||||
compileOnly(files("libs/ExcellentEnchants 4.1.0-striped.jar")) // For legacy excellent enchants
|
||||
|
||||
// Disenchantment
|
||||
compileOnly("cz.kominekjan:Disenchantment:v5.4.0")
|
||||
|
||||
// HavenBags
|
||||
compileOnly(files("libs/HavenBags-1.30.1.1729.jar"))
|
||||
|
||||
// Include nms
|
||||
implementation(project(":nms:nms-common"))
|
||||
implementation(project(":nms:v1_17R1", configuration = "reobf"))
|
||||
|
|
|
|||
BIN
libs/HavenBags-1.30.1.1729.jar
Normal file
BIN
libs/HavenBags-1.30.1.1729.jar
Normal file
Binary file not shown.
|
|
@ -28,13 +28,14 @@ object DependencyManager {
|
|||
var excellentEnchantsCompatibility: ExcellentEnchantsDependency? = null
|
||||
|
||||
var disenchantmentCompatibility: DisenchantmentDependency? = null
|
||||
var havenBagsCompatibility: HavenBagsDependency? = null
|
||||
|
||||
fun loadDependency(){
|
||||
fun loadDependency() {
|
||||
val pluginManager = Bukkit.getPluginManager()
|
||||
|
||||
// Bukkit or Paper scheduler ?
|
||||
isFolia = testIsFolia()
|
||||
scheduler = if(isFolia) {
|
||||
scheduler = if (isFolia) {
|
||||
CustomAnvil.instance.logger.info("Folia detected... Custom Anvil Folia support is experimental. issues are more likely to happens.")
|
||||
|
||||
FoliaScheduler()
|
||||
|
|
@ -46,29 +47,35 @@ object DependencyManager {
|
|||
externGuiTester = GuiTesterSelector.selectGuiTester
|
||||
|
||||
// Enchantment Squared dependency
|
||||
if(pluginManager.isPluginEnabled("EnchantsSquared")){
|
||||
if (pluginManager.isPluginEnabled("EnchantsSquared")) {
|
||||
enchantmentSquaredCompatibility = EnchantmentSquaredDependency(pluginManager.getPlugin("EnchantsSquared")!!)
|
||||
enchantmentSquaredCompatibility!!.disableAnvilListener()
|
||||
}
|
||||
|
||||
// EcoEnchants dependency
|
||||
if(pluginManager.isPluginEnabled("EcoEnchants")){
|
||||
if (pluginManager.isPluginEnabled("EcoEnchants")) {
|
||||
ecoEnchantCompatibility = EcoEnchantDependency(pluginManager.getPlugin("EcoEnchants")!!)
|
||||
ecoEnchantCompatibility!!.disableAnvilListener()
|
||||
}
|
||||
|
||||
// Excellent Enchants dependency
|
||||
if(pluginManager.isPluginEnabled("ExcellentEnchants")){
|
||||
if (pluginManager.isPluginEnabled("ExcellentEnchants")) {
|
||||
excellentEnchantsCompatibility = ExcellentEnchantsDependency()
|
||||
excellentEnchantsCompatibility!!.redirectListeners()
|
||||
}
|
||||
|
||||
// Disenchantment dependency
|
||||
if(pluginManager.isPluginEnabled("Disenchantment")){
|
||||
if (pluginManager.isPluginEnabled("Disenchantment")) {
|
||||
disenchantmentCompatibility = DisenchantmentDependency()
|
||||
disenchantmentCompatibility!!.redirectListeners()
|
||||
}
|
||||
|
||||
// HavenBags dependency
|
||||
if (pluginManager.isPluginEnabled("HavenBags")) {
|
||||
havenBagsCompatibility = HavenBagsDependency()
|
||||
havenBagsCompatibility!!.redirectListeners()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun handleCompatibilityConfig() {
|
||||
|
|
@ -83,7 +90,7 @@ object DependencyManager {
|
|||
|
||||
}
|
||||
|
||||
fun handleConfigReload(){
|
||||
fun handleConfigReload() {
|
||||
// Register enchantment of compatible plugin and load configuration change.
|
||||
handleCompatibilityConfig()
|
||||
|
||||
|
|
@ -95,14 +102,18 @@ object DependencyManager {
|
|||
fun tryEventPreAnvilBypass(event: PrepareAnvilEvent, player: HumanEntity): Boolean {
|
||||
var bypass = false
|
||||
|
||||
// Test if disenchantment used special prepare anvil
|
||||
if(disenchantmentCompatibility?.testPrepareAnvil(event, player) == true) bypass = true
|
||||
// Test if disenchantment used prepare anvil
|
||||
if (disenchantmentCompatibility?.testPrepareAnvil(event, player) == true) bypass = true
|
||||
|
||||
// Test excellent enchantments used special prepare anvil
|
||||
if(!bypass && (excellentEnchantsCompatibility?.testPrepareAnvil(event) == true)) bypass = true
|
||||
// Test heaven bags used prepare anvil
|
||||
if (!bypass && (havenBagsCompatibility?.testPrepareAnvil(event, player) == true)) bypass = true
|
||||
|
||||
// Test excellent enchantments used prepare anvil
|
||||
if (!bypass && (excellentEnchantsCompatibility?.testPrepareAnvil(event) == true)) bypass = true
|
||||
|
||||
// Test if the inventory is a gui(version specific)
|
||||
if(!bypass && (externGuiTester?.testIfGui(event.view) == true)) bypass = true
|
||||
if (!bypass && (externGuiTester?.testIfGui(event.view) == true)) bypass = true
|
||||
|
||||
|
||||
return bypass
|
||||
}
|
||||
|
|
@ -114,14 +125,17 @@ object DependencyManager {
|
|||
fun tryClickAnvilResultBypass(event: InventoryClickEvent, inventory: AnvilInventory): Boolean {
|
||||
var bypass = false
|
||||
|
||||
// Test if disenchantment used special event click
|
||||
if(disenchantmentCompatibility?.testAnvilResult(event, inventory) == true) bypass = true
|
||||
// Test if disenchantment used event click
|
||||
if (disenchantmentCompatibility?.testAnvilResult(event, inventory) == true) bypass = true
|
||||
|
||||
// Test if disenchantment used special event click
|
||||
if(!bypass && (excellentEnchantsCompatibility?.testAnvilResult(event) == true)) bypass = true
|
||||
// Test if haven bag used event click
|
||||
if (!bypass && (havenBagsCompatibility?.testAnvilResult(event, inventory) == true)) bypass = true
|
||||
|
||||
// Test if disenchantment used event click
|
||||
if (!bypass && (excellentEnchantsCompatibility?.testAnvilResult(event) == true)) bypass = true
|
||||
|
||||
// Test if the inventory is a gui(version specific)
|
||||
if(!bypass && (externGuiTester?.testIfGui(event.view) == true)) bypass = true
|
||||
if (!bypass && (externGuiTester?.testIfGui(event.view) == true)) bypass = true
|
||||
|
||||
return bypass
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,92 @@
|
|||
package xyz.alexcrea.cuanvil.dependency
|
||||
|
||||
import io.delilaheve.CustomAnvil
|
||||
import org.bukkit.entity.HumanEntity
|
||||
import org.bukkit.event.inventory.InventoryClickEvent
|
||||
import org.bukkit.event.inventory.PrepareAnvilEvent
|
||||
import org.bukkit.inventory.AnvilInventory
|
||||
import org.bukkit.inventory.ItemStack
|
||||
import org.bukkit.plugin.RegisteredListener
|
||||
import valorless.havenbags.BagSkin
|
||||
import valorless.havenbags.BagUpgrade
|
||||
import valorless.havenbags.HavenBags
|
||||
import valorless.havenbags.prevention.EquipPrevention
|
||||
import xyz.alexcrea.cuanvil.listener.PrepareAnvilListener
|
||||
import xyz.alexcrea.cuanvil.util.AnvilXpUtil
|
||||
|
||||
class HavenBagsDependency {
|
||||
|
||||
init {
|
||||
CustomAnvil.instance.logger.info("Heaven Bags Detected !")
|
||||
}
|
||||
|
||||
private lateinit var bagUpgrade: BagUpgrade
|
||||
private lateinit var bagSkin: BagSkin
|
||||
|
||||
fun redirectListeners() {
|
||||
val toUnregister = ArrayList<RegisteredListener>()
|
||||
// get required PrepareAnvilEvent listener
|
||||
for (registeredListener in PrepareAnvilEvent.getHandlerList().registeredListeners) {
|
||||
val listener = registeredListener.listener
|
||||
|
||||
if (listener is BagUpgrade) {
|
||||
bagUpgrade = listener
|
||||
toUnregister.add(registeredListener)
|
||||
}
|
||||
|
||||
if (listener is BagSkin) {
|
||||
bagSkin = listener
|
||||
toUnregister.add(registeredListener)
|
||||
}
|
||||
}
|
||||
|
||||
for (listener in toUnregister) {
|
||||
PrepareAnvilEvent.getHandlerList().unregister(listener)
|
||||
InventoryClickEvent.getHandlerList().unregister(listener)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun testPrepareAnvil(event: PrepareAnvilEvent, player: HumanEntity): Boolean {
|
||||
val previousResult = event.result
|
||||
event.result = null
|
||||
|
||||
// Test if event change the result
|
||||
bagSkin.onPrepareAnvil(event)
|
||||
if (event.result != null) {
|
||||
CustomAnvil.log("Detected pre anvil heaven bag anvil skin.")
|
||||
AnvilXpUtil.setAnvilInvXp(event.inventory, event.view, player, event.inventory.repairCost)
|
||||
return true
|
||||
}
|
||||
|
||||
bagUpgrade.onPrepareAnvil(event)
|
||||
if (event.result != null) {
|
||||
CustomAnvil.log("Detected pre anvil heaven bag anvil upgrade.")
|
||||
AnvilXpUtil.setAnvilInvXp(event.inventory, event.view, player, event.inventory.repairCost)
|
||||
return true
|
||||
}
|
||||
|
||||
event.result = previousResult
|
||||
return false
|
||||
}
|
||||
|
||||
fun testAnvilResult(event: InventoryClickEvent, inventory: AnvilInventory): Boolean {
|
||||
val result = inventory.getItem(PrepareAnvilListener.ANVIL_OUTPUT_SLOT)?.clone()
|
||||
|
||||
if (HavenBags.IsBag(result)) {
|
||||
CustomAnvil.log("Detected anvil click haven bag bypass.")
|
||||
bagUpgrade.onInventoryClick(event)
|
||||
bagSkin.onInventoryClick(event)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
private fun testAnvilInventoryChange(inventory: AnvilInventory, previous: ItemStack?): Boolean {
|
||||
val currentResult = inventory.getItem(PrepareAnvilListener.ANVIL_OUTPUT_SLOT)
|
||||
|
||||
return currentResult == previous
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -58,3 +58,4 @@ softdepend:
|
|||
- EcoEnchants
|
||||
- eco
|
||||
- ExcellentEnchants
|
||||
- HavenBags
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue