mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-20 16:00:20 +00:00
Improve usability of Sign API (#1202)
* Improve usability of Sign API * PHP * Throw exceptions if out of range * Fix phpdocs * Formatting, additional checks in the SignChangeEvent. * Blame php storm * require line count to always be 4 * Adjust exception message
This commit is contained in:
parent
cca9cf2c86
commit
42fb1d1fef
@ -69,14 +69,30 @@ class SignChangeEvent extends BlockEvent implements Cancellable{
|
||||
* @return string
|
||||
*/
|
||||
public function getLine($index){
|
||||
if($index < 0 or $index > 3){
|
||||
throw new \InvalidArgumentException("Index must be in the range 0-3!");
|
||||
}
|
||||
return $this->lines[$index];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string[] $lines
|
||||
*/
|
||||
public function setLines(array $lines){
|
||||
if(count($lines) !== 4){
|
||||
throw new \InvalidArgumentException("Array size must be 4!");
|
||||
}
|
||||
$this->lines = $lines;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $index 0-3
|
||||
* @param string $line
|
||||
*/
|
||||
public function setLine($index, $line){
|
||||
if($index < 0 or $index > 3){
|
||||
throw new \InvalidArgumentException("Index must be in the range 0-3!");
|
||||
}
|
||||
$this->lines[$index] = $line;
|
||||
}
|
||||
}
|
@ -64,6 +64,33 @@ class Sign extends Spawnable{
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $index 0-3
|
||||
* @param string $line
|
||||
* @param bool $update
|
||||
*/
|
||||
public function setLine(int $index, string $line, bool $update = true){
|
||||
if($index < 0 or $index > 3){
|
||||
throw new \InvalidArgumentException("Index must be in the range 0-3!");
|
||||
}
|
||||
$this->namedtag["Text" . ($index + 1)] = $line;
|
||||
if($update){
|
||||
$this->onChanged();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $index 0-3
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getLine(int $index) : string{
|
||||
if($index < 0 or $index > 3){
|
||||
throw new \InvalidArgumentException("Index must be in the range 0-3!");
|
||||
}
|
||||
return (string) $this->namedtag["Text" . ($index + 1)];
|
||||
}
|
||||
|
||||
public function getText(){
|
||||
return [
|
||||
|
Loading…
x
Reference in New Issue
Block a user