mirror of
https://github.com/Auxilor/EcoEnchants.git
synced 2024-11-25 15:35:11 +01:00
Lots of updating
This commit is contained in:
parent
a24b118dba
commit
77aedf8c81
@ -23,10 +23,13 @@ import com.willfp.ecoenchants.mechanics.LootSupport
|
||||
import com.willfp.ecoenchants.mechanics.VillagerSupport
|
||||
import com.willfp.ecoenchants.target.EnchantLookup.clearEnchantCache
|
||||
import com.willfp.ecoenchants.target.EnchantLookup.heldEnchantLevels
|
||||
import com.willfp.ecoenchants.type.EnchantmentTypes
|
||||
import com.willfp.libreforge.integrations.ecoenchants.impl.TriggerEnchantType
|
||||
import com.willfp.libreforge.loader.LibreforgePlugin
|
||||
import com.willfp.libreforge.loader.configs.ConfigCategory
|
||||
import com.willfp.libreforge.registerHolderProvider
|
||||
import com.willfp.libreforge.registerPlayerRefreshFunction
|
||||
import com.willfp.libreforge.triggers.Triggers
|
||||
import org.bukkit.event.Listener
|
||||
|
||||
class EcoEnchantsPlugin : LibreforgePlugin() {
|
||||
|
@ -36,7 +36,7 @@ class CommandGiveRandomBook(plugin: EcoPlugin) : PluginCommand(
|
||||
val filterName = args.getOrNull(1)
|
||||
|
||||
val filter = if (filterName != null) {
|
||||
EnchantmentTypes.getByID(filterName) ?: EnchantmentRarities.getByID(filterName)
|
||||
EnchantmentTypes[filterName] ?: EnchantmentRarities[filterName]
|
||||
} else null
|
||||
|
||||
val minLevel = args.getOrNull(2)?.toIntOrNull() ?: 1
|
||||
|
@ -62,7 +62,7 @@ object TypeSorter : EnchantmentSorter {
|
||||
fun update(plugin: EcoEnchantsPlugin) {
|
||||
types.clear()
|
||||
types.addAll(plugin.configYml.getStrings("display.sort.type-order").mapNotNull {
|
||||
EnchantmentTypes.getByID(it)
|
||||
EnchantmentTypes[it]
|
||||
})
|
||||
}
|
||||
|
||||
@ -91,7 +91,7 @@ object RaritySorter : EnchantmentSorter {
|
||||
fun update(plugin: EcoEnchantsPlugin) {
|
||||
rarities.clear()
|
||||
rarities.addAll(plugin.configYml.getStrings("display.sort.rarity-order").mapNotNull {
|
||||
EnchantmentRarities.getByID(it)
|
||||
EnchantmentRarities[it]
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -58,15 +58,15 @@ abstract class EcoEnchant(
|
||||
val conditions: ConditionList
|
||||
|
||||
val targets = config.getStrings("targets")
|
||||
.mapNotNull { EnchantmentTargets.getByID(it) }
|
||||
.mapNotNull { EnchantmentTargets[it] }
|
||||
|
||||
val slots: Set<TargetSlot>
|
||||
get() = targets.map { it.slot }.toSet()
|
||||
|
||||
override val type = EnchantmentTypes.getByID(config.getString("type")) ?: EnchantmentTypes.values().first()
|
||||
override val type = EnchantmentTypes[config.getString("type")] ?: EnchantmentTypes.values().first()
|
||||
|
||||
override val enchantmentRarity =
|
||||
EnchantmentRarities.getByID(config.getString("rarity")) ?: EnchantmentRarities.values().first()
|
||||
EnchantmentRarities[config.getString("rarity")] ?: EnchantmentRarities.values().first()
|
||||
|
||||
private val conflictNames = config.getStrings("conflicts")
|
||||
|
||||
|
@ -104,11 +104,11 @@ class VanillaEcoEnchantLike(
|
||||
override val config = plugin.vanillaEnchantsYml.getSubsection(enchant.key.key)
|
||||
|
||||
override val type: EnchantmentType =
|
||||
EnchantmentTypes.getByID(plugin.vanillaEnchantsYml.getString("${enchant.key.key}.type"))
|
||||
EnchantmentTypes[plugin.vanillaEnchantsYml.getString("${enchant.key.key}.type")]
|
||||
?: EnchantmentTypes.values().first()
|
||||
|
||||
override val enchantmentRarity: EnchantmentRarity =
|
||||
EnchantmentRarities.getByID(plugin.vanillaEnchantsYml.getString("${enchant.key.key}.rarity"))
|
||||
EnchantmentRarities[plugin.vanillaEnchantsYml.getString("${enchant.key.key}.rarity")]
|
||||
?: EnchantmentRarities.values().first()
|
||||
|
||||
override val displayName = plugin.vanillaEnchantsYml.getFormattedString("${enchant.key.key}.name")
|
||||
|
@ -0,0 +1,45 @@
|
||||
package com.willfp.ecoenchants.libreforge
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin
|
||||
import com.willfp.eco.core.fast.fast
|
||||
import com.willfp.ecoenchants.enchants.EcoEnchant
|
||||
import com.willfp.libreforge.triggers.Trigger
|
||||
import com.willfp.libreforge.triggers.TriggerData
|
||||
import com.willfp.libreforge.triggers.TriggerParameter
|
||||
import org.bukkit.event.EventHandler
|
||||
import org.bukkit.event.EventPriority
|
||||
import org.bukkit.event.enchantment.EnchantItemEvent
|
||||
|
||||
class TriggerEnchantType(
|
||||
private val plugin: EcoPlugin,
|
||||
private val type: String
|
||||
) : Trigger("enchant_$type") {
|
||||
override val parameters = setOf(
|
||||
TriggerParameter.PLAYER,
|
||||
TriggerParameter.LOCATION,
|
||||
TriggerParameter.ITEM
|
||||
)
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
fun handleLevelling(event: EnchantItemEvent) {
|
||||
val player = event.enchanter
|
||||
|
||||
plugin.scheduler.runLater({
|
||||
if (
|
||||
event.item.fast().getEnchants(true).keys
|
||||
.filterIsInstance<EcoEnchant>()
|
||||
.any { it.type.id.equals(type, ignoreCase = true) }
|
||||
) {
|
||||
this.dispatch(
|
||||
player,
|
||||
TriggerData(
|
||||
player = player,
|
||||
location = player.location,
|
||||
item = event.item,
|
||||
value = event.expLevelCost.toDouble()
|
||||
)
|
||||
)
|
||||
}
|
||||
}, 2)
|
||||
}
|
||||
}
|
@ -1,82 +1,16 @@
|
||||
package com.willfp.ecoenchants.rarity
|
||||
|
||||
import com.google.common.collect.HashBiMap
|
||||
import com.google.common.collect.ImmutableSet
|
||||
import com.willfp.eco.core.config.updating.ConfigUpdater
|
||||
import com.willfp.eco.core.registry.Registry
|
||||
import com.willfp.ecoenchants.EcoEnchantsPlugin
|
||||
import com.willfp.ecoenchants.enchants.EcoEnchants
|
||||
|
||||
@Suppress("UNUSED")
|
||||
object EnchantmentRarities {
|
||||
private val BY_ID = HashBiMap.create<String, EnchantmentRarity>()
|
||||
|
||||
/**
|
||||
* Get all registered [EnchantmentRarity]s.
|
||||
*
|
||||
* @return A list of all [EnchantmentRarity]s.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun values(): Set<EnchantmentRarity> {
|
||||
return ImmutableSet.copyOf(BY_ID.values)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get [String]s for all registered [EnchantmentRarity]s.
|
||||
*
|
||||
* @return A list of all [EnchantmentRarity]s.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun keySet(): Set<String> {
|
||||
return ImmutableSet.copyOf(BY_ID.keys)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get [EnchantmentRarity] matching key.
|
||||
*
|
||||
* @param id The key to search for.
|
||||
* @return The matching [EnchantmentRarity], or null if not found.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun getByID(id: String?): EnchantmentRarity? {
|
||||
return if (id == null) {
|
||||
null
|
||||
} else BY_ID[id]
|
||||
}
|
||||
|
||||
/**
|
||||
* Update all [EnchantmentRarity]s.
|
||||
*
|
||||
* @param plugin Instance of EcoEnchants.
|
||||
*/
|
||||
object EnchantmentRarities : Registry<EnchantmentRarity>() {
|
||||
@JvmStatic
|
||||
fun update(plugin: EcoEnchantsPlugin) {
|
||||
for (type in values()) {
|
||||
removeRarity(type)
|
||||
}
|
||||
clear()
|
||||
|
||||
for (config in plugin.rarityYml.getSubsections("rarities")) {
|
||||
EnchantmentRarity(config)
|
||||
register(EnchantmentRarity(config))
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove [EnchantmentRarity] from EcoEnchants.
|
||||
*
|
||||
* @param rarity The [EnchantmentRarity] to remove.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun removeRarity(rarity: EnchantmentRarity) {
|
||||
BY_ID.remove(rarity.id)
|
||||
}
|
||||
|
||||
/**
|
||||
* Add new [EnchantmentRarity] to EcoEnchants.
|
||||
*
|
||||
* Only for internal use, rarities are automatically added in the constructor.
|
||||
*
|
||||
* @param rarity The [EnchantmentRarity] to add.
|
||||
*/
|
||||
internal fun addNewRarity(rarity: EnchantmentRarity) {
|
||||
BY_ID.remove(rarity.id)
|
||||
BY_ID[rarity.id] = rarity
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,13 @@
|
||||
package com.willfp.ecoenchants.rarity
|
||||
|
||||
import com.willfp.eco.core.config.interfaces.Config
|
||||
import com.willfp.eco.core.registry.Registrable
|
||||
import java.util.*
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
class EnchantmentRarity(
|
||||
internal val config: Config
|
||||
) {
|
||||
) : Registrable {
|
||||
val id = config.getString("id")
|
||||
val displayName = config.getFormattedString("display-name")
|
||||
val tableChance = config.getDouble("table-chance")
|
||||
@ -14,8 +15,8 @@ class EnchantmentRarity(
|
||||
val villagerChance = config.getDouble("villager-chance")
|
||||
val lootChance = config.getDouble("loot-chance")
|
||||
|
||||
init {
|
||||
EnchantmentRarities.addNewRarity(this)
|
||||
override fun getID(): String {
|
||||
return id
|
||||
}
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
|
@ -4,12 +4,13 @@ import com.willfp.eco.core.config.interfaces.Config
|
||||
import com.willfp.eco.core.items.Items
|
||||
import com.willfp.eco.core.items.TestableItem
|
||||
import com.willfp.eco.core.recipe.parts.EmptyTestableItem
|
||||
import com.willfp.eco.core.registry.Registrable
|
||||
import com.willfp.ecoenchants.EcoEnchantsPlugin
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.inventory.ItemStack
|
||||
import java.util.Objects
|
||||
|
||||
interface EnchantmentTarget {
|
||||
interface EnchantmentTarget : Registrable {
|
||||
val id: String
|
||||
val displayName: String
|
||||
val slot: TargetSlot
|
||||
@ -23,6 +24,10 @@ interface EnchantmentTarget {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
override fun getID(): String {
|
||||
return this.id
|
||||
}
|
||||
}
|
||||
|
||||
class ConfiguredEnchantmentTarget(
|
||||
@ -37,10 +42,6 @@ class ConfiguredEnchantmentTarget(
|
||||
.map { Items.lookup(it) }
|
||||
.filterNot { it is EmptyTestableItem }
|
||||
|
||||
init {
|
||||
EnchantmentTargets.addNewTarget(this)
|
||||
}
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (other !is EnchantmentTarget) {
|
||||
return false
|
||||
|
@ -3,6 +3,7 @@ package com.willfp.ecoenchants.target
|
||||
import com.github.benmanes.caffeine.cache.Caffeine
|
||||
import com.google.common.collect.ImmutableSet
|
||||
import com.willfp.eco.core.items.HashedItem
|
||||
import com.willfp.eco.core.registry.Registry
|
||||
import com.willfp.ecoenchants.EcoEnchantsPlugin
|
||||
import com.willfp.ecoenchants.enchants.EcoEnchant
|
||||
import com.willfp.ecoenchants.enchants.EcoEnchants
|
||||
@ -12,34 +13,14 @@ import org.bukkit.enchantments.Enchantment
|
||||
import org.bukkit.inventory.ItemStack
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
object EnchantmentTargets {
|
||||
private val BY_ID = mutableMapOf<String, EnchantmentTarget>()
|
||||
|
||||
object EnchantmentTargets: Registry<EnchantmentTarget>() {
|
||||
init {
|
||||
BY_ID["all"] = AllEnchantmentTarget
|
||||
register(AllEnchantmentTarget)
|
||||
update(EcoEnchantsPlugin.instance)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get EnchantTarget matching name.
|
||||
*
|
||||
* @param name The name to search for.
|
||||
* @return The matching EnchantTarget, or null if not found.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun getByID(name: String): EnchantmentTarget? {
|
||||
return BY_ID[name]
|
||||
}
|
||||
|
||||
/**
|
||||
* Get target from item.
|
||||
*
|
||||
* @param item The item.
|
||||
* @return The target.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun getForItem(item: ItemStack): List<EnchantmentTarget> {
|
||||
return BY_ID.values
|
||||
private fun getForItem(item: ItemStack): List<EnchantmentTarget> {
|
||||
return values()
|
||||
.filter { !it.id.equals("all", ignoreCase = true) }
|
||||
.filter { it.matches(item) }
|
||||
}
|
||||
@ -54,54 +35,21 @@ object EnchantmentTargets {
|
||||
EcoEnchants.values().filter { it.canEnchantItem(this) }
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all targets.
|
||||
*
|
||||
* @return A set of all targets.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun values(): Set<EnchantmentTarget> {
|
||||
return ImmutableSet.copyOf(BY_ID.values)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun update(plugin: EcoEnchantsPlugin) {
|
||||
for (target in values()) {
|
||||
if (target is AllEnchantmentTarget) {
|
||||
continue
|
||||
}
|
||||
removeTarget(target)
|
||||
remove(target)
|
||||
}
|
||||
|
||||
for (config in plugin.targetsYml.getSubsections("targets")) {
|
||||
ConfiguredEnchantmentTarget(config)
|
||||
register(ConfiguredEnchantmentTarget(config))
|
||||
}
|
||||
|
||||
AllEnchantmentTarget.updateItems()
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove [EnchantmentTarget] from EcoEnchants.
|
||||
*
|
||||
* @param target The [EnchantmentTarget] to remove.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun removeTarget(target: EnchantmentTarget) {
|
||||
BY_ID.remove(target.id)
|
||||
}
|
||||
|
||||
/**
|
||||
* Add new [EnchantmentTarget] to EcoEnchants.
|
||||
*
|
||||
* Only for internal use, targets are automatically added in the
|
||||
* constructor.
|
||||
*
|
||||
* @param target The [EnchantmentTarget] to add.
|
||||
*/
|
||||
internal fun addNewTarget(target: EnchantmentTarget) {
|
||||
BY_ID.remove(target.id)
|
||||
BY_ID[target.id] = target
|
||||
}
|
||||
}
|
||||
|
||||
private val enchantableCache = Caffeine.newBuilder()
|
||||
|
@ -1,23 +1,23 @@
|
||||
package com.willfp.ecoenchants.type
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin
|
||||
import com.willfp.eco.core.config.interfaces.Config
|
||||
import com.willfp.eco.core.registry.Registrable
|
||||
import com.willfp.ecoenchants.libreforge.TriggerEnchantType
|
||||
import com.willfp.ecoenchants.mechanics.infiniteIfNegative
|
||||
import com.willfp.libreforge.triggers.Triggers
|
||||
import java.util.*
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
class EnchantmentType(
|
||||
private val plugin: EcoPlugin,
|
||||
internal val config: Config
|
||||
) {
|
||||
): Registrable {
|
||||
val id = config.getString("id")
|
||||
val format = config.getString("format")
|
||||
val limit = config.getInt("limit").infiniteIfNegative()
|
||||
val highLevelBias = config.getDouble("high-level-bias")
|
||||
val noGrindstone = config.getBool("no-grindstone")
|
||||
|
||||
init {
|
||||
EnchantmentTypes.addNewType(this)
|
||||
}
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) {
|
||||
return true
|
||||
@ -30,6 +30,14 @@ class EnchantmentType(
|
||||
return other.id == this.id
|
||||
}
|
||||
|
||||
override fun onRegister() {
|
||||
Triggers.register(TriggerEnchantType(plugin, this.id))
|
||||
}
|
||||
|
||||
override fun getID(): String {
|
||||
return this.id
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
return Objects.hash(id)
|
||||
}
|
||||
|
@ -1,84 +1,22 @@
|
||||
package com.willfp.ecoenchants.type
|
||||
|
||||
import com.google.common.collect.HashBiMap
|
||||
import com.google.common.collect.ImmutableSet
|
||||
import com.willfp.eco.core.config.updating.ConfigUpdater
|
||||
import com.willfp.eco.core.registry.Registry
|
||||
import com.willfp.ecoenchants.EcoEnchantsPlugin
|
||||
import com.willfp.ecoenchants.enchants.EcoEnchants
|
||||
import com.willfp.ecoenchants.rarity.EnchantmentRarities
|
||||
import com.willfp.ecoenchants.target.EnchantmentTargets
|
||||
|
||||
@Suppress("UNUSED")
|
||||
object EnchantmentTypes {
|
||||
private val BY_ID = HashBiMap.create<String, EnchantmentType>()
|
||||
|
||||
/**
|
||||
* Get all registered [EnchantmentType]s.
|
||||
*
|
||||
* @return A list of all [EnchantmentType]s.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun values(): Set<EnchantmentType> {
|
||||
return ImmutableSet.copyOf(BY_ID.values)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get [String]s for all registered [EnchantmentType]s.
|
||||
*
|
||||
* @return A list of all [EnchantmentType]s.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun keySet(): Set<String> {
|
||||
return ImmutableSet.copyOf(BY_ID.keys)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get [EnchantmentType] matching key.
|
||||
*
|
||||
* @param id The key to search for.
|
||||
* @return The matching [EnchantmentType], or null if not found.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun getByID(id: String?): EnchantmentType? {
|
||||
return if (id == null) {
|
||||
null
|
||||
} else BY_ID[id]
|
||||
}
|
||||
|
||||
object EnchantmentTypes: Registry<EnchantmentType>() {
|
||||
/**
|
||||
* Update all [EnchantmentType]s.
|
||||
*
|
||||
* @param plugin Instance of EcoEnchants.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun update(plugin: EcoEnchantsPlugin) {
|
||||
for (type in values()) {
|
||||
removeType(type)
|
||||
clear()
|
||||
}
|
||||
|
||||
for (config in plugin.typesYml.getSubsections("types")) {
|
||||
EnchantmentType(config)
|
||||
register(EnchantmentType(plugin, config))
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove [EnchantmentType] from EcoEnchants.
|
||||
*
|
||||
* @param type The [EnchantmentType] to remove.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun removeType(type: EnchantmentType) {
|
||||
BY_ID.remove(type.id)
|
||||
}
|
||||
|
||||
/**
|
||||
* Add new [EnchantmentType] to EcoEnchants.
|
||||
*
|
||||
* Only for internal use, types are automatically added in the constructor.
|
||||
*
|
||||
* @param type The [EnchantmentType] to add.
|
||||
*/
|
||||
internal fun addNewType(type: EnchantmentType) {
|
||||
BY_ID.remove(type.id)
|
||||
BY_ID[type.id] = type
|
||||
}
|
||||
}
|
||||
|
@ -36,8 +36,6 @@ permissions:
|
||||
ecoenchants.command.giverandombook: true
|
||||
ecoenchants.command.enchantinfo: true
|
||||
ecoenchants.command.gui: true
|
||||
ecoenchants.command.import: true
|
||||
ecoenchants.command.export: true
|
||||
ecoenchants.anvil.*:
|
||||
description: All anvil perks
|
||||
default: op
|
||||
@ -64,10 +62,4 @@ permissions:
|
||||
default: true
|
||||
ecoenchants.command.gui:
|
||||
description: Allows the use of /ecoenchants gui.
|
||||
default: true
|
||||
ecoenchants.command.import:
|
||||
description: Allows the use of /ecoenchants import.
|
||||
default: op
|
||||
ecoenchants.command.export:
|
||||
description: Allows the use of /ecoenchants export.
|
||||
default: op
|
||||
default: true
|
@ -1,5 +1,5 @@
|
||||
#libreforge-updater
|
||||
#Mon Mar 13 13:39:16 GMT 2023
|
||||
#Tue Mar 28 18:28:43 BST 2023
|
||||
kotlin.code.style=official
|
||||
libreforge-version=4.0.0
|
||||
version=10.0.0
|
||||
|
Loading…
Reference in New Issue
Block a user