mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-19 09:54:10 +00:00
- All entity and tile constructors now require a \pocketmine\level\Level instead of a \pocketmine\level\format\Chunk. - Chunk->getProvider() and Chunk->setProvider() have been removed. - Chunk::__construct() has had the $provider parameter removed. - Chunk->unload() has had the unused $save parameter removed. - ChunkEvents now take a Level parameter instead of going through the Chunk API bump to 3.0.0-ALPHA4
115 lines
3.0 KiB
PHP
115 lines
3.0 KiB
PHP
<?php
|
|
|
|
/*
|
|
*
|
|
* ____ _ _ __ __ _ __ __ ____
|
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* @author PocketMine Team
|
|
* @link http://www.pocketmine.net/
|
|
*
|
|
*
|
|
*/
|
|
|
|
namespace pocketmine\tile;
|
|
|
|
use pocketmine\event\block\SignChangeEvent;
|
|
use pocketmine\level\Level;
|
|
use pocketmine\nbt\tag\CompoundTag;
|
|
use pocketmine\nbt\tag\IntTag;
|
|
use pocketmine\nbt\tag\StringTag;
|
|
use pocketmine\Player;
|
|
use pocketmine\utils\TextFormat;
|
|
|
|
class Sign extends Spawnable{
|
|
|
|
public function __construct(Level $level, CompoundTag $nbt){
|
|
if(!isset($nbt->Text1)){
|
|
$nbt->Text1 = new StringTag("Text1", "");
|
|
}
|
|
if(!isset($nbt->Text2)){
|
|
$nbt->Text2 = new StringTag("Text2", "");
|
|
}
|
|
if(!isset($nbt->Text3)){
|
|
$nbt->Text3 = new StringTag("Text3", "");
|
|
}
|
|
if(!isset($nbt->Text4)){
|
|
$nbt->Text4 = new StringTag("Text4", "");
|
|
}
|
|
|
|
parent::__construct($level, $nbt);
|
|
}
|
|
|
|
public function saveNBT(){
|
|
parent::saveNBT();
|
|
unset($this->namedtag->Creator);
|
|
}
|
|
|
|
public function setText($line1 = "", $line2 = "", $line3 = "", $line4 = ""){
|
|
$this->namedtag->Text1 = new StringTag("Text1", $line1);
|
|
$this->namedtag->Text2 = new StringTag("Text2", $line2);
|
|
$this->namedtag->Text3 = new StringTag("Text3", $line3);
|
|
$this->namedtag->Text4 = new StringTag("Text4", $line4);
|
|
$this->onChanged();
|
|
|
|
return true;
|
|
}
|
|
|
|
public function getText(){
|
|
return [
|
|
$this->namedtag["Text1"],
|
|
$this->namedtag["Text2"],
|
|
$this->namedtag["Text3"],
|
|
$this->namedtag["Text4"]
|
|
];
|
|
}
|
|
|
|
public function getSpawnCompound(){
|
|
return new CompoundTag("", [
|
|
new StringTag("id", Tile::SIGN),
|
|
$this->namedtag->Text1,
|
|
$this->namedtag->Text2,
|
|
$this->namedtag->Text3,
|
|
$this->namedtag->Text4,
|
|
new IntTag("x", (int) $this->x),
|
|
new IntTag("y", (int) $this->y),
|
|
new IntTag("z", (int) $this->z)
|
|
]);
|
|
}
|
|
|
|
public function updateCompoundTag(CompoundTag $nbt, Player $player) : bool{
|
|
if($nbt["id"] !== Tile::SIGN){
|
|
return false;
|
|
}
|
|
|
|
$ev = new SignChangeEvent($this->getBlock(), $player, [
|
|
TextFormat::clean($nbt["Text1"], ($removeFormat = $player->getRemoveFormat())),
|
|
TextFormat::clean($nbt["Text2"], $removeFormat),
|
|
TextFormat::clean($nbt["Text3"], $removeFormat),
|
|
TextFormat::clean($nbt["Text4"], $removeFormat)
|
|
]);
|
|
|
|
if(!isset($this->namedtag->Creator) or $this->namedtag["Creator"] !== $player->getRawUniqueId()){
|
|
$ev->setCancelled();
|
|
}
|
|
|
|
$this->level->getServer()->getPluginManager()->callEvent($ev);
|
|
|
|
if(!$ev->isCancelled()){
|
|
$this->setText(...$ev->getLines());
|
|
return true;
|
|
}else{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
}
|