I am currently working on an updated version of the MyPlot Plugin and when the help command is run, the save commands are output to the player no matter what page i use. Can someone help me understand why? This still works on the old PocketMine PHP: public function execute(CommandSender $sender, array $args) { if (count($args) === 0) { $pageNumber = 1; } elseif (is_numeric($args[0])) { $pageNumber = (int)$args[0]; if ($pageNumber <= 0) { $pageNumber = 1; } } else { return false; } $pageHeight = 7; $commands = []; foreach ($this->cmd->getCommands() as $command) { if ($command->canUse($sender)) { $commands[$command->getName()] = $command; } } ksort($commands, SORT_NATURAL | SORT_FLAG_CASE); $commands = array_chunk($commands, $pageHeight); /** @var SubCommand[][] $commands */ $pageNumber = (int) min(count($commands), $pageNumber); $sender->sendMessage($this->translateString("help.header", [$pageNumber, count($commands)])); if($sender instanceof Player) { foreach ($commands[$pageNumber - 1] as $command) { $sender->sendMessage(TextFormat::DARK_GREEN . $command->getName() . ": " . TextFormat::WHITE . $command->getDescription()); } }else{ foreach ($this->cmd->getCommands() as $subCommand) { $sender->sendMessage(TextFormat::DARK_GREEN . $subCommand->getName() . ": " . TextFormat::WHITE . $subCommand->getDescription()); } } return true; }
I simplified your problem: https://3v4l.org/VKnBs It is working perfectly (at least for what I expect it to do). Might it be some other problems you have in command parsing? Also note that using array_chunk() is not the most efficient way to do it. Might have negligible difference in terms of performance compared to other parts of the code, but using simple arithmetic directlly might be more effective: PHP: function showPage(int $pageNumber, int $pageHeight, array $objects, callable $send){ $pageNumber--; // now starts counting from 0 $cnt = count($objects); printf("Showing page %d of %d", $pageNumber + 1, ceil(count($objects) / $pageNumber)); // I know this line is not what you asked for, just putting it here for future readers for($i = 0; $i < $pageHeight and $pageNumber * $pageHeight + $i < $cnt; $i++){ $send($objects[$pageNumber * $pageHeight + $i]); }}