residentsleeper/scripting/minecraft/ops.go
Tyler b52b38179a
Some checks failed
continuous-integration/drone/push Build is failing
Major updates/patches, functionality, api
2020-07-09 21:01:29 -04:00

70 lines
1.1 KiB
Go

package minecraft
import (
"encoding/json"
"github.com/yuin/gopher-lua"
"meow.tf/residentsleeper/events"
"os"
"path"
)
var (
ops = make([]*minecraftOp, 0)
)
func init() {
events.On(events.Init, loadOps)
events.On(events.Op, oppedPlayer)
events.On(events.Deop, deoppedPlayer)
}
type minecraftOp struct {
UUID string `json:"uuid"`
Name string `json:"name"`
Level int `json:"level"`
BypassesPlayerLimit bool `json:"bypassesPlayerLimit"`
}
func loadOps(args ...interface{}) {
opPath := path.Join(BasePath, "ops.json")
f, err := os.Open(opPath)
if err != nil {
return
}
defer f.Close()
ops = make([]*minecraftOp, 0)
if err = json.NewDecoder(f).Decode(&ops); err != nil {
return
}
}
func oppedPlayer(args ...interface{}) {
loadOps()
}
func deoppedPlayer(args ...interface{}) {
loadOps()
}
func IsOp(name string) bool {
for _, op := range ops {
if op.Name == name {
return true
}
}
return false
}
func isOpFunc(L *lua.LState) int {
name := L.CheckString(1)
L.Push(lua.LBool(IsOp(name)))
return 1
}