PocketMine-MP 5.15.1 git-5ef247620a7c6301a849b54e5ef1009217729fc8
ConsoleCommandSender.php
1<?php
2
3/*
4 *
5 * ____ _ _ __ __ _ __ __ ____
6 * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
7 * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
8 * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
9 * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
10 *
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * @author PocketMine Team
17 * @link http://www.pocketmine.net/
18 *
19 *
20 */
21
22declare(strict_types=1);
23
24namespace pocketmine\console;
25
31use pocketmine\permission\PermissibleDelegateTrait;
35use function explode;
36use function trim;
37use const PHP_INT_MAX;
38
40 use PermissibleDelegateTrait;
41
43 protected ?int $lineHeight = null;
44
45 public function __construct(
46 private Server $server,
47 private Language $language
48 ){
49 $this->perm = new PermissibleBase([DefaultPermissions::ROOT_CONSOLE => true]);
50 }
51
52 public function getServer() : Server{
53 return $this->server;
54 }
55
56 public function getLanguage() : Language{
57 return $this->language;
58 }
59
60 public function sendMessage(Translatable|string $message) : void{
61 if($message instanceof Translatable){
62 $message = $this->getLanguage()->translate($message);
63 }
64
65 foreach(explode("\n", trim($message)) as $line){
66 Terminal::writeLine(TextFormat::GREEN . "Command output | " . TextFormat::addBase(TextFormat::WHITE, $line));
67 }
68 }
69
70 public function getName() : string{
71 return "CONSOLE";
72 }
73
74 public function getScreenLineHeight() : int{
75 return $this->lineHeight ?? PHP_INT_MAX;
76 }
77
78 public function setScreenLineHeight(?int $height) : void{
79 if($height !== null && $height < 1){
80 throw new \InvalidArgumentException("Line height must be at least 1");
81 }
82 $this->lineHeight = $height;
83 }
84}