From a7f5ee2f3e7ddf270074522b2529008fac66360c Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 13 Jul 2017 10:57:10 +0100 Subject: [PATCH] Added capability to get/set screen height in lines for each CommandSender to alter page sizes of command output such as /help (#1144) --- src/pocketmine/Player.php | 14 ++++++++++++++ src/pocketmine/command/CommandSender.php | 12 ++++++++++++ src/pocketmine/command/ConsoleCommandSender.php | 15 +++++++++++++++ src/pocketmine/command/defaults/HelpCommand.php | 6 +----- 4 files changed, 42 insertions(+), 5 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 499d78220..8b8536793 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -325,6 +325,9 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade /** @var PermissibleBase */ private $perm = null; + /** @var int|null */ + protected $lineHeight = null; + public function getLeaveMessage(){ return new TranslationContainer(TextFormat::YELLOW . "%multiplayer.player.left", [ $this->getDisplayName() @@ -461,6 +464,17 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade $this->removeFormat = (bool) $remove; } + public function getScreenLineHeight() : int{ + return $this->lineHeight ?? 7; + } + + public function setScreenLineHeight(int $height = null){ + if($height !== null and $height < 1){ + throw new \InvalidArgumentException("Line height must be at least 1"); + } + $this->lineHeight = $height; + } + /** * @param Player $player * diff --git a/src/pocketmine/command/CommandSender.php b/src/pocketmine/command/CommandSender.php index 9c9c374a9..2a522fd27 100644 --- a/src/pocketmine/command/CommandSender.php +++ b/src/pocketmine/command/CommandSender.php @@ -44,5 +44,17 @@ interface CommandSender extends Permissible{ */ public function getName(); + /** + * Returns the line height of the command-sender's screen. Used for determining sizes for command output pagination + * such as in the /help command. + * + * @return int + */ + public function getScreenLineHeight() : int; + /** + * Sets the line height used for command output pagination for this command sender. `null` will reset it to default. + * @param int|null $height + */ + public function setScreenLineHeight(int $height = null); } \ No newline at end of file diff --git a/src/pocketmine/command/ConsoleCommandSender.php b/src/pocketmine/command/ConsoleCommandSender.php index ddd122368..4a75dd125 100644 --- a/src/pocketmine/command/ConsoleCommandSender.php +++ b/src/pocketmine/command/ConsoleCommandSender.php @@ -31,11 +31,15 @@ use pocketmine\permission\PermissionAttachmentInfo; use pocketmine\plugin\Plugin; use pocketmine\Server; use pocketmine\utils\MainLogger; +use pocketmine\utils\Terminal; class ConsoleCommandSender implements CommandSender{ private $perm; + /** @var int|null */ + protected $lineHeight = null; + public function __construct(){ $this->perm = new PermissibleBase($this); } @@ -139,4 +143,15 @@ class ConsoleCommandSender implements CommandSender{ } + public function getScreenLineHeight() : int{ + return $this->lineHeight ?? PHP_INT_MAX; + } + + public function setScreenLineHeight(int $height = null){ + if($height !== null and $height < 1){ + throw new \InvalidArgumentException("Line height must be at least 1"); + } + $this->lineHeight = $height; + } + } \ No newline at end of file diff --git a/src/pocketmine/command/defaults/HelpCommand.php b/src/pocketmine/command/defaults/HelpCommand.php index 9d56ced46..761e727de 100644 --- a/src/pocketmine/command/defaults/HelpCommand.php +++ b/src/pocketmine/command/defaults/HelpCommand.php @@ -60,11 +60,7 @@ class HelpCommand extends VanillaCommand{ $pageNumber = 1; } - if($sender instanceof ConsoleCommandSender){ - $pageHeight = PHP_INT_MAX; - }else{ - $pageHeight = 7; - } + $pageHeight = $sender->getScreenLineHeight(); if($command === ""){ /** @var Command[][] $commands */