-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
60 lines (48 loc) · 1.31 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
59
60
package main
import (
"log/slog"
"time"
"github.com/bedrock-gophers/intercept/intercept"
"github.com/bedrock-gophers/knockback/knockback"
"github.com/df-mc/dragonfly/server"
"github.com/df-mc/dragonfly/server/cmd"
"github.com/df-mc/dragonfly/server/player"
"github.com/df-mc/dragonfly/server/player/chat"
"github.com/df-mc/dragonfly/server/world"
"github.com/sirupsen/logrus"
)
func main() {
err := knockback.Load("assets/knockback.json")
if err != nil {
panic(err)
}
chat.Global.Subscribe(chat.StdoutSubscriber{})
c := server.DefaultConfig()
c.Players.SaveData = false
conf, err := c.Config(slog.Default())
if err != nil {
logrus.Fatalln(err)
}
srv := conf.New()
srv.CloseOnProgramEnd()
cmd.Register(cmd.New("kb", "", nil, knockback.Menu{}))
srv.Listen()
for p := range srv.Accept() {
intercept.Intercept(p)
p.Handle(handler{})
p.SetGameMode(world.GameModeSurvival)
}
}
type handler struct {
player.NopHandler
}
func (handler) HandleHurt(ctx *player.Context, damage *float64, immune bool, attackImmunity *time.Duration, src world.DamageSource) {
if immune {
return
}
knockback.ApplyHitDelay(attackImmunity)
}
func (handler) HandleAttackEntity(ctx *player.Context, e world.Entity, force, height *float64, critical *bool) {
knockback.ApplyForce(force)
knockback.ApplyHeight(height)
}