A modification-free API for Minecraft utilizing log parsing
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

47 lines
622 B

package rcon
import (
"fmt"
"regexp"
"strconv"
)
var (
timeRegexp = regexp.MustCompile("(\\d+)$")
)
func (r *Session) AddTime(delta int) int {
res, err := r.connection().SendCommand(fmt.Sprintf("time add %d", delta))
if err != nil {
return -1
}
m := timeRegexp.FindStringSubmatch(res)
if m == nil {
return -1
}
ret, _ := strconv.Atoi(m[1])
return ret
}
func (r *Session) GetTime() int {
res, err := r.connection().SendCommand("time query daytime")
if err != nil {
return -1
}
m := timeRegexp.FindStringSubmatch(res)
if m == nil {
return -1
}
v, _ := strconv.Atoi(m[1])
return v
}