multiserver/hand.go

50 lines
858 B
Go
Raw Normal View History

2021-02-25 00:11:37 -08:00
package main
import (
"fmt"
2021-02-28 12:59:55 -08:00
2021-02-25 00:11:37 -08:00
"github.com/anon55555/mt"
)
2021-03-29 09:57:30 -07:00
func (c *Conn) UpdateHandCapabs() error {
l := c.Inv().List("hand")
2021-02-25 00:11:37 -08:00
if l == nil {
2021-03-29 09:57:30 -07:00
*c.inv = mt.Inv(append([]mt.NamedInvList(*c.inv), mt.NamedInvList{
2021-02-25 00:11:37 -08:00
Name: "hand",
InvList: mt.InvList{
Width: 1,
},
}))
2021-03-29 09:57:30 -07:00
l = c.Inv().List("hand")
2021-02-25 00:11:37 -08:00
}
var hand mt.Stack
2021-02-25 00:11:37 -08:00
2021-03-29 09:57:30 -07:00
if len(l.Stacks) == 1 && l.Stacks[0].Name != "multiserver:hand_"+c.ServerName() {
hand = l.Stacks[0]
2021-03-29 09:57:30 -07:00
caps := handcapabs[c.ServerName()]
2021-02-28 12:59:55 -08:00
if caps == nil {
2021-03-29 09:57:30 -07:00
return fmt.Errorf("hand tool capabilities of server %s missing", c.ServerName())
2021-02-28 12:59:55 -08:00
}
s, err := caps.SerializeJSON()
if err != nil {
return err
}
2021-02-25 02:21:32 -08:00
hand.SetField("tool_capabilities", s)
} else {
hand = mt.Stack{
Item: mt.Item{
2021-03-29 09:57:30 -07:00
Name: "multiserver:hand_" + c.ServerName(),
},
Count: 1,
}
}
2021-02-25 02:21:32 -08:00
2021-02-25 00:11:37 -08:00
l.Stacks = []mt.Stack{hand}
return nil
}