-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
46 lines (39 loc) · 1.24 KB
/
Copy pathmain.go
File metadata and controls
46 lines (39 loc) · 1.24 KB
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
// Package main demonstrates event handling using the current API.
// Build with: CGO_ENABLED=1 go build -buildmode=plugin -o events.so .
package main
import (
"context"
"fmt"
"github.com/ompgo-dev/ompgo/pkg/omp"
"github.com/ompgo-dev/ompgo/pkg/omp/core"
"github.com/ompgo-dev/ompgo/pkg/omp/players"
"github.com/ompgo-dev/ompgo/pkg/runtime"
)
type EventsGamemode struct {
omp.BaseEventHandler
}
func (g *EventsGamemode) OnLoad(ctx context.Context) error {
_ = core.Log("[Events] Gamemode loaded")
return nil
}
func (g *EventsGamemode) OnPlayerConnect(ctx context.Context, event *omp.PlayerConnectEvent) error {
if event.Player == nil || !event.Player.Valid() {
return nil
}
name, _ := players.GetName(event.Player)
_ = players.SendClientMessage(event.Player, uint32(omp.ColorGreen), fmt.Sprintf("Welcome, %s!", name))
return nil
}
func (g *EventsGamemode) OnPlayerCommandText(ctx context.Context, event *omp.PlayerCommandTextEvent) (bool, error) {
if event.Player == nil || !event.Player.Valid() {
return false, nil
}
if event.Command.EqualString("/ping") {
_ = players.SendClientMessage(event.Player, uint32(omp.ColorYellow), "pong")
return true, nil
}
return false, nil
}
func NewGamemode() runtime.Gamemode {
return &EventsGamemode{}
}