-
Notifications
You must be signed in to change notification settings - Fork 0
/
form_remove.go
51 lines (43 loc) · 1.03 KB
/
form_remove.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
package main
import (
"github.com/df-mc/dragonfly/server/player"
"github.com/df-mc/dragonfly/server/player/form"
"golang.org/x/text/message"
"slices"
)
func newRemoveForm(p *message.Printer, prof profile) form.Form {
buttons, servers := serverButtons(p, prof)
return form.NewMenu(removeForm{
p: p,
servers: servers,
}, p.Sprintf("menu.remove.title")).WithButtons(buttons...)
}
type removeForm struct {
p *message.Printer
servers map[string]serverProfile
}
func (f removeForm) Submit(s form.Submitter, pressed form.Button) {
server, ok := f.servers[pressed.Text]
if !ok {
return
}
p, ok := s.(*player.Player)
if !ok {
return
}
v, ok := handlers.Load(p.UUID())
if !ok {
return
}
h := v.(*handler)
prof := h.prof.Load()
i := slices.IndexFunc(prof.Servers, func(s serverProfile) bool {
return addressEqual(s.Address, server.Address) || s.RawAddress == server.RawAddress
})
if i < 0 {
return
}
prof.Servers = slices.Delete(prof.Servers, i, i+1)
h.prof.Store(prof)
p.Message(f.p.Sprintf("menu.remove.success"))
}