Skip to content

Commit

Permalink
Unused triggers will no longer be dispatched
Browse files Browse the repository at this point in the history
  • Loading branch information
WillFP committed May 24, 2023
1 parent ebce265 commit addb36c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ class DispatchedTriggerFactory(
private val playerTriggers = listMap<UUID, Int>()

fun create(player: Player, trigger: Trigger, data: TriggerData): DispatchedTrigger? {
if (!trigger.isEnabled) {
return null
}

val hash = (trigger.hashCode() shl 5) xor data.hashCode()
if (hash in playerTriggers[player.uniqueId]) {
return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ abstract class Trigger(
*/
abstract val parameters: Set<TriggerParameter>

/**
* Whether this trigger is enabled.
*/
var isEnabled: Boolean = false
internal set

/**
* Dispatch the trigger.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,16 @@ object Triggers : Registry<Trigger>() {

/**
* Get a trigger by [id].
*
* This will enable the trigger.
*/
override fun get(id: String): Trigger? {
return doGet(id)?.apply {
isEnabled = true
}
}

private fun doGet(id: String): Trigger? {
for (group in groupRegistry.values()) {
if (id.startsWith("${group.prefix}_")) {
return group.create(id.removePrefix("${group.prefix}_"))
Expand Down

0 comments on commit addb36c

Please sign in to comment.