2022-09-04 14:26:32 +00:00
|
|
|
package world
|
2022-02-26 20:14:40 +00:00
|
|
|
|
|
|
|
import (
|
2022-03-08 22:06:19 +00:00
|
|
|
"context"
|
2022-02-27 10:08:19 +00:00
|
|
|
"flag"
|
2022-02-26 20:14:40 +00:00
|
|
|
|
2023-04-04 00:44:13 +00:00
|
|
|
"github.com/bedrock-tool/bedrocktool/handlers/worlds"
|
2023-01-23 12:40:12 +00:00
|
|
|
"github.com/bedrock-tool/bedrocktool/locale"
|
2023-03-18 11:12:54 +00:00
|
|
|
"github.com/bedrock-tool/bedrocktool/ui/messages"
|
2022-09-04 14:53:21 +00:00
|
|
|
"github.com/bedrock-tool/bedrocktool/utils"
|
2022-02-26 20:14:40 +00:00
|
|
|
)
|
|
|
|
|
2022-02-27 10:08:19 +00:00
|
|
|
func init() {
|
2022-09-04 14:26:32 +00:00
|
|
|
utils.RegisterCommand(&WorldCMD{})
|
2022-08-14 13:18:04 +00:00
|
|
|
}
|
|
|
|
|
2022-08-14 20:55:52 +00:00
|
|
|
type WorldCMD struct {
|
2023-04-04 18:06:05 +00:00
|
|
|
ServerAddress string
|
|
|
|
Packs bool
|
|
|
|
EnableVoid bool
|
|
|
|
SaveEntities bool
|
|
|
|
SaveInventories bool
|
|
|
|
SaveImage bool
|
2022-02-27 10:08:19 +00:00
|
|
|
}
|
|
|
|
|
2022-08-14 20:55:52 +00:00
|
|
|
func (*WorldCMD) Name() string { return "worlds" }
|
2023-01-23 12:40:12 +00:00
|
|
|
func (*WorldCMD) Synopsis() string { return locale.Loc("world_synopsis", nil) }
|
2022-07-29 16:12:06 +00:00
|
|
|
|
2023-01-29 21:20:13 +00:00
|
|
|
func (c *WorldCMD) SetFlags(f *flag.FlagSet) {
|
2023-03-06 01:03:31 +00:00
|
|
|
f.StringVar(&c.ServerAddress, "address", "", locale.Loc("remote_address", nil))
|
|
|
|
f.BoolVar(&c.Packs, "packs", false, locale.Loc("save_packs_with_world", nil))
|
|
|
|
f.BoolVar(&c.EnableVoid, "void", true, locale.Loc("enable_void", nil))
|
|
|
|
f.BoolVar(&c.SaveImage, "image", false, locale.Loc("save_image", nil))
|
2023-04-04 18:06:05 +00:00
|
|
|
f.BoolVar(&c.SaveEntities, "save-entities", true, "Save Entities")
|
|
|
|
f.BoolVar(&c.SaveInventories, "save-inventories", true, "Save Inventories")
|
2023-03-05 21:50:58 +00:00
|
|
|
}
|
|
|
|
|
2023-03-06 20:49:30 +00:00
|
|
|
func (c *WorldCMD) Execute(ctx context.Context, ui utils.UI) error {
|
|
|
|
serverAddress, hostname, err := ui.ServerInput(ctx, c.ServerAddress)
|
2022-03-05 12:10:17 +00:00
|
|
|
if err != nil {
|
2023-03-06 20:49:30 +00:00
|
|
|
return err
|
2022-03-05 12:10:17 +00:00
|
|
|
}
|
|
|
|
|
2023-03-06 01:03:31 +00:00
|
|
|
proxy, err := utils.NewProxy()
|
2023-02-12 21:22:44 +00:00
|
|
|
if err != nil {
|
2023-03-06 20:49:30 +00:00
|
|
|
return err
|
2023-02-12 21:22:44 +00:00
|
|
|
}
|
|
|
|
|
2023-04-04 00:42:17 +00:00
|
|
|
proxy.AlwaysGetPacks = true
|
2023-04-04 00:44:13 +00:00
|
|
|
proxy.AddHandler(worlds.NewWorldsHandler(ctx, ui, worlds.WorldSettings{
|
2023-04-04 18:06:05 +00:00
|
|
|
VoidGen: c.EnableVoid,
|
|
|
|
WithPacks: c.Packs,
|
|
|
|
SaveEntities: c.SaveEntities,
|
|
|
|
SaveInventories: c.SaveInventories,
|
|
|
|
SaveImage: c.SaveImage,
|
2023-04-04 00:42:17 +00:00
|
|
|
}))
|
|
|
|
|
|
|
|
ui.Message(messages.SetUIState(messages.UIStateConnect))
|
|
|
|
err = proxy.Run(ctx, serverAddress, hostname)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2023-03-30 11:48:03 +00:00
|
|
|
}
|
2023-04-04 00:42:17 +00:00
|
|
|
ui.Message(messages.SetUIState(messages.UIStateFinished))
|
|
|
|
return nil
|
|
|
|
}
|