mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-15 02:09:42 +00:00
Better BlockEntityDataPacket handling
This commit is contained in:
parent
2987c7a80c
commit
c4d4277a6c
@ -32,7 +32,6 @@ use pocketmine\entity\Human;
|
|||||||
use pocketmine\entity\Item as DroppedItem;
|
use pocketmine\entity\Item as DroppedItem;
|
||||||
use pocketmine\entity\Living;
|
use pocketmine\entity\Living;
|
||||||
use pocketmine\entity\Projectile;
|
use pocketmine\entity\Projectile;
|
||||||
use pocketmine\event\block\SignChangeEvent;
|
|
||||||
use pocketmine\event\entity\EntityDamageByBlockEvent;
|
use pocketmine\event\entity\EntityDamageByBlockEvent;
|
||||||
use pocketmine\event\entity\EntityDamageByEntityEvent;
|
use pocketmine\event\entity\EntityDamageByEntityEvent;
|
||||||
use pocketmine\event\entity\EntityDamageEvent;
|
use pocketmine\event\entity\EntityDamageEvent;
|
||||||
@ -2906,28 +2905,12 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
|
|||||||
}
|
}
|
||||||
|
|
||||||
$t = $this->level->getTile($pos);
|
$t = $this->level->getTile($pos);
|
||||||
if($t instanceof Sign){
|
if($t instanceof Spawnable){
|
||||||
$nbt = new NBT(NBT::LITTLE_ENDIAN);
|
$nbt = new NBT(NBT::LITTLE_ENDIAN);
|
||||||
$nbt->read($packet->namedtag, false, true);
|
$nbt->read($packet->namedtag, false, true);
|
||||||
$nbt = $nbt->getData();
|
$nbt = $nbt->getData();
|
||||||
if($nbt["id"] !== Tile::SIGN){
|
if(!$t->updateCompoundTag($nbt, $this)){
|
||||||
$t->spawnTo($this);
|
$t->spawnTo($this);
|
||||||
}else{
|
|
||||||
$ev = new SignChangeEvent($t->getBlock(), $this, [
|
|
||||||
TextFormat::clean($nbt["Text1"], $this->removeFormat), TextFormat::clean($nbt["Text2"], $this->removeFormat), TextFormat::clean($nbt["Text3"], $this->removeFormat), TextFormat::clean($nbt["Text4"], $this->removeFormat)
|
|
||||||
]);
|
|
||||||
|
|
||||||
if(!isset($t->namedtag->Creator) or $t->namedtag["Creator"] !== $this->getRawUniqueId()){
|
|
||||||
$ev->setCancelled();
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->server->getPluginManager()->callEvent($ev);
|
|
||||||
|
|
||||||
if(!$ev->isCancelled()){
|
|
||||||
$t->setText($ev->getLine(0), $ev->getLine(1), $ev->getLine(2), $ev->getLine(3));
|
|
||||||
}else{
|
|
||||||
$t->spawnTo($this);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -21,10 +21,13 @@
|
|||||||
|
|
||||||
namespace pocketmine\tile;
|
namespace pocketmine\tile;
|
||||||
|
|
||||||
|
use pocketmine\event\block\SignChangeEvent;
|
||||||
use pocketmine\level\format\Chunk;
|
use pocketmine\level\format\Chunk;
|
||||||
use pocketmine\nbt\tag\CompoundTag;
|
use pocketmine\nbt\tag\CompoundTag;
|
||||||
use pocketmine\nbt\tag\IntTag;
|
use pocketmine\nbt\tag\IntTag;
|
||||||
use pocketmine\nbt\tag\StringTag;
|
use pocketmine\nbt\tag\StringTag;
|
||||||
|
use pocketmine\Player;
|
||||||
|
use pocketmine\utils\TextFormat;
|
||||||
|
|
||||||
class Sign extends Spawnable{
|
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 true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return CompoundTag
|
|
||||||
*/
|
|
||||||
public abstract function getSpawnCompound();
|
|
||||||
|
|
||||||
public function __construct(Chunk $chunk, CompoundTag $nbt){
|
public function __construct(Chunk $chunk, CompoundTag $nbt){
|
||||||
parent::__construct($chunk, $nbt);
|
parent::__construct($chunk, $nbt);
|
||||||
$this->spawnToAll();
|
$this->spawnToAll();
|
||||||
@ -76,4 +71,22 @@ abstract class Spawnable extends Tile{
|
|||||||
$this->level->clearChunkCache($this->chunk->getX(), $this->chunk->getZ());
|
$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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user