mirror of
https://github.com/Auxilor/EcoEnchants.git
synced 2025-01-25 00:51:20 +01:00
Fixed Anvil breaking with vanilla mismatched canEnchantItem logic
This commit is contained in:
parent
6f44b99289
commit
8240cc76f0
@ -269,7 +269,7 @@ abstract class EcoEnchant(
|
||||
override fun canEnchantItem(item: ItemStack): Boolean {
|
||||
if (
|
||||
item.fast().getEnchants(true).keys
|
||||
.filterIsInstance<EcoEnchant>()
|
||||
.map { it.wrap() }
|
||||
.count { it.type == this.type } >= this.type.limit
|
||||
) {
|
||||
return false
|
||||
|
@ -1,14 +1,17 @@
|
||||
package com.willfp.ecoenchants.enchants
|
||||
|
||||
import com.github.benmanes.caffeine.cache.Caffeine
|
||||
import com.willfp.eco.core.fast.fast
|
||||
import com.willfp.ecoenchants.EcoEnchantsPlugin
|
||||
import com.willfp.ecoenchants.proxy.proxies.EcoCraftEnchantmentManagerProxy
|
||||
import com.willfp.ecoenchants.rarity.EnchantmentRarities
|
||||
import com.willfp.ecoenchants.rarity.EnchantmentRarity
|
||||
import com.willfp.ecoenchants.type.EnchantmentType
|
||||
import com.willfp.ecoenchants.type.EnchantmentTypes
|
||||
import org.bukkit.Material
|
||||
import org.bukkit.NamespacedKey
|
||||
import org.bukkit.enchantments.Enchantment
|
||||
import org.bukkit.inventory.ItemStack
|
||||
import java.util.*
|
||||
|
||||
interface EcoEnchantLike {
|
||||
@ -19,6 +22,9 @@ interface EcoEnchantLike {
|
||||
val rarity: EnchantmentRarity
|
||||
|
||||
fun getUnformattedDescription(level: Int): String
|
||||
|
||||
// Includes all extra logic not found in vanilla canEnchantItem
|
||||
fun canEnchantItem(item: ItemStack): Boolean
|
||||
}
|
||||
|
||||
private val ecoEnchantLikes = Caffeine.newBuilder()
|
||||
@ -56,6 +62,27 @@ class VanillaEcoEnchantLike(
|
||||
return plugin.vanillaEnchantsYml.getString("${enchant.key.key}.description")
|
||||
}
|
||||
|
||||
override fun canEnchantItem(item: ItemStack): Boolean {
|
||||
// Yes this code is copied from EcoEnchant, but I can't be bothered to abstract it properly
|
||||
if (
|
||||
item.fast().getEnchants(true).keys
|
||||
.map { it.wrap() }
|
||||
.count { it.type == this.type } >= this.type.limit
|
||||
) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (item.fast().getEnchants(true).any { (enchant, _) -> enchant.conflictsWithDeep(this.enchant) }) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (item.type == Material.BOOK || item.type == Material.ENCHANTED_BOOK) {
|
||||
return true
|
||||
}
|
||||
|
||||
return enchant.canEnchantItem(item)
|
||||
}
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (other !is VanillaEcoEnchantLike) {
|
||||
return false
|
||||
|
@ -5,6 +5,7 @@ import com.willfp.eco.core.fast.fast
|
||||
import com.willfp.eco.core.proxy.ProxyConstants
|
||||
import com.willfp.eco.util.StringUtils
|
||||
import com.willfp.ecoenchants.enchants.EcoEnchants
|
||||
import com.willfp.ecoenchants.enchants.wrap
|
||||
import com.willfp.ecoenchants.proxy.proxies.OpenInventoryProxy
|
||||
import org.bukkit.ChatColor
|
||||
import org.bukkit.Material
|
||||
@ -58,7 +59,9 @@ class AnvilSupport(
|
||||
fun onAnvilPrepare(@NotNull event: PrepareAnvilEvent) {
|
||||
val player = event.viewers.getOrNull(0) as? Player ?: return
|
||||
|
||||
if (this.plugin.getProxy(OpenInventoryProxy::class.java).getOpenInventory(player)::class.java.toString() == anvilGuiClass) {
|
||||
if (this.plugin.getProxy(OpenInventoryProxy::class.java)
|
||||
.getOpenInventory(player)::class.java.toString() == anvilGuiClass
|
||||
) {
|
||||
return
|
||||
}
|
||||
|
||||
@ -102,7 +105,8 @@ class AnvilSupport(
|
||||
|
||||
val cost = oldCost + price
|
||||
|
||||
if (cost == 0) {
|
||||
// Cost could be less than zero at times, so I include that here.
|
||||
if (cost <= 0) {
|
||||
return@run
|
||||
}
|
||||
|
||||
@ -156,7 +160,8 @@ class AnvilSupport(
|
||||
return FAIL
|
||||
}
|
||||
|
||||
left.fast().displayName = formattedItemName.let { "§o$it" } // Not a great way to make it italic, but it works
|
||||
left.fast().displayName =
|
||||
formattedItemName.let { "§o$it" } // Not a great way to make it italic, but it works
|
||||
|
||||
return AnvilResult(left, 0)
|
||||
}
|
||||
@ -175,7 +180,8 @@ class AnvilSupport(
|
||||
val outEnchants = leftEnchants.toMutableMap()
|
||||
|
||||
for ((enchant, level) in rightEnchants) {
|
||||
if (enchant.canEnchantItem(left) && !outEnchants.containsKey(enchant)) {
|
||||
// Running .wrap() to use EcoEnchantLike canEnchantItem logic
|
||||
if (enchant.wrap().canEnchantItem(left) && !outEnchants.containsKey(enchant)) {
|
||||
if (outEnchants.size < plugin.configYml.getInt("anvil.enchant-limit").infiniteIfNegative()) {
|
||||
outEnchants[enchant] = level
|
||||
}
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
protection:
|
||||
name: "Protection"
|
||||
description: Reduces most types of damage.
|
||||
description: Reduces most types of damage
|
||||
type: normal
|
||||
rarity: common
|
||||
#max-level: 6 # Custom max level to override for the enchantment. Raise it, but lowering it may cause bugs.
|
||||
@ -15,228 +15,228 @@ protection:
|
||||
|
||||
fire_protection:
|
||||
name: "Fire Protection"
|
||||
description: Reduces fire damage and burn time.
|
||||
description: Reduces fire damage and burn time
|
||||
type: normal
|
||||
rarity: common
|
||||
|
||||
feather_falling:
|
||||
name: "Feather Falling"
|
||||
description: Reduces fall damage.
|
||||
description: Reduces fall damage
|
||||
type: normal
|
||||
rarity: common
|
||||
|
||||
blast_protection:
|
||||
name: "Blast Protection"
|
||||
type: normal
|
||||
description: Reduces explosion damage and knockback.
|
||||
description: Reduces explosion damage and knockback
|
||||
rarity: common
|
||||
|
||||
projectile_protection:
|
||||
name: "Projectile Protection"
|
||||
description: Reduces projectile damage.
|
||||
description: Reduces projectile damage
|
||||
type: normal
|
||||
rarity: common
|
||||
|
||||
respiration:
|
||||
name: "Respiration"
|
||||
description: Extends underwater breathing time.
|
||||
description: Extends underwater breathing time
|
||||
type: normal
|
||||
rarity: common
|
||||
|
||||
aqua_affinity:
|
||||
name: "Aqua Affinity"
|
||||
description: Increases underwater mining speed.
|
||||
description: Increases underwater mining speed
|
||||
type: normal
|
||||
rarity: common
|
||||
|
||||
thorns:
|
||||
name: "Thorns"
|
||||
description: Reflects some of the damage taken when hit.
|
||||
description: Reflects some of the damage taken when hit
|
||||
type: normal
|
||||
rarity: common
|
||||
|
||||
depth_strider:
|
||||
name: "Depth Strider"
|
||||
description: Increases underwater movement speed.
|
||||
description: Increases underwater movement speed
|
||||
type: normal
|
||||
rarity: common
|
||||
|
||||
frost_walker:
|
||||
name: "Frost Walker"
|
||||
description: Turns water beneath the player into ice.
|
||||
description: Turns water beneath the player into ice
|
||||
type: normal
|
||||
rarity: common
|
||||
|
||||
binding_curse:
|
||||
name: "Curse of Binding"
|
||||
description: Items cannot be removed from armor slots.
|
||||
description: Items cannot be removed from armor slots
|
||||
type: curse
|
||||
rarity: common
|
||||
|
||||
sharpness:
|
||||
name: "Sharpness"
|
||||
description: Increases damage.
|
||||
description: Increases damage
|
||||
type: normal
|
||||
rarity: common
|
||||
|
||||
smite:
|
||||
name: "Smite"
|
||||
description: Increases damage against undead mobs.
|
||||
description: Increases damage against undead mobs
|
||||
type: normal
|
||||
rarity: common
|
||||
|
||||
bane_of_arthropods:
|
||||
name: "Bane of Arthropods"
|
||||
description: Increases damage and slows arthropod mobs.
|
||||
description: Increases damage and slows arthropod mobs
|
||||
type: normal
|
||||
rarity: common
|
||||
|
||||
knockback:
|
||||
name: "Knockback"
|
||||
description: Increases knockback.
|
||||
description: Increases knockback
|
||||
type: normal
|
||||
rarity: common
|
||||
|
||||
fire_aspect:
|
||||
name: "Fire Aspect"
|
||||
description: Sets target on fire.
|
||||
description: Sets target on fire
|
||||
type: normal
|
||||
rarity: common
|
||||
|
||||
looting:
|
||||
name: "Looting"
|
||||
description: Increases mob loot.
|
||||
description: Increases mob loot
|
||||
type: normal
|
||||
rarity: common
|
||||
|
||||
sweeping:
|
||||
name: "Sweeping Edge"
|
||||
description: Increases sweeping attack damage.
|
||||
description: Increases sweeping attack damage
|
||||
type: normal
|
||||
rarity: common
|
||||
|
||||
efficiency:
|
||||
name: "Efficiency"
|
||||
description: Increases mining speed.
|
||||
description: Increases mining speed
|
||||
type: normal
|
||||
rarity: common
|
||||
|
||||
silk_touch:
|
||||
name: "Silk Touch"
|
||||
description: Mined blocks drop themselves exactly.
|
||||
description: Mined blocks drop themselves exactly
|
||||
type: normal
|
||||
rarity: common
|
||||
|
||||
unbreaking:
|
||||
name: "Unbreaking"
|
||||
description: Increases item durability.
|
||||
description: Increases item durability
|
||||
type: normal
|
||||
rarity: common
|
||||
|
||||
fortune:
|
||||
name: "Fortune"
|
||||
description: Increases certain block drops.
|
||||
description: Increases certain block drops
|
||||
type: normal
|
||||
rarity: common
|
||||
|
||||
power:
|
||||
name: "Power"
|
||||
description: Increases arrow damage.
|
||||
description: Increases arrow damage
|
||||
type: normal
|
||||
rarity: common
|
||||
|
||||
punch:
|
||||
name: "Punch"
|
||||
description: Increases arrow knockback.
|
||||
description: Increases arrow knockback
|
||||
type: normal
|
||||
rarity: common
|
||||
|
||||
flame:
|
||||
name: "Flame"
|
||||
description: Arrows set target on fire.
|
||||
description: Arrows set target on fire
|
||||
type: normal
|
||||
rarity: common
|
||||
|
||||
infinity:
|
||||
name: "Infinity"
|
||||
description: Shooting consumes no regular arrows.
|
||||
description: Shooting consumes no regular arrows
|
||||
type: normal
|
||||
rarity: common
|
||||
|
||||
luck_of_the_sea:
|
||||
name: "Luck of the Sea"
|
||||
description: Increases rate of good loot.
|
||||
description: Increases rate of good loot
|
||||
type: normal
|
||||
rarity: common
|
||||
|
||||
lure:
|
||||
name: "Lure"
|
||||
description: Decreases fishing wait time.
|
||||
description: Decreases fishing wait time
|
||||
type: normal
|
||||
rarity: common
|
||||
|
||||
loyalty:
|
||||
name: "Loyalty"
|
||||
description: Trident returns after being thrown.
|
||||
description: Trident returns after being thrown
|
||||
type: normal
|
||||
rarity: common
|
||||
|
||||
impaling:
|
||||
name: "Impaling"
|
||||
description: Trident deals additional damage to ocean mobs.
|
||||
description: Trident deals additional damage to ocean mobs
|
||||
type: normal
|
||||
rarity: common
|
||||
|
||||
riptide:
|
||||
name: "Riptide"
|
||||
description: Trident launches player when thrown in water or while raining.
|
||||
description: Trident launches player when thrown in water or while raining
|
||||
type: normal
|
||||
rarity: common
|
||||
|
||||
channeling:
|
||||
name: "Channeling"
|
||||
description: Strikes lightning where trident lands during thunderstorms.
|
||||
description: Strikes lightning where trident lands during thunderstorms
|
||||
type: normal
|
||||
rarity: common
|
||||
|
||||
multishot:
|
||||
name: "Multishot"
|
||||
description: Shoots 3 arrows.
|
||||
description: Shoots 3 arrows
|
||||
type: normal
|
||||
rarity: common
|
||||
|
||||
quick_charge:
|
||||
name: "Quick Charge"
|
||||
description: Decreases crossbow charging time.
|
||||
description: Decreases crossbow charging time
|
||||
type: normal
|
||||
rarity: common
|
||||
|
||||
piercing:
|
||||
name: "Piercing"
|
||||
description: Arrows pass through multiple entities.
|
||||
description: Arrows pass through multiple entities
|
||||
type: normal
|
||||
rarity: common
|
||||
|
||||
mending:
|
||||
name: "Mending"
|
||||
description: Repair the item while gaining XP orbs.
|
||||
description: Repair the item while gaining XP orbs
|
||||
type: normal
|
||||
rarity: common
|
||||
|
||||
vanishing_curse:
|
||||
name: "Curse of Vanishing"
|
||||
description: Item destroyed on death.
|
||||
description: Item destroyed on death
|
||||
type: curse
|
||||
rarity: common
|
||||
|
||||
soul_speed:
|
||||
name: "Soul Speed"
|
||||
description: Increases walking speed on soul sand and soul soil.
|
||||
description: Increases walking speed on soul sand and soul soil
|
||||
type: normal
|
||||
rarity: common
|
||||
|
||||
swift_sneak:
|
||||
name: "Swift Sneak"
|
||||
description: Increases speed while sneaking.
|
||||
description: Increases speed while sneaking
|
||||
type: normal
|
||||
rarity: common
|
||||
|
Loading…
Reference in New Issue
Block a user