Fixed remaining bugs

This commit is contained in:
Auxilor 2023-03-19 17:52:39 +00:00
parent 9353dc601b
commit 9457260236
7 changed files with 50 additions and 119 deletions

View File

@ -21,7 +21,6 @@ import com.willfp.ecoenchants.mechanics.EnchantingTableSupport
import com.willfp.ecoenchants.mechanics.GrindstoneSupport
import com.willfp.ecoenchants.mechanics.LootSupport
import com.willfp.ecoenchants.mechanics.VillagerSupport
import com.willfp.ecoenchants.target.ActiveEnchantUpdateListeners
import com.willfp.ecoenchants.target.EnchantLookup.heldEnchantLevels
import com.willfp.libreforge.loader.LibreforgePlugin
import com.willfp.libreforge.loader.configs.ConfigCategory
@ -62,7 +61,6 @@ class EcoEnchantsPlugin : LibreforgePlugin() {
override fun loadListeners(): List<Listener> {
return listOf(
ActiveEnchantUpdateListeners(this),
VillagerSupport(this),
EnchantingTableSupport(this),
LootSupport(this),

View File

@ -1,6 +1,7 @@
package com.willfp.ecoenchants.enchants
import com.github.benmanes.caffeine.cache.Caffeine
import com.willfp.eco.core.EcoPlugin
import com.willfp.eco.core.config.ConfigType
import com.willfp.eco.core.config.config
import com.willfp.eco.core.config.interfaces.Config
@ -43,7 +44,7 @@ import java.util.Objects
abstract class EcoEnchant(
val id: String,
configProvider: (EcoEnchant) -> Config,
protected val plugin: EcoEnchantsPlugin
protected val plugin: EcoPlugin
) : Enchantment(NamespacedKey.minecraft(id)), EcoEnchantLike {
final override val config by lazy { configProvider(this) }
override val enchant by lazy { this }
@ -84,19 +85,19 @@ abstract class EcoEnchant(
constructor(
config: Config,
plugin: EcoEnchantsPlugin
plugin: EcoPlugin
) : this(config.getString("id"), { config }, plugin)
constructor(
id: String,
config: Config,
plugin: EcoEnchantsPlugin
plugin: EcoPlugin
) : this(id, { config }, plugin)
@JvmOverloads
constructor(
id: String,
plugin: EcoEnchantsPlugin,
plugin: EcoPlugin,
force: Boolean = true
) : this(
id,
@ -127,10 +128,10 @@ abstract class EcoEnchant(
}
)
conditions = if (plugin.isLoaded) Conditions.compile(
conditions = Conditions.compile(
config.getSubsections("conditions"),
ViolationContext(plugin, "Enchantment $id")
) else emptyConditionList()
)
if (Bukkit.getPluginManager().getPermission("ecoenchants.fromtable.$id") == null) {
val permission = Permission(

View File

@ -0,0 +1,33 @@
package com.willfp.ecoenchants.enchants
import com.willfp.eco.core.EcoPlugin
import com.willfp.libreforge.Holder
import com.willfp.libreforge.conditions.ConditionList
import com.willfp.libreforge.effects.EffectList
import java.util.Objects
class EcoEnchantLevel(
parent: EcoEnchant,
level: Int,
override val effects: EffectList,
override val conditions: ConditionList,
plugin: EcoPlugin
) : Holder {
override val id = plugin.createNamespacedKey("${parent.id}_$level")
override fun equals(other: Any?): Boolean {
if (other !is EcoEnchantLevel) {
return false
}
return this.id == other.id
}
override fun toString(): String {
return id.toString()
}
override fun hashCode(): Int {
return Objects.hash(this.id)
}
}

View File

@ -1,5 +1,6 @@
package com.willfp.ecoenchants.enchants
import com.willfp.eco.core.EcoPlugin
import com.willfp.eco.core.config.interfaces.Config
import com.willfp.ecoenchants.EcoEnchantsPlugin
import com.willfp.libreforge.Holder
@ -14,47 +15,17 @@ import java.util.Objects
class LibReforgeEcoEnchant(
id: String,
config: Config,
plugin: EcoEnchantsPlugin
plugin: EcoPlugin
) : EcoEnchant(
id,
config,
plugin
) {
private val effects: EffectList
init {
effects = if (plugin.isLoaded) Effects.compile(
config.getSubsections("effects"),
ViolationContext(plugin, "Enchantment $id")
) else emptyEffectList()
}
private val effects = Effects.compile(
config.getSubsections("effects"),
ViolationContext(plugin, "Enchantment $id")
)
override fun createLevel(level: Int): EcoEnchantLevel =
EcoEnchantLevel(this, level, effects, conditions, plugin)
}
class EcoEnchantLevel(
parent: EcoEnchant,
level: Int,
override val effects: EffectList,
override val conditions: ConditionList,
plugin: LibreforgePlugin
) : Holder {
override val id = plugin.createNamespacedKey("${parent.id}_$level")
override fun equals(other: Any?): Boolean {
if (other !is EcoEnchantLevel) {
return false
}
return this.id == other.id
}
override fun toString(): String {
return id.toString()
}
override fun hashCode(): Int {
return Objects.hash(this.id)
}
}

View File

@ -1,5 +1,6 @@
package com.willfp.ecoenchants.enchants.impl
import com.willfp.eco.core.EcoPlugin
import com.willfp.ecoenchants.EcoEnchantsPlugin
import com.willfp.ecoenchants.enchants.EcoEnchant
import com.willfp.ecoenchants.target.EnchantLookup.hasEnchantActive
@ -27,7 +28,7 @@ class EnchantmentReplenish(
private class ReplenishHandler(
private val enchant: EcoEnchant,
private val plugin: EcoEnchantsPlugin
private val plugin: EcoPlugin
) : Listener {
@EventHandler(
ignoreCancelled = true

View File

@ -1,5 +1,6 @@
package com.willfp.ecoenchants.enchants.impl
import com.willfp.eco.core.EcoPlugin
import com.willfp.eco.core.data.keys.PersistentDataKey
import com.willfp.eco.core.data.keys.PersistentDataKeyType
import com.willfp.eco.core.data.profile
@ -32,7 +33,7 @@ class EnchantmentSoulbound(
}
private class SoulboundHandler(
private val plugin: EcoEnchantsPlugin,
private val plugin: EcoPlugin,
private val enchant: EcoEnchant
) : Listener {
private val savedSoulboundItems = PersistentDataKey(

View File

@ -1,74 +0,0 @@
package com.willfp.ecoenchants.target
import com.willfp.eco.core.EcoPlugin
import com.willfp.eco.core.events.ArmorChangeEvent
import com.willfp.ecoenchants.target.EnchantLookup.clearEnchantCache
import com.willfp.ecoenchants.target.EnchantmentTargets.isEnchantable
import com.willfp.libreforge.updateEffects
import org.bukkit.entity.Player
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
import org.bukkit.event.entity.EntityPickupItemEvent
import org.bukkit.event.inventory.InventoryClickEvent
import org.bukkit.event.player.PlayerDropItemEvent
import org.bukkit.event.player.PlayerItemHeldEvent
import org.bukkit.event.player.PlayerJoinEvent
@Suppress("UNUSED", "UNUSED_PARAMETER")
class ActiveEnchantUpdateListeners(private val plugin: EcoPlugin) : Listener {
@EventHandler
fun onItemPickup(event: EntityPickupItemEvent) {
if (event.entity !is Player) {
return
}
val player = event.entity as Player
if (!event.item.itemStack.isEnchantable) {
return
}
refreshPlayer(player)
}
@EventHandler
fun onPlayerJoin(event: PlayerJoinEvent) {
refresh()
}
@EventHandler
fun onInventoryDrop(event: PlayerDropItemEvent) {
if (!event.itemDrop.itemStack.isEnchantable) {
return
}
refreshPlayer(event.player)
}
@EventHandler
fun onChangeSlot(event: PlayerItemHeldEvent) {
refreshPlayer(event.player)
plugin.scheduler.run { refreshPlayer(event.player) }
}
@EventHandler
fun onArmorChange(event: ArmorChangeEvent) {
refreshPlayer(event.player)
}
@EventHandler
fun onInventoryClick(event: InventoryClickEvent) {
if (event.whoClicked !is Player) {
return
}
refreshPlayer(event.whoClicked as Player)
}
private fun refresh() {
plugin.server.onlinePlayers.forEach { player: Player -> refreshPlayer(player) }
}
private fun refreshPlayer(player: Player) {
player.clearEnchantCache()
player.updateEffects()
}
}