-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
58 lines (50 loc) · 1.02 KB
/
main.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
package main
import (
"bufio"
"obsidian/log"
"obsidian/server"
"obsidian/server/command"
"obsidian/server/command/core"
"os"
"os/signal"
"strings"
"time"
)
var startTime = time.Now()
func main() {
log.Info("Starting Obsidian 0.30 Minecraft Server")
cfg, _ := server.LoadConfig()
srv := cfg.New()
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
go func() {
<-c
log.Info("Stopping server")
srv.Stop()
}()
go scanConsole(srv)
srv.Start(startTime)
}
func scanConsole(srv *server.Server) {
scanner := bufio.NewScanner(os.Stdin)
for {
scanner.Scan()
cmd := scanner.Text()
if cmd == "" {
continue
}
args := strings.Split(cmd, " ")
cmd = args[0]
args = args[1:]
c, ok := core.Manager.Search(cmd)
if !ok {
log.Print("&cUnknown command. Use \"/help\" for a list of commands.")
continue
}
if c.PlayerOnly {
log.Print("&cThis command can only be used by players.")
continue
}
c.Execute(command.CommandContext{Arguments: args, Executor: srv, Manager: core.Manager})
}
}