PocketMine-MP
5.21.2 git-b2aa6396c3cc2cafdd815eacc360e1ad89599899
Loading...
Searching...
No Matches
SignText.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
22
declare(strict_types=1);
23
24
namespace
pocketmine\block\utils;
25
26
use
pocketmine\color\Color
;
27
use
pocketmine\utils\Utils
;
28
use
function
array_fill;
29
use
function
array_pad;
30
use
function
array_slice;
31
use
function
count;
32
use
function
explode;
33
use
function
is_int;
34
use
function
str_contains;
35
36
class
SignText
{
37
public
const
LINE_COUNT = 4;
38
40
private
array $lines;
41
private
Color
$baseColor;
42
private
bool
$glowing;
43
51
public
function
__construct
(?array $lines =
null
, ?
Color
$baseColor =
null
,
bool
$glowing =
false
){
52
$this->lines = array_fill(0, self::LINE_COUNT,
""
);
53
if
($lines !==
null
){
54
if
(count($lines) > self::LINE_COUNT){
55
throw
new \InvalidArgumentException(
"Expected at most 4 lines, got "
. count($lines));
56
}
57
foreach
($lines as $k => $line){
58
$this->checkLineIndex($k);
59
Utils::checkUTF8($line);
60
if
(str_contains($line,
"\n"
)){
61
throw
new \InvalidArgumentException(
"Line must not contain newlines"
);
62
}
63
//TODO: add length checks
64
$this->lines[$k] = $line;
65
}
66
}
67
$this->baseColor = $baseColor ??
new
Color
(0, 0, 0);
68
$this->glowing = $glowing;
69
}
70
77
public
static
function
fromBlob
(
string
$blob, ?
Color
$baseColor =
null
,
bool
$glowing =
false
) :
SignText
{
78
return new self(array_slice(array_pad(explode(
"\n"
, $blob), self::LINE_COUNT,
""
), 0, self::LINE_COUNT), $baseColor, $glowing);
79
}
80
86
public
function
getLines
() : array{
87
return $this->lines;
88
}
89
90
private
function
checkLineIndex(
int
|
string
$index) : void{
91
if(!is_int($index)){
92
throw
new \InvalidArgumentException(
"Index must be an integer"
);
93
}
94
if
($index < 0 || $index >= self::LINE_COUNT){
95
throw
new \InvalidArgumentException(
"Line index is out of bounds"
);
96
}
97
}
98
104
public
function
getLine
(
int
$index) : string{
105
$this->checkLineIndex($index);
106
return
$this->lines[$index];
107
}
108
112
public
function
getBaseColor
() :
Color
{
113
return $this->baseColor;
114
}
115
120
public
function
isGlowing
() : bool{
121
return $this->glowing;
122
}
123
}
pocketmine\block\utils\SignText
Definition
SignText.php:36
pocketmine\block\utils\SignText\getBaseColor
getBaseColor()
Definition
SignText.php:112
pocketmine\block\utils\SignText\__construct
__construct(?array $lines=null, ?Color $baseColor=null, bool $glowing=false)
Definition
SignText.php:51
pocketmine\block\utils\SignText\getLines
getLines()
Definition
SignText.php:86
pocketmine\block\utils\SignText\isGlowing
isGlowing()
Definition
SignText.php:120
pocketmine\block\utils\SignText\fromBlob
static fromBlob(string $blob, ?Color $baseColor=null, bool $glowing=false)
Definition
SignText.php:77
pocketmine\block\utils\SignText\getLine
getLine(int $index)
Definition
SignText.php:104
pocketmine\color\Color
Definition
Color.php:29
pocketmine\utils\Utils
Definition
Utils.php:103
src
block
utils
SignText.php
Generated by
1.12.0