Added requirements and refined existing features

This commit is contained in:
Auxilor
2024-07-05 16:06:34 +01:00
parent 2f9516a599
commit db78526c61
7 changed files with 66 additions and 21 deletions

View File

@@ -11,6 +11,7 @@ import com.willfp.libreforge.toDispatcher
import com.willfp.libreforge.triggers.TriggerData
import org.bukkit.entity.Player
import org.bukkit.inventory.ItemStack
import sun.jvm.hotspot.oops.CellTypeState.value
class InscriptionHandler(private val plugin: EcoScrollsPlugin) {
private val context = ViolationContext(plugin, "Inscriptions")
@@ -41,7 +42,8 @@ class InscriptionHandler(private val plugin: EcoScrollsPlugin) {
TriggerData(
player = player,
item = item,
text = scroll.name
text = scroll.name,
value = item.getScrollLevel(scroll)?.level?.toDouble() ?: 1.0
).dispatch(player.toDispatcher())
.apply {
addPlaceholder(
@@ -56,6 +58,12 @@ class InscriptionHandler(private val plugin: EcoScrollsPlugin) {
scroll.id
)
)
addPlaceholder(
NamedValue(
"level",
item.getScrollLevel(scroll)?.level?.toString() ?: "1"
)
)
}
fun tryInscribe(item: ItemStack, scroll: Scroll, player: Player): Boolean {

View File

@@ -4,19 +4,15 @@ import com.willfp.eco.core.config.interfaces.Config
import com.willfp.eco.core.display.Display
import com.willfp.eco.core.fast.FastItemStack
import com.willfp.eco.core.fast.fast
import com.willfp.eco.core.integrations.placeholder.PlaceholderManager
import com.willfp.eco.core.items.Items
import com.willfp.eco.core.placeholder.InjectablePlaceholder
import com.willfp.eco.core.placeholder.PlaceholderInjectable
import com.willfp.eco.core.placeholder.context.PlaceholderContext
import com.willfp.eco.core.placeholder.context.placeholderContext
import com.willfp.eco.core.placeholder.templates.DynamicInjectablePlaceholder
import com.willfp.eco.core.placeholder.templates.DynamicPlaceholder
import com.willfp.eco.core.price.ConfiguredPrice
import com.willfp.eco.core.recipe.Recipes
import com.willfp.eco.core.registry.KRegistrable
import com.willfp.eco.util.evaluateExpression
import com.willfp.eco.util.evaluateExpressionOrNull
import com.willfp.eco.util.formatEco
import com.willfp.ecoscrolls.EcoScrollsPlugin
import com.willfp.ecoscrolls.plugin
@@ -30,7 +26,6 @@ import org.bukkit.entity.Player
import org.bukkit.inventory.ItemStack
import java.util.Objects
import java.util.regex.Pattern
import kotlin.math.exp
class Scroll(
plugin: EcoScrollsPlugin,
@@ -82,6 +77,16 @@ class Scroll(
private val conflicts = config.getStrings("conflicts")
private val requirements = config.getSubsections("requirements")
.map {
ScrollRequirement(
it.getString("scroll"),
it.getIntOrNull("level")
)
}
val removeRequirements = config.getBool("remove-requirements")
val inscriptionConditions = Conditions.compile(
config.getSubsections("inscription.conditions"),
context.with("inscription conditions")
@@ -92,7 +97,7 @@ class Scroll(
context.with("inscription effects")
)
val inscriptionPrice = ConfiguredPrice.create(
val inscriptionPrice = ConfiguredPrice.createOrFree(
config.getSubsection("inscription.price"),
)
@@ -149,6 +154,10 @@ class Scroll(
return false
}
if (requirements.any { !it.isPresent(itemStack) }) {
return false
}
val level = itemStack.getScrollLevel(this)?.level ?: 0
if (level >= maxLevel) {
@@ -173,20 +182,19 @@ class Scroll(
return false
}
if (inscriptionPrice != null) {
if (!inscriptionPrice.canAfford(player)) {
return false
}
inscriptionPrice.pay(player)
if (!inscriptionPrice.canAfford(player)) {
return false
}
inscriptionPrice.pay(player)
inscribe(itemStack)
inscriptionEffects.trigger(
TriggerData(
player = player,
item = itemStack
item = itemStack,
value = itemStack.getScrollLevel(this)?.level?.toDouble() ?: 1.0
).dispatch(player.toDispatcher())
)
@@ -198,7 +206,16 @@ class Scroll(
val next = current + 1
val level = this.getLevel(next)
itemStack.scrolls = itemStack.scrolls.filter { it.scroll != this }.toSet() + level
var scrolls = itemStack.scrolls.filter { it.scroll != this }.toSet() + level
if (removeRequirements) {
scrolls = scrolls.filter { scroll ->
!requirements.any { it.scrollId == scroll.scroll.id }
}.toSet()
}
itemStack.scrolls = scrolls
}
fun getLore(itemStack: ItemStack, player: Player?): List<String> {

View File

@@ -0,0 +1,14 @@
package com.willfp.ecoscrolls.scrolls
import org.bukkit.inventory.ItemStack
class ScrollRequirement(
val scrollId: String,
private val level: Int?
) {
fun isPresent(itemStack: ItemStack): Boolean {
val scroll = Scrolls[scrollId] ?: return false
return (itemStack.getScrollLevel(scroll)?.level ?: 0) >= (level ?: 1)
}
}

View File

@@ -109,13 +109,11 @@ inscription:
# Effects to run when an item is inscribed
# The text placeholder is the name of the scroll, read here:
# https://plugins.auxilor.io/effects/configuring-an-effect#placeholders
# You can also use %scroll% and %scroll_id% as placeholders.
# You can also use %scroll%, %scroll_id%, and %level% as placeholders.
apply-effects: [ ]
# Effects to run when trying to inscribe an item without meeting the conditions
# The text placeholder is the name of the scroll, read here:
# https://plugins.auxilor.io/effects/configuring-an-effect#placeholders
# You can also use %scroll% and %scroll_id% as placeholders.
# Same placeholders as apply-effects
deny-effects: [ ]
# The maximum amount of scrolls that can be applied to an item

View File

@@ -3,6 +3,6 @@ environment:
value: ${libreforgeVersion}
options:
resource-id: 2873
resource-id: 0
bstats-id: 22538
color: "&#1e3c72"

View File

@@ -49,13 +49,21 @@ targets:
# The conflicts that the scroll has with other scrolls
conflicts: [ ]
# The scroll(s) that must be applied to the item before this scroll can be applied
requirements:
- scroll: my_requirement_scroll # The scroll to require
level: 2 # The level required (optional)
# If inscribing this scroll should remove the required scrolls
remove-requirements: false
# The lore added to items when inscribed with the scroll
lore:
- ""
- "&7This item has been inscribed with"
- "&6Example Scroll"
# Item placeholders, can be used in other plugins.
# Item placeholders for dynamic lore in plugins like EcoItems
# The placeholder is %ecoscrolls_scroll_<scroll>_<placeholder>%
placeholders:
bonus: "%level% * 2"