command

package
v0.0.0-...-2a33acd Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 20, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BOOL               parser_kind = iota // Boolean value
	DOUBLE                                // Double
	FLOAT                                 // Float
	INTEGER                               // Integer
	STRING                                // A string
	ENTITY                                // A selector, player name, or UUID.
	GAME_PROFILE                          // A player, online or not. Can also use a selector, which may match one or more players (but not entities).
	BLOCK_POS                             // A location, represented as 3 numbers (which must be integers). May use relative locations with ~.
	COLUMN_POS                            // A column location, represented as 3 numbers (which must be integers). May use relative locations with ~.
	VEC3                                  // A location, represented as 3 numbers (which may have a decimal point, but will be moved to the center of a block if none is specified). May use relative locations with ~.
	VEC2                                  // A location, represented as 2 numbers (which may have a decimal point, but will be moved to the center of a block if none is specified). May use relative locations with ~.
	BLOCK_STATE                           // A block state, optionally including NBT and state information.
	BLOCK_PREDICATE                       // A block, or a block tag.
	ITEM_STACK                            // An item, optionally including NBT.
	ITEM_PREDICATE                        // An item, or an item tag.
	COLOR                                 // A chat color. One of the names from Chat#Colors, or reset. Case-insensitive.
	COMPONENT                             // A JSON Chat component.
	MESSAGE                               // A regular message, potentially including selectors.
	NBT                                   // An NBT value, parsed using JSON-NBT rules.
	NBT_PATH                              // A path within an NBT value, allowing for array and member accesses.
	OBJECTIVE                             // A scoreboard objective.
	OBJECTIVE_CRITERIA                    // A single score criterion.
	OPERATION                             // A scoreboard operator.
	PARTICLE                              // A particle effect (an identifier with extra information following it for specific particles, mirroring the Particle packet)
	ROTATION                              // An angle, represented as 2 numbers (which may have a decimal point, but will be moved to the center of a block if none is specified). May use relative locations with ~.
	ANGLE                                 // minecraft:angle
	SCOREBOARD_SLOT                       // A scoreboard display position slot. list, sidebar, belowName, and sidebar.team.${color} for all chat colors (reset is not included)
	SCORE_HOLDER                          // Something that can join a team. Allows selectors and *.
	SWIZZLE                               // A collection of up to 3 axes.
	TEAM                                  // The name of a team. Parsed as an unquoted string.
	ITEM_SLOT                             // A name for an inventory slot.
	RESOURCE_LOCATION                     // An Identifier.
	MOB_EFFECT                            // A potion effect.
	FUNCTION                              // A function.
	ENTITY_ANCHOR                         // The entity anchor related to the facing argument in the teleport command, is feet or eyes.
	RANGE                                 // A range of values with a min and a max.
	INT_RANGE                             // An integer range of values with a min and a max.
	FLOAT_RANGE                           // A floating-point range of values with a min and a max.
	ITEM_ENCHANTMENT                      // Represents a item enchantment.
	ENTITY_SUMMON                         // Represents an entity summon.
	DIMENSION                             // Represents a dimension.
	UUID                                  // Represents a UUID value.
	NBT_TAG                               // Represents a partial nbt tag, usable in data modify command.
	NBT_COMPOUND_TAG                      // Represents a full nbt tag.
	TIME                                  // Represents a time duration.
)

See https://wiki.vg/Command_Data for more information.

Variables

This section is empty.

Functions

func ParseFloat

func ParseFloat(arg string) (float32, error)

Shorthand for any float

func ParsePosition

func ParsePosition(player *player.Player, x_str, y_str, z_str string) (x, y, z int32, err error)

This parses a block position in the world, and is just three PositionNums in a row

func ParsePositionNum

func ParsePositionNum(base int32, val string) (int32, error)

Parses a number in either of these formats: 10 -5 -123 ~ ~-10 ~123 The ~ means relative positioning, and that is relative to the base parameter

func Parser

func Parser(k parser_kind) parser

This creates a parser for a node. You should use the constants for the parser_kind. To change the way the values are parsed, call functions like Min() or Max(). See the individual functions for more info. All functions will return copies of the original parser, with the new settings applied. They are designed to be used inline as arguments to NewArgumentNode().

Types

type Command

type Command struct {
	// contains filtered or unexported fields
}

func New

func New(name string, runner func(*world.WorldManager, *player.Player, []string) bool, children ...*Node) *Command

Creates a new command. The name will be the command without the /. The running is called whenever the client runs this command. The children are the arguments to the command. See Node for more information on command nodes.

func (*Command) AddNode

func (c *Command) AddNode(child ...*Node) *Command

Adds the given nodes as children. These are top level arguments to the command.

func (*Command) SetRunner

func (c *Command) SetRunner(runner func(*world.WorldManager, *player.Player, []string) bool) *Command

Changes the function that is called when the command is run. This will override the previous runner.

func (*Command) SetTabCompleter

func (c *Command) SetTabCompleter(runner func(*world.WorldManager, *player.Player, []string) []string) *Command

Changes the function that is called whenever the client requests tab completes. This will only be called if one if the nodes has the 'minecraft:ask_server' suggestion type.

type CommandManager

type CommandManager struct {
	// contains filtered or unexported fields
}

func NewCommandManager

func NewCommandManager(world_manager *world.WorldManager) *CommandManager

func (*CommandManager) Add

func (c *CommandManager) Add(command *Command)

func (*CommandManager) Execute

func (c *CommandManager) Execute(player *player.Player, text string) *util.Chat

func (*CommandManager) GetCommandTree

func (c *CommandManager) GetCommandTree() *packet.OutgoingPacket

func (*CommandManager) TabComplete

func (c *CommandManager) TabComplete(player *player.Player, id int32, text string) *util.Chat

type Node

type Node struct {
	// contains filtered or unexported fields
}

A command node. Since minecraft 1.13, all possible commands are represented with a tree. Every node on the tree is one argument in a command. Every one of these nodes has a type: Root, literal, or argument. The root node is created automatically. Literal nodes are for things like keyworks; they only allow a certain string to be inserted at that point. Argument nodes allow for any text, and are parsed with a node parser. See parser.go for more information on parsers.

To create a command, use the New() function. To add arguments, call AddNode(Node). To create a node, use the ArgumentNode() or LiteralNode() functions.

func ArgumentNode

func ArgumentNode(name string, parser parser, children ...*Node) *Node

Creates a new argument node. The name is what the users sees when they are entering the value of this arguemnt. The parser should be one of the parsers from parser.go.

func LiteralNode

func LiteralNode(name string, children ...*Node) *Node

Creates a new literal node. The name is the only text that will be accepted for this node.

func (*Node) AddNode

func (n *Node) AddNode(other ...*Node) *Node

Adds another node as a child. Will return itself.

func (*Node) Executable

func (n *Node) Executable() *Node

Makes the node executable. This means that at the end of this node, this is a valid command. All nodes that have no children are automatically set to be executable, so this function should only be used if you command is valid with only partial arguments.

func (*Node) Name

func (n *Node) Name(name string) *Node

Changes the name of the node.

func (*Node) Parser

func (n *Node) Parser(parser parser) *Node

Changes the parser for the node. Will panic if this is not an argument node.

func (*Node) Redirect

func (n *Node) Redirect(other *Node) *Node

Sets this node to redirect to another node. If other is nil, then the redirect will be cleared.

func (*Node) Suggestion

func (n *Node) Suggestion(suggestion string) *Node

Changes the suggestion of the node. If this is an empty string, the suggestion will be cleared.

func (*Node) ToPacket

func (n *Node) ToPacket() *packet.OutgoingPacket

Only valid on the root node. Will return an outgoing packet that contains the entire command tree. You should node call this function, as it will panic on everything that is not a root node.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL