1: <?php
2: namespace aliuly\common;
3:
4: use pocketmine\command\CommandSender;
5: use pocketmine\command\Command;
6: use pocketmine\utils\TextFormat;
7: use aliuly\common\mc;
8: use aliuly\common\BasicCli;
9:
10: 11: 12:
13: class BasicHelp extends BasicCli {
14: protected $fmt;
15: 16: 17:
18: public function __construct($owner,$fmt = "/%s %s %s") {
19: parent::__construct($owner);
20: $this->enableSCmd("help",["aliases"=>["?"]]);
21: $this->fmt = $fmt;
22: }
23: 24: 25: 26: 27: 28: 29: 30: 31:
32: public function onSCommand(CommandSender $c,Command $cc,$scmd,$data,array $args) {
33: $cm = $this->owner->getSCmdMap();
34: $pageNumber = $this->getPageNumber($args);
35:
36: if (count($args)) {
37: if ($args[0] == "usage") {
38: if ($cm->getUsage($scmd) === null) return false;
39: $c->sendMessage(TextFormat::RED.mc::_("Usage: ").
40: sprintf($this->fmt,
41: $cc->getName(),
42: $scmd, $cm->getUsage($scmd)));
43: return true;
44: }
45: $txt = [ "Help for ".$cc->getName() ];
46:
47: foreach ($args as $i) {
48: if ($cm->getAlias($i) !== null) $i=$cm->getAlias($i);
49: if ($cm->getHelpMsg($i) === null && $cm->getUsage($i) === null) {
50: $txt[] = TextFormat::RED.mc::_("No help for %1%",$i);
51: continue;
52: }
53:
54: $txt[] = TextFormat::YELLOW.mc::_("Help: ").TextFormat::WHITE.
55: "/".$cc->getName()." $i";
56: if ($cm->getHelpMsg($i) !== null)
57: $txt[] = TextFormat::YELLOW.mc::_("Description: ").
58: TextFormat::WHITE.$cm->getHelpMsg($i);
59: if ($cm->getUsage($i) !== null)
60: $txt[] = TextFormat::YELLOW.mc::_("Usage: ").
61: TextFormat::WHITE.
62: sprintf($this->fmt,$cc->getName(),$i,$cm->getUsage($i));
63:
64: }
65: return $this->paginateText($c,$pageNumber,$txt);
66: }
67:
68: $txt = [ mc::_("Available sub-commands for %1%",$cc->getName()) ];
69: foreach ($cm->getHelp() as $cn => $desc) {
70: $ln = TextFormat::GREEN.$cn;
71: foreach ($cm->getAliases() as $i => $j) {
72: if ($j == $cn) $ln .= "|$i";
73: }
74: $ln .= ": ".TextFormat::WHITE.$desc;
75: $txt[] = $ln;
76: }
77: return $this->paginateText($c,$pageNumber,$txt);
78: }
79: }
80: