Download the PHP package valiant-bedrock/libcommand without Composer
On this page you can find all versions of the php package valiant-bedrock/libcommand. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download valiant-bedrock/libcommand
More information about valiant-bedrock/libcommand
Files in valiant-bedrock/libcommand
Package libcommand
Short Description A PocketMine-MP library for registering commands with proper overloads
License MIT
Informations about the package libcommand
libcommand
A small PocketMine-MP command library meant to simplify the process of creating commands while also enhancing the user experience.
NOTE: This library is still in development and as such, the API is subject to change.
Installation
Composer
The following command can be used to install the library using Composer:
Virion (Poggit)
Virion support can be accessed through Poggit using this link.
Usage
Parameter
At the basis of the library, there is the parameter. In most instances, the parameter class accepts two properties:
name
- The name of the parameter. This is used in the command'sonExecute()
method as well as sent to the client.optional
- Whether the parameter is optional. If the parameter is optional, it will not be required in the overload. When sent to the client, it will be displayed as<name>
if not optional. Otherwise, it'll be displayed as[name]
.
A simple raw-text parameter looks like so:
Parameter Types
This is a list of all current parameter types:
Standard
Class Name | Return Type | Description |
---|---|---|
CommandParameter |
Command |
Accepts any registered command that has been sent to the client. |
EquipmentSlotParameter |
string |
A hardcoded client enum that can take any equipment slot (See [Equipment Slot](#Equipment Slot)) |
EnumParameter |
string |
A list of accepted string values that can be used to filter the results of a command. |
FilepathParameter |
string |
Accepts a filepath (In progress / Not fully researched yet) |
FloatParameter |
float |
Accepts any float value. |
IntParameter |
int |
Accepts any integer value. |
IntVector3Parameter |
Vector3<int> |
Accepts positional coordinates and returns a integer-oriented Vector3 |
JsonParameter |
string |
Returns a JSON string (In progress / Not fully researched yet) |
MessageParameter |
string |
Returns a message (used for chat commands like /tell ) |
OperatorParameter |
string |
Accepts one of the following: "+", "-", "*", "/", "%" |
RawTextParameter |
string |
Returns a string (No parameters can be accepted after this) |
StringParameter |
string |
Accepts any string value. |
TargetParameter |
Player |
Accepts a target (only supported for Players at the moment) |
ValueParameter |
string |
(Not fully researched yet) |
Vector3Parameter |
Vector3<float> |
Accepts positional coordinates and returns a float-oriented Vector3 |
WildcardIntParameter |
int |
(In progress / Not fully researched yet) |
WildcardTargetParameter |
Player |
(In progress / Not fully researched yet) |
Custom
Class Name | Return Type | Description |
---|---|---|
BoolParameter |
bool |
An Enum parameter that can be true , false , 1 , or 0 |
SubcommandParameter |
string |
A parameter that allows for nothing but the subcommand name to be passed. |
BlockEnumParameter |
Block |
An Enum parameter that displays a list of blocks to the client |
ItemEnumParameter |
Item |
An Enum parameter that displays a list of items to the client |
Overload
In the terms of commands, an overload is a set of parameters that a command can take. An overload is defined by an array of Parameter
objects. Here is how a simple overload class looks:
Command
Finally, to tie these features together, it uses the Command
class. This class is meant to be extended to create new commands. The class extends \pocketmine\command\Command
and accepts
one more parameter, $overloads
, which is an array of Overload
objects, though you can use the methods addOverload(Overload $overload): void
and addOverloads(Overload ...$overloads)
to add them separately from the constructor.
onExecute(CommandSender $sender, string $overload, array<Parameter> $arguments): bool|string
This method is the heart of the command and runs the actual logic of the command. The command will look for a compatible overload and then pass it to $arguments
. With $arguments
, you can
access the parameter values through their name (e.g., new StringParameter("name")
would be accessed through $arguments["name"]
). If the return type from this method is string
, the returned value will be sent to the command sender.
Command Sender Access
To limit the access to the command, you can use the ConsoleCommand
class or PlayerCommand
class. This will verify the command sender before executing the command.
Each of these classes have their own special methods that are called after the sender is verified:
PlayerCommand
:onPlayerExecute(Player $player, string $overload, array $arguments): bool|string
ConsoleCommand
:onConsoleExecute(ConsoleCommandSender $sender, string $overload, array $arguments): bool|string
NOTE: These methods do replace the onExecute()
method.
Simple Example
Below is a simple example on how to create and register commands.
Command Class
Registration
ClosureCommand
If you would like to create a command without using a separate class, the ClosureCommand
class can be used.
This foregoes the need for a separate class and allows you to use a closure to define the command logic.
A simple example of a closure command would look something like:
Vanilla Command Rendering
While not supported by default, libcommand\VanillaCommandPatcher::register(PluginBase $plugin)
can be used to patch the default vanilla commands and render them client-side.
NOTE: This may be separated into a separate plugin in the future, but as of now, it is bundled with the library.
Types
These types are associated with the various parameters.
Equipment Slot
slot.armor
slot.armor.head
slot.armor.chest
slot.armor.legs
slot.armor.feet
slot.chest
slot.enderchest
slot.equippable
slot.hotbar
slot.inventory
slot.saddle
slot.weapon.mainhand
slot.weapon.offhand
Roadmap
- [ ] Generate usage messages based off of overloads
- [ ] Introduce subcommand system