承接 hadesnetwork/commando 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

hadesnetwork/commando

Composer 安装命令:

composer require hadesnetwork/commando

包简介

A Command Framework virion for PocketMine-MP

README 文档

README


A PocketMine-MP Virion for easier implementation of dynamic commands, including support for Minecraft: Bedrock Edition argument listing aimed for both the end users and the plugin developers.

Usage:

Installation is easy, you may get a compiled phar here, integrate the virion itself into your plugin or you could also use it as a composer library by running the command below:

composer require cortexpe/commando

This virion is purely object oriented. So, to use it you'll have to extend the BaseCommand object, import the PacketHooker object and the optional objects for subcommands and arguments (whenever necessary).

For PocketMine-MP API 4, you will need to include Muqsit/SimplePacketHandler in your dependencies.

Why is this necessary?

The virion provides an easy way to verify user input, convert user input, and for making sure that our arguments are the type that we expect it to.

On the plus side, it also provides the argument list for the client to recognize making it easy to use the command without remembering the order of arguments.

Because not only MC: Bedrock can use the commands, I've also implemented command usage pre-generation for ease of use with the console as well.

This also provides an easy to use API for lessening boilerplate code while adding more functionality and verbosity (error codes, and error lists, and sending usage messages).

It is structured in a similar way to the legacy PocketMine commands for ease of migration from an older codebase.

Upon the time of writing this readme file, This virion will be used on Hierarchy for the command implementation clean-up

Basic Usage:

NOTE: Other miscellaneous functions can be indexed within your IDEs or by reading the source code. This is only the basic usage of the virion, it does not show every aspect of it as that'd be too long to document.

Create your command class

In our command class, we need to extend BaseCommand and implement its required methods to use all of Commando's features.

<?php

use CortexPE\Commando\BaseCommand;
use pocketmine\command\CommandSender;

class MyCommand extends BaseCommand {
	protected function prepare(): void {
		// This is where we'll register our arguments and subcommands
	}
	
	public function onRun(CommandSender $sender, string $aliasUsed, array $args): void {
		// This is where the processing will occur if it's NOT handled by other subcommands
	}
}

Register the arguments

If we register arguments, we need to import and use / extend (if needed) the provided argument objects.

use CortexPE\Commando\args\RawStringArgument;

	protected function prepare(): void {
		// $this->registerArgument(position, argument object (name, isOptional));
		$this->registerArgument(0, new RawStringArgument("name", true));
	}

Handling our arguments

The arguments passed on our onRun method will be mapped by name => value this makes it easy to understand which argument is which, instead of using numeric indices. It is also guaranteed that the arguments passed will be the declared type that we've set.

	public function onRun(CommandSender $sender, string $aliasUsed, array $args): void {
		if(isset($args["name"])){
			$sender->sendMessage("Hello, " . $args["name"] . "!");
		} else {
			$this->sendUsage();
		}
	}

Registering the PacketHooker for vanilla command arguments

The PacketHooker listener is required for us to be able to inject data to the AvailableCommandsPacket the server sends.

use CortexPE\Commando\PacketHooker;

// onEnable:
	if(!PacketHooker::isRegistered()) {
		PacketHooker::register($this);
	}

Registering the command from a plugin

Once we've constructed our command with our arguments and subcommands, we can now register our command to PocketMine's command map, to be available to our users.

// onEnable:
$this->getServer()->getCommandMap()->register("myplugin", new MyCommand($this, "greet", "Make the server greet you!"));

The only difference with using this framework is that you don't need to set the usage message, as they are pre-generated after all the arguments have been registered.

SubCommands

Subcommands work the same way as regular commands, the only difference is that they're registered on the parent command with BaseCommand->registerSubCommand() having their own set of arguments and own usage message.

Error messages

The virion provides default error messages for user input errors regarding the arguments given. It also provides a way to register your own error message formats for the sake of customizability.

$cmdCtx->setErrorFormat($errorCode, $format);
// Arrays can be passed on `BaseCommand->setErrorFormats()` to bulk-set other error messages

The error messages are sent in bulk to the users to let them know what parts are wrong with their input, not having to do trial-and-error. A current limitation is that, you cannot register your own error messages with other error codes.

This framework was made with ❤️ by CortexPE, Enjoy!~ :3

hadesnetwork/commando 适用场景与选型建议

hadesnetwork/commando 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 66 次下载、GitHub Stars 达 1, 最近一次更新时间为 2024 年 02 月 23 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 hadesnetwork/commando 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 hadesnetwork/commando 我们能提供哪些服务?
定制开发 / 二次开发

基于 hadesnetwork/commando 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 66
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 8
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 68
  • 开发语言: PHP

其他信息

  • 授权协议: LGPL-3.0-only
  • 更新时间: 2024-02-23