mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-07 02:08:21 +00:00
Better BlockEntityDataPacket handling
This commit is contained in:
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -46,11 +46,6 @@ abstract class Spawnable extends Tile{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return CompoundTag
|
||||
*/
|
||||
public abstract function getSpawnCompound();
|
||||
|
||||
public function __construct(Chunk $chunk, CompoundTag $nbt){
|
||||
parent::__construct($chunk, $nbt);
|
||||
$this->spawnToAll();
|
||||
@ -76,4 +71,22 @@ abstract class Spawnable extends Tile{
|
||||
$this->level->clearChunkCache($this->chunk->getX(), $this->chunk->getZ());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return CompoundTag
|
||||
*/
|
||||
public abstract function getSpawnCompound();
|
||||
|
||||
/**
|
||||
* Called when a player updates a block entity's NBT data
|
||||
* for example when writing on a sign.
|
||||
*
|
||||
* @param CompoundTag $nbt
|
||||
* @param Player $player
|
||||
*
|
||||
* @return bool indication of success, will respawn the tile to the player if false.
|
||||
*/
|
||||
public function updateCompoundTag(CompoundTag $nbt, Player $player) : bool{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user