-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandler.go
40 lines (33 loc) · 1.3 KB
/
handler.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package cooldown
import (
"errors"
"github.com/df-mc/dragonfly/server/event"
)
// Context ...
type Context = event.Context[*CoolDown]
// Handler is interface that implements basic handler of the CoolDown actions.
type Handler interface {
// HandleStart handles start with the ability to cancel it.
HandleStart(ctx *Context)
// HandleRenew handles renew with the ability to cancel it.
HandleRenew(ctx *Context)
// HandleTick handles every tick of the cooldown (variable TicksPerSecond). We can handle every
// second, two seconds or any amount that we want by [tickCount % tps == 0] logic.
HandleTick(cooldown *CoolDown, current int64)
// HandleStop handles stop of the CoolDown, with the specified cause.
HandleStop(cooldown *CoolDown, cause StopCause)
}
// NopHandler is no-operation implementation of Handler.
type NopHandler struct{}
func (NopHandler) HandleStart(*Context) {}
func (NopHandler) HandleRenew(*Context) {}
func (NopHandler) HandleTick(*CoolDown, int64) {}
func (NopHandler) HandleStop(*CoolDown, StopCause) {}
// StopCause ...
type StopCause error
var (
// StopCauseExpired used when cooldown is expired.
StopCauseExpired StopCause = errors.New("expired")
// StopCauseCancelled used when cooldown is cancelled.
StopCauseCancelled StopCause = errors.New("cancelled")
)