-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandler.go
63 lines (52 loc) · 1.7 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package main
import (
"github.com/df-mc/dragonfly/server/block/cube"
"github.com/df-mc/dragonfly/server/event"
"github.com/df-mc/dragonfly/server/item"
"github.com/df-mc/dragonfly/server/player"
"github.com/df-mc/we"
"github.com/go-gl/mathgl/mgl64"
"github.com/sandertv/gophertunnel/minecraft/text"
)
// Handler is the handler for the player.
type Handler struct {
player.NopHandler
p *player.Player
w *we.Handler
// These are the users selected positions, we can do this since handlers are per player.
Pos1, Pos2 cube.Pos
}
// HandleItemUse ...
func (h *Handler) HandleItemUse(ctx *event.Context) {
h.w.HandleItemUse(ctx)
}
// HandleItemUseOnBlock ...
func (h *Handler) HandleItemUseOnBlock(ctx *event.Context, pos cube.Pos, face cube.Face, vec mgl64.Vec3) {
h.w.HandleItemUseOnBlock(ctx, pos, face, vec)
if held, _ := h.p.HeldItems(); held.Item() == (item.Stick{}) && pos != h.Pos2 {
h.SetPos2(pos)
}
}
// HandleBlockBreak ...
func (h *Handler) HandleBlockBreak(ctx *event.Context, pos cube.Pos, drops *[]item.Stack) {
h.w.HandleBlockBreak(ctx, pos, drops)
if held, _ := h.p.HeldItems(); held.Item() == (item.Stick{}) {
ctx.Cancel()
h.SetPos1(pos)
}
}
// HandleQuit ...
func (h *Handler) HandleQuit() {
h.w.HandleQuit()
}
/* User Functions ------------------------------ BELOW --------------------------------------- User Functions */
// SetPos1 sets the first position saved for the player.
func (h *Handler) SetPos1(p cube.Pos) {
h.Pos1 = p
h.p.Message(text.Colourf("<green>Pos1 has been set to %v</green>", p))
}
// SetPos2 sets the second position saved for the player.
func (h *Handler) SetPos2(p cube.Pos) {
h.Pos2 = p
h.p.Message(text.Colourf("<green>Pos2 has been set to %v</green>", p))
}