mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-07 18:32:55 +00:00
Merge remote-tracking branch 'origin/stable'
This commit is contained in:
@ -26,9 +26,12 @@ namespace pocketmine\block;
|
||||
use pocketmine\block\tile\Sign as TileSign;
|
||||
use pocketmine\block\utils\SignText;
|
||||
use pocketmine\event\block\SignChangeEvent;
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\math\AxisAlignedBB;
|
||||
use pocketmine\math\Vector3;
|
||||
use pocketmine\player\Player;
|
||||
use pocketmine\utils\TextFormat;
|
||||
use pocketmine\world\BlockTransaction;
|
||||
use function array_map;
|
||||
use function assert;
|
||||
use function strlen;
|
||||
@ -39,6 +42,9 @@ abstract class BaseSign extends Transparent{
|
||||
/** @var SignText */
|
||||
protected $text;
|
||||
|
||||
/** @var int|null */
|
||||
protected $editorEntityRuntimeId = null;
|
||||
|
||||
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
|
||||
parent::__construct($idInfo, $name, $breakInfo ?? new BlockBreakInfo(1.0, BlockToolType::AXE));
|
||||
$this->text = new SignText();
|
||||
@ -49,6 +55,7 @@ abstract class BaseSign extends Transparent{
|
||||
$tile = $this->pos->getWorld()->getTile($this->pos);
|
||||
if($tile instanceof TileSign){
|
||||
$this->text = $tile->getText();
|
||||
$this->editorEntityRuntimeId = $tile->getEditorEntityRuntimeId();
|
||||
}
|
||||
}
|
||||
|
||||
@ -57,6 +64,7 @@ abstract class BaseSign extends Transparent{
|
||||
$tile = $this->pos->getWorld()->getTile($this->pos);
|
||||
assert($tile instanceof TileSign);
|
||||
$tile->setText($this->text);
|
||||
$tile->setEditorEntityRuntimeId($this->editorEntityRuntimeId);
|
||||
}
|
||||
|
||||
public function isSolid() : bool{
|
||||
@ -78,6 +86,13 @@ abstract class BaseSign extends Transparent{
|
||||
}
|
||||
}
|
||||
|
||||
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
||||
if($player !== null){
|
||||
$this->editorEntityRuntimeId = $player->getId();
|
||||
}
|
||||
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an object containing information about the sign text.
|
||||
*/
|
||||
@ -108,6 +123,9 @@ abstract class BaseSign extends Transparent{
|
||||
$ev = new SignChangeEvent($this, $author, new SignText(array_map(function(string $line) : string{
|
||||
return TextFormat::clean($line, false);
|
||||
}, $text->getLines())));
|
||||
if($this->editorEntityRuntimeId === null || $this->editorEntityRuntimeId !== $author->getId()){
|
||||
$ev->cancel();
|
||||
}
|
||||
$ev->call();
|
||||
if(!$ev->isCancelled()){
|
||||
$this->setText($ev->getNewText());
|
||||
|
@ -53,6 +53,9 @@ class Sign extends Spawnable{
|
||||
/** @var SignText */
|
||||
protected $text;
|
||||
|
||||
/** @var int|null */
|
||||
protected $editorEntityRuntimeId = null;
|
||||
|
||||
public function __construct(World $world, Vector3 $pos){
|
||||
$this->text = new SignText();
|
||||
parent::__construct($world, $pos);
|
||||
@ -90,6 +93,22 @@ class Sign extends Spawnable{
|
||||
$this->text = $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the entity runtime ID of the player who placed this sign. Only the player whose entity ID matches this
|
||||
* one may edit the sign text.
|
||||
* This is needed because as of 1.16.220, there is still no reliable way to detect when the MCPE client closed the
|
||||
* sign edit GUI, so we have no way to know when the text is finalized. This limits editing of the text to only the
|
||||
* player who placed it, and only while that player is online.
|
||||
* We can say for sure that the sign is finalized if either of the following occurs:
|
||||
* - The player quits (after rejoin, the player's entity runtimeID will be different).
|
||||
* - The chunk is unloaded (on next load, the entity runtimeID will be null, because it's not saved).
|
||||
*/
|
||||
public function getEditorEntityRuntimeId() : ?int{ return $this->editorEntityRuntimeId; }
|
||||
|
||||
public function setEditorEntityRuntimeId(?int $editorEntityRuntimeId) : void{
|
||||
$this->editorEntityRuntimeId = $editorEntityRuntimeId;
|
||||
}
|
||||
|
||||
protected function addAdditionalSpawnData(CompoundTag $nbt) : void{
|
||||
$nbt->setString(self::TAG_TEXT_BLOB, implode("\n", $this->text->getLines()));
|
||||
}
|
||||
|
Reference in New Issue
Block a user