diff --git a/core_commands/gamemode.go b/core_commands/gamemode.go index 4aa2a3f..64b51bf 100644 --- a/core_commands/gamemode.go +++ b/core_commands/gamemode.go @@ -22,17 +22,8 @@ var gamemode_cmd = &commands.Command{ Name: "gamemode", RequiredPermissions: []string{"server.command.gamemode"}, Arguments: []commands.Argument{ - { - Name: "mode", - ParserID: 39, - }, - { - Name: "player", - ParserID: 6, - Properties: commands.Properties{ - Flags: 0x02, - }, - }, + commands.NewGamemodeArgument("mode"), + commands.NewEntityArgument("player", commands.EntityPlayerOnly), }, Execute: func(ctx commands.CommandContext) { if len(ctx.Arguments) == 0 { diff --git a/go.mod b/go.mod index 1b8d241..e90fbec 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( require ( github.com/Shopify/go-lua v0.0.0-20221004153744-91867de107cf - github.com/aimjel/minecraft v0.0.0-20230927182639-1fa3dd7aeebc + github.com/aimjel/minecraft v0.0.0-20230927222750-0a432da348ec github.com/dop251/goja v0.0.0-20230919151941-fc55792775de ) diff --git a/go.sum b/go.sum index 460ae7b..f0d8bd8 100644 --- a/go.sum +++ b/go.sum @@ -8,6 +8,8 @@ github.com/aimjel/minecraft v0.0.0-20230927163915-b3907034c0a8 h1:Vl58C0lpKTDgSZ github.com/aimjel/minecraft v0.0.0-20230927163915-b3907034c0a8/go.mod h1:/Y9/YBqxNOU7IFInEjDbsCVkdPNYJCPxC26jK+w3Phc= github.com/aimjel/minecraft v0.0.0-20230927182639-1fa3dd7aeebc h1:irjh4/oH9vWvkOr8xyQGudFeOYVpuzy9dgDnTkevtvg= github.com/aimjel/minecraft v0.0.0-20230927182639-1fa3dd7aeebc/go.mod h1:/Y9/YBqxNOU7IFInEjDbsCVkdPNYJCPxC26jK+w3Phc= +github.com/aimjel/minecraft v0.0.0-20230927222750-0a432da348ec h1:aFUC1sZUBSlOtIniOxDWN2orepj9/dSxSAdqVtdVNcE= +github.com/aimjel/minecraft v0.0.0-20230927222750-0a432da348ec/go.mod h1:/Y9/YBqxNOU7IFInEjDbsCVkdPNYJCPxC26jK+w3Phc= github.com/chzyer/logex v1.2.0/go.mod h1:9+9sk7u7pGNWYMkh0hdiL++6OeibzJccyQU4p4MedaY= github.com/chzyer/readline v1.5.0/go.mod h1:x22KAscuvRqlLoK9CsoYsmxoXZMMFVyOl86cAH8qUic= github.com/chzyer/test v0.0.0-20210722231415-061457976a23/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= diff --git a/server/commands/builders.go b/server/commands/builders.go index 6a4f98f..706b238 100644 --- a/server/commands/builders.go +++ b/server/commands/builders.go @@ -6,14 +6,17 @@ const ( StringGreedyPhrase ) -func NewCommand(name string, execute func(ctx CommandContext), arguments ...Argument) *Command { - return &Command{Name: name, Execute: execute, Arguments: arguments} -} +const ( + EntitySingle = iota + 1 + EntityPlayerOnly +) func NewBoolArgument(name string) Argument { return Argument{ - Name: name, - ParserID: 0, + Name: name, + Parser: Parser{ + ID: 0, + }, } } @@ -31,9 +34,11 @@ func NewFloatArgument(name string, properties struct { props.Max = *properties.Max } return Argument{ - Name: name, - ParserID: 1, - Properties: props, + Name: name, + Parser: Parser{ + ID: 1, + Properties: props, + }, } } @@ -51,9 +56,11 @@ func NewDoubleArgument(name string, properties struct { props.Max = *properties.Max } return Argument{ - Name: name, - ParserID: 2, - Properties: props, + Name: name, + Parser: Parser{ + ID: 2, + Properties: props, + }, } } @@ -71,9 +78,11 @@ func NewIntegerArgument(name string, properties struct { props.Max = uint64(*properties.Max) } return Argument{ - Name: name, - ParserID: 3, - Properties: props, + Name: name, + Parser: Parser{ + ID: 3, + Properties: props, + }, } } @@ -91,17 +100,41 @@ func NewLongArgument(name string, properties struct { props.Max = uint64(*properties.Max) } return Argument{ - Name: name, - ParserID: 4, - Properties: props, + Name: name, + Parser: Parser{ + ID: 4, + Properties: props, + }, } } func NewStringArgument(name string, properties byte) Argument { props := Properties{Flags: properties} return Argument{ - Name: name, - ParserID: 5, - Properties: props, + Name: name, + Parser: Parser{ + ID: 5, + Properties: props, + }, + } +} + +func NewEntityArgument(name string, properties byte) Argument { + props := Properties{Flags: properties} + return Argument{ + Name: name, + Parser: Parser{ + ID: 6, + Properties: props, + }, + } +} + +func NewGamemodeArgument(name string) Argument { + return Argument{ + Name: name, + Parser: Parser{ + ID: 39, + }, } } diff --git a/server/commands/commands.go b/server/commands/commands.go index 84feaf2..762bead 100644 --- a/server/commands/commands.go +++ b/server/commands/commands.go @@ -54,16 +54,20 @@ type Command struct { } type Properties struct { - Flags uint8 `json:",omitempty"` - Min, Max uint64 `json:",omitempty"` - Identifier string `json:",omitempty"` + Flags uint8 + Min, Max uint64 + Identifier string +} + +type Parser struct { + ID int32 `js:"id"` + Properties Properties `js:"properties"` } type Argument struct { Name string `js:"name"` - ParserID int32 `js:"parserId"` SuggestionType string `js:"suggestionType"` - Properties Properties + Parser Parser `js:"parser"` } type Graph struct { @@ -110,7 +114,7 @@ func (graph Graph) Data() *pk.DeclareCommands { for _, argument := range command.Arguments { parent := len(packet.Nodes) - 1 packet.Nodes[parent].Children = append(packet.Nodes[parent].Children, int32(len(packet.Nodes))) - node := pk.Node{Flags: 2, Name: argument.Name, Properties: argument.Properties, ParserID: argument.ParserID} + node := pk.Node{Flags: 2, Name: argument.Name, Properties: argument.Parser.Properties, ParserID: argument.Parser.ID} if argument.SuggestionType != "" { node.Flags |= 0x10 node.SuggestionsType = argument.SuggestionType