spiglin
spiglin copied to clipboard
Implement repeating function with expectations
A simple way to run an action every 1 * [specified time unit] when declaring an expectation. This can be used to simplify the creation of countdowns.
I'm not sure I fully understand. Could you give an example of the expected behaviour and what it could look like in code?
Maybe something like this:
plugin.expect<PlayerMoveEvent>(
predicate = { it.player == player },
timeout = 5,
timeoutUnit = TimeUnit.SECONDS,
timeoutAction = { player.teleport(location) },
repeatingAction = { player.sendMessage("Timeout in " + leftTimeout + " seconds.") },
action = { player.sendMessage("You moved!") }
)
I see. This could grow rather complex though, because You certainly do not want to execute such an action every time unit in all use cases. I'm not really happy with the "expectation"-mechanics anyway - I might consider rewriting it to be more flexible.