-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathevents.go
71 lines (64 loc) · 1.33 KB
/
events.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
64
65
66
67
68
69
70
71
package mcpiapi
import (
"strconv"
"strings"
)
// Events provides methods for getting events.
type Events object
// Block provides methods for getting block events.
type Block object
// Hit contains the information for a block event.
type Hit struct {
PositionX int
PositionY int
PositionZ int
SurfaceX int
SurfaceY int
SurfaceZ int
BlockTypeId int
}
// Block returns the block object.
func (obj Events) Block() Block {
return Block(obj)
}
// Clear clears the event queue.
func (obj Events) Clear() error {
s := "events.clear()"
return object(obj).send(s)
}
// Hits returns the current block events as a slice.
func (obj Block) Hits() (hits []Hit, err error) {
s := "events.block.hits()"
hits = make([]Hit, 0)
var r string
var i int64
r, err = object(obj).sendReceive(s)
if err != nil {
return
}
if r == "" {
return
}
harr := strings.Split(r, "|")
for _, h := range harr {
var hit Hit
arr := strings.Split(h, ",")
arr2 := make([]*int, 7)
arr2[0] = &hit.PositionX
arr2[1] = &hit.PositionY
arr2[2] = &hit.PositionZ
arr2[3] = &hit.SurfaceX
arr2[4] = &hit.SurfaceY
arr2[5] = &hit.SurfaceZ
arr2[6] = &hit.BlockTypeId
for index, rs := range arr {
i, err = strconv.ParseInt(rs, 10, 32)
if err != nil {
return
}
*(arr2[index]) = int(i)
}
hits = append(hits, hit)
}
return
}