Better BlockEntityDataPacket handling

This commit is contained in:
Dylan K. Taylor
2016-11-28 10:38:56 +00:00
parent 2987c7a80c
commit c4d4277a6c
3 changed files with 54 additions and 29 deletions

View File

@ -2,11 +2,11 @@
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* 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
@ -15,16 +15,19 @@
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*
*/
namespace pocketmine\tile;
use pocketmine\event\block\SignChangeEvent;
use pocketmine\level\format\Chunk;
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{
@ -82,4 +85,30 @@ class Sign extends Spawnable{
]);
}
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;
}
}
}