Skip to content

Commit

Permalink
libreforge-updater
Browse files Browse the repository at this point in the history
  • Loading branch information
WillFP committed Nov 21, 2023
1 parent a5d08f1 commit 559c70e
Show file tree
Hide file tree
Showing 16 changed files with 84 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ import com.willfp.libreforge.filters.Filters
import com.willfp.libreforge.loader.LibreforgePlugin
import com.willfp.libreforge.loader.configs.ConfigCategory
import com.willfp.libreforge.registerHolderProvider
import com.willfp.libreforge.registerSpecificHolderProvider
import com.willfp.libreforge.triggers.Triggers
import org.bukkit.entity.Player
import org.bukkit.event.Listener

internal lateinit var plugin: EcoSkillsPlugin
Expand All @@ -72,7 +74,7 @@ class EcoSkillsPlugin : LibreforgePlugin() {
}

override fun handleEnable() {
registerHolderProvider { player ->
registerSpecificHolderProvider<Player> { player ->
if (player.isInDisabledWorld) emptyList() else
(Effects.values() union Stats.values())
.mapNotNull { it.getLevelHolder(it.getActualLevel(player)) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ package com.willfp.ecoskills.libreforge
import com.willfp.eco.core.config.interfaces.Config
import com.willfp.ecoskills.api.getMagic
import com.willfp.ecoskills.magic.MagicTypes
import com.willfp.libreforge.Dispatcher
import com.willfp.libreforge.NoCompileData
import com.willfp.libreforge.ProvidedHolder
import com.willfp.libreforge.arguments
import com.willfp.libreforge.conditions.Condition
import com.willfp.libreforge.get
import org.bukkit.entity.Player

object ConditionAboveMagic : Condition<NoCompileData>("above_magic") {
Expand All @@ -14,7 +17,14 @@ object ConditionAboveMagic : Condition<NoCompileData>("above_magic") {
require("amount", "You must specify the amount!")
}

override fun isMet(player: Player, config: Config, compileData: NoCompileData): Boolean {
override fun isMet(
dispatcher: Dispatcher<*>,
config: Config,
holder: ProvidedHolder,
compileData: NoCompileData
): Boolean {
val player = dispatcher.get<Player>() ?: return false

val type = MagicTypes.getByID(config.getString("type").lowercase()) ?: return false

return player.getMagic(type) >= config.getIntFromExpression("amount", player)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ package com.willfp.ecoskills.libreforge
import com.willfp.eco.core.config.interfaces.Config
import com.willfp.ecoskills.api.getMagic
import com.willfp.ecoskills.magic.MagicTypes
import com.willfp.libreforge.Dispatcher
import com.willfp.libreforge.NoCompileData
import com.willfp.libreforge.ProvidedHolder
import com.willfp.libreforge.arguments
import com.willfp.libreforge.conditions.Condition
import com.willfp.libreforge.get
import org.bukkit.entity.Player

object ConditionBelowMagic : Condition<NoCompileData>("below_magic") {
Expand All @@ -14,7 +17,14 @@ object ConditionBelowMagic : Condition<NoCompileData>("below_magic") {
require("amount", "You must specify the amount!")
}

override fun isMet(player: Player, config: Config, compileData: NoCompileData): Boolean {
override fun isMet(
dispatcher: Dispatcher<*>,
config: Config,
holder: ProvidedHolder,
compileData: NoCompileData
): Boolean {
val player = dispatcher.get<Player>() ?: return false

val type = MagicTypes.getByID(config.getString("type").lowercase()) ?: return false

return player.getMagic(type) <= config.getIntFromExpression("amount", player)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ import com.willfp.eco.core.config.interfaces.Config
import com.willfp.ecoskills.api.event.PlayerSkillLevelUpEvent
import com.willfp.ecoskills.api.getSkillLevel
import com.willfp.ecoskills.skills.Skills
import com.willfp.libreforge.Dispatcher
import com.willfp.libreforge.NoCompileData
import com.willfp.libreforge.ProvidedHolder
import com.willfp.libreforge.arguments
import com.willfp.libreforge.conditions.Condition
import com.willfp.libreforge.get
import com.willfp.libreforge.toDispatcher
import com.willfp.libreforge.updateEffects
import org.bukkit.entity.Player
import org.bukkit.event.EventHandler
Expand All @@ -18,14 +22,21 @@ object ConditionHasSkillLevel : Condition<NoCompileData>("has_skill_level") {
require("level", "You must specify the skill level!")
}

override fun isMet(player: Player, config: Config, compileData: NoCompileData): Boolean {
override fun isMet(
dispatcher: Dispatcher<*>,
config: Config,
holder: ProvidedHolder,
compileData: NoCompileData
): Boolean {
val player = dispatcher.get<Player>() ?: return false

val skill = Skills.getByID(config.getString("skill").lowercase()) ?: return false

return player.getSkillLevel(skill) >= config.getIntFromExpression("level", player)
}

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
fun handle(event: PlayerSkillLevelUpEvent) {
event.player.updateEffects()
event.player.toDispatcher().updateEffects()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import com.willfp.ecoskills.api.modifiers.ModifierOperation
import com.willfp.ecoskills.api.modifiers.StatModifier
import com.willfp.ecoskills.api.removeStatModifier
import com.willfp.ecoskills.stats.Stats
import com.willfp.libreforge.Dispatcher
import com.willfp.libreforge.NoCompileData
import com.willfp.libreforge.ProvidedHolder
import com.willfp.libreforge.arguments
import com.willfp.libreforge.effects.Effect
import com.willfp.libreforge.effects.Identifiers
import com.willfp.libreforge.effects.RunOrder
import com.willfp.libreforge.get
import org.bukkit.entity.Player

object EffectAddStat : Effect<NoCompileData>("add_stat") {
Expand All @@ -23,12 +25,14 @@ object EffectAddStat : Effect<NoCompileData>("add_stat") {
}

override fun onEnable(
player: Player,
dispatcher: Dispatcher<*>,
config: Config,
identifiers: Identifiers,
holder: ProvidedHolder,
compileData: NoCompileData
) {
val player = dispatcher.get<Player>() ?: return

val stat = Stats.getByID(config.getString("stat")) ?: return

player.addStatModifier(
Expand All @@ -41,7 +45,9 @@ object EffectAddStat : Effect<NoCompileData>("add_stat") {
)
}

override fun onDisable(player: Player, identifiers: Identifiers, holder: ProvidedHolder) {
override fun onDisable(dispatcher: Dispatcher<*>, identifiers: Identifiers, holder: ProvidedHolder) {
val player = dispatcher.get<Player>() ?: return

player.removeStatModifier(identifiers.uuid)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,24 @@ import com.willfp.ecoskills.magic.magic
import com.willfp.libreforge.ConfigurableElement
import com.willfp.libreforge.NoCompileData
import com.willfp.libreforge.effects.arguments.EffectArgument
import com.willfp.libreforge.get
import com.willfp.libreforge.getIntFromExpression
import com.willfp.libreforge.triggers.DispatchedTrigger
import org.bukkit.entity.Player

class EffectArgumentMagicCost(private val type: MagicType) : EffectArgument<NoCompileData>("${type.id}_cost") {
override fun isMet(element: ConfigurableElement, trigger: DispatchedTrigger, compileData: NoCompileData): Boolean {
val player = trigger.dispatcher.get<Player>() ?: return false

val cost = element.config.getIntFromExpression("${type.id}_cost", trigger.data)
val player = trigger.player

return player.magic[type] >= cost
}

override fun ifMet(element: ConfigurableElement, trigger: DispatchedTrigger, compileData: NoCompileData) {
val player = trigger.dispatcher.get<Player>() ?: return

val cost = element.config.getIntFromExpression("${type.id}_cost", trigger.data)
val player = trigger.player

player.magic[type] -= cost
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.willfp.ecoskills.api.event.PlayerRegenMagicEvent
import com.willfp.ecoskills.magic.MagicType
import com.willfp.ecoskills.magic.MagicTypes
import com.willfp.libreforge.effects.templates.MultiMultiplierEffect
import com.willfp.libreforge.toDispatcher
import org.bukkit.event.EventHandler
import kotlin.math.roundToInt

Expand All @@ -22,6 +23,6 @@ object EffectMagicRegenMultiplier : MultiMultiplierEffect<MagicType>("magic_rege
fun handle(event: PlayerRegenMagicEvent) {
val player = event.player

event.amount *= getMultiplier(player, event.magicType).roundToInt()
event.amount *= getMultiplier(player.toDispatcher(), event.magicType).roundToInt()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import com.willfp.ecoskills.api.modifiers.ModifierOperation
import com.willfp.ecoskills.api.modifiers.StatModifier
import com.willfp.ecoskills.api.removeStatModifier
import com.willfp.ecoskills.stats.Stats
import com.willfp.libreforge.Dispatcher
import com.willfp.libreforge.NoCompileData
import com.willfp.libreforge.ProvidedHolder
import com.willfp.libreforge.arguments
import com.willfp.libreforge.effects.Effect
import com.willfp.libreforge.effects.Identifiers
import com.willfp.libreforge.effects.RunOrder
import com.willfp.libreforge.get
import org.bukkit.entity.Player

object EffectMultiplyAllStats : Effect<NoCompileData>("multiply_all_stats") {
Expand All @@ -22,12 +24,14 @@ object EffectMultiplyAllStats : Effect<NoCompileData>("multiply_all_stats") {
}

override fun onEnable(
player: Player,
dispatcher: Dispatcher<*>,
config: Config,
identifiers: Identifiers,
holder: ProvidedHolder,
compileData: NoCompileData
) {
val player = dispatcher.get<Player>() ?: return

val factory = identifiers.makeFactory()

for ((offset, stat) in Stats.values().withIndex()) {
Expand All @@ -42,7 +46,9 @@ object EffectMultiplyAllStats : Effect<NoCompileData>("multiply_all_stats") {
}
}

override fun onDisable(player: Player, identifiers: Identifiers, holder: ProvidedHolder) {
override fun onDisable(dispatcher: Dispatcher<*>, identifiers: Identifiers, holder: ProvidedHolder) {
val player = dispatcher.get<Player>() ?: return

val factory = identifiers.makeFactory()

for (offset in Stats.values().indices) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import com.willfp.ecoskills.api.modifiers.ModifierOperation
import com.willfp.ecoskills.api.modifiers.StatModifier
import com.willfp.ecoskills.api.removeStatModifier
import com.willfp.ecoskills.stats.Stats
import com.willfp.libreforge.Dispatcher
import com.willfp.libreforge.NoCompileData
import com.willfp.libreforge.ProvidedHolder
import com.willfp.libreforge.arguments
import com.willfp.libreforge.effects.Effect
import com.willfp.libreforge.effects.Identifiers
import com.willfp.libreforge.effects.RunOrder
import com.willfp.libreforge.get
import org.bukkit.entity.Player

object EffectMultiplyStat : Effect<NoCompileData>("multiply_stat") {
Expand All @@ -23,12 +25,13 @@ object EffectMultiplyStat : Effect<NoCompileData>("multiply_stat") {
}

override fun onEnable(
player: Player,
dispatcher: Dispatcher<*>,
config: Config,
identifiers: Identifiers,
holder: ProvidedHolder,
compileData: NoCompileData
) {
val player = dispatcher.get<Player>() ?: return
val stat = Stats.getByID(config.getString("stat")) ?: return

player.addStatModifier(
Expand All @@ -41,7 +44,9 @@ object EffectMultiplyStat : Effect<NoCompileData>("multiply_stat") {
)
}

override fun onDisable(player: Player, identifiers: Identifiers, holder: ProvidedHolder) {
override fun onDisable(dispatcher: Dispatcher<*>, identifiers: Identifiers, holder: ProvidedHolder) {
val player = dispatcher.get<Player>() ?: return

player.removeStatModifier(identifiers.uuid)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.willfp.ecoskills.api.event.PlayerSkillXPGainEvent
import com.willfp.ecoskills.skills.Skill
import com.willfp.ecoskills.skills.Skills
import com.willfp.libreforge.effects.templates.MultiMultiplierEffect
import com.willfp.libreforge.toDispatcher
import org.bukkit.event.EventHandler

object EffectSkillXpMultiplier : MultiMultiplierEffect<Skill>("skill_xp_multiplier") {
Expand All @@ -21,6 +22,6 @@ object EffectSkillXpMultiplier : MultiMultiplierEffect<Skill>("skill_xp_multipli
fun handle(event: PlayerSkillXPGainEvent) {
val player = event.player

event.gainedXP *= getMultiplier(player, event.skill)
event.gainedXP *= getMultiplier(player.toDispatcher(), event.skill)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.willfp.ecoskills.libreforge

import com.willfp.ecoskills.api.event.PlayerSkillXPGainEvent
import com.willfp.libreforge.toDispatcher
import com.willfp.libreforge.triggers.Trigger
import com.willfp.libreforge.triggers.TriggerData
import com.willfp.libreforge.triggers.TriggerParameter
Expand All @@ -18,7 +19,7 @@ object TriggerGainSkillXp : Trigger("gain_skill_xp") {
val player = event.player

this.dispatch(
player,
player.toDispatcher(),
TriggerData(
player = player,
location = player.location,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.willfp.ecoskills.libreforge

import com.willfp.ecoskills.api.event.PlayerSkillLevelUpEvent
import com.willfp.libreforge.toDispatcher
import com.willfp.libreforge.triggers.Trigger
import com.willfp.libreforge.triggers.TriggerData
import com.willfp.libreforge.triggers.TriggerParameter
Expand All @@ -17,7 +18,7 @@ object TriggerLevelUpSkill : Trigger("level_up_skill") {
val player = event.player

this.dispatch(
player,
player.toDispatcher(),
TriggerData(
player = player,
location = player.location,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.willfp.ecoskills.libreforge

import com.willfp.ecoskills.api.event.PlayerRegenMagicEvent
import com.willfp.libreforge.toDispatcher
import com.willfp.libreforge.triggers.Trigger
import com.willfp.libreforge.triggers.TriggerData
import com.willfp.libreforge.triggers.TriggerParameter
Expand All @@ -18,7 +19,7 @@ object TriggerRegenMagic : Trigger("regen_magic") {
val player = event.player

this.dispatch(
player,
player.toDispatcher(),
TriggerData(
player = player,
location = player.location,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import com.willfp.libreforge.ViolationContext
import com.willfp.libreforge.conditions.Conditions
import com.willfp.libreforge.counters.Counters
import com.willfp.libreforge.effects.executors.impl.NormalExecutorFactory
import com.willfp.libreforge.toDispatcher
import com.willfp.libreforge.triggers.DispatchedTrigger
import com.willfp.libreforge.triggers.TriggerData
import org.bukkit.OfflinePlayer
Expand Down Expand Up @@ -257,7 +258,7 @@ class Skill(
// I don't really know a way to clean this up
levelUpEffects?.trigger(
DispatchedTrigger(
player,
player.toDispatcher(),
TriggerLevelUpSkill,
TriggerData(
holder = EmptyProvidedHolder,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.willfp.eco.util.containsIgnoreCase
import com.willfp.ecoskills.api.gainSkillXP
import com.willfp.libreforge.EmptyProvidedHolder
import com.willfp.libreforge.counters.Accumulator
import com.willfp.libreforge.toDispatcher
import org.bukkit.GameMode
import org.bukkit.entity.Player
import java.util.concurrent.TimeUnit
Expand All @@ -29,7 +30,7 @@ class SkillXPAccumulator(
return
}

if (!skill.conditions.areMet(player, EmptyProvidedHolder)) {
if (!skill.conditions.areMet(player.toDispatcher(), EmptyProvidedHolder)) {
return
}

Expand Down
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#libreforge-updater
#Sun Nov 19 14:13:59 GMT 2023
#Tue Nov 21 22:41:15 GMT 2023
kotlin.code.style=official
libreforge-version=4.43.1
version=3.31.1
libreforge-version=4.44.0
version=3.32.0

0 comments on commit 559c70e

Please sign in to comment.