PocketMine-MP 5.35.1 git-f412a390b8f63d0311cc1d1c81046404153b8440
Loading...
Searching...
No Matches
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
32use pocketmine\permission\PermissibleDelegateTrait;
36use function explode;
37use function trim;
38use const PHP_INT_MAX;
39
41 use PermissibleDelegateTrait;
42
44 protected ?int $lineHeight = null;
45
46 private CommandAliasMap $commandAliasMap;
47
48 public function __construct(
49 private Server $server,
50 private Language $language
51 ){
52 $this->perm = new PermissibleBase([DefaultPermissions::ROOT_CONSOLE => true]);
53 $this->commandAliasMap = new CommandAliasMap();
54 }
55
56 public function getServer() : Server{
57 return $this->server;
58 }
59
60 public function getLanguage() : Language{
61 return $this->language;
62 }
63
64 public function sendMessage(Translatable|string $message) : void{
65 if($message instanceof Translatable){
66 $message = $this->getLanguage()->translate($message);
67 }
68
69 foreach(explode("\n", trim($message), limit: PHP_INT_MAX) as $line){
70 Terminal::writeLine(TextFormat::GREEN . "Command output | " . TextFormat::addBase(TextFormat::WHITE, $line));
71 }
72 }
73
74 public function getName() : string{
75 return "CONSOLE";
76 }
77
78 public function getScreenLineHeight() : int{
79 return $this->lineHeight ?? PHP_INT_MAX;
80 }
81
82 public function setScreenLineHeight(?int $height) : void{
83 if($height !== null && $height < 1){
84 throw new \InvalidArgumentException("Line height must be at least 1");
85 }
86 $this->lineHeight = $height;
87 }
88
89 public function getCommandAliasMap() : CommandAliasMap{ return $this->commandAliasMap; }
90}