1. Go to this page and download the library: Download valiant-bedrock/libcommand library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
valiant-bedrock / libcommand example snippets
$parameter = new \libcommand\parameter\types\RawTextParameter(name: "text", optional: true);
$overload = new libcommand\Overload(
// An internal name used to track the overload
name: "test",
// A list of parameters
parameters: []
);
class SimpleCommand extends libcommand\Command {
public function __construct() {
parent::__construct(
name: "simple",
description: "Simple command description",
usageMessage: "Usage: /simple <test_int> <test_raw>",
aliases: ["s"],
overloads: [
new libcommand\Overload(name: "default", parameters: [
new \libcommand\IntParameter(name: "test_int", description: "Test integer parameter", optional: false),
new \libcommand\RawTextParameter(name: "test_raw", description: "Test raw text parameter", optional: true)
])
],
// Permissions and their messages can also be specified using the `permission` and `permissionMessage` properties.
// permission: "simple.command",
// permissionMessage: "Ouch! You don't have permission to use SimpleCommand!"
);
}
public function onExecute(\pocketmine\command\CommandSender $sender, string $overload, array $arguments) : bool|string {
$int = $arguments["test_int"];
$raw = $arguments["test_raw"] ?? "fallback raw text";
// Returning a string will send the sender the returned message
return "Simple command executed with $int and $raw";
}
}
class SimplePlugin extends \pocketmine\plugin\PluginBase {
protected function onEnable(): void {
// Registering `LibCommandBase` allows for client-sided rendering to be done
libcommand\LibCommandBase::register(plugin: $this);
$this->getServer()->getCommandMap()->register(
fallbackPrefix: $this->getName(),
command: new SimpleCommand()
);
}
}
\pocketmine\Server::getInstance()->getCommandMap()->register(
fallbackPrefix: "examples",
command: new \libcommand\ClosureCommand(
name: "add",
onExecute: function (\pocketmine\command\CommandSender $sender, string $overload, array $arguments) : bool|string {
// Null-coalescing operator is used to keep PHPStan happy, but won't actually occur
$first = $arguments["first"] ?? throw new AssumptionFailedError("First argument is r(name: "first"),
new \libcommand\parameter\types\IntParameter(name: "second")
]
)
]
)
);
// `/add 1 2` will send a message with the following message: "Result of 1 + 2: 3"
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.