diff --git a/src/matcracker/BedcoreProtect/listeners/PlayerListener.php b/src/matcracker/BedcoreProtect/listeners/PlayerListener.php index 146a9a62..4102034c 100644 --- a/src/matcracker/BedcoreProtect/listeners/PlayerListener.php +++ b/src/matcracker/BedcoreProtect/listeners/PlayerListener.php @@ -133,7 +133,7 @@ public function trackPlayerInteraction(PlayerInteractEvent $event): void $tile = BlockUtils::asTile($clickedBlock); if ($tile instanceof TileItemFrame && $tile->hasItem()) { //I consider the ItemFrame as a fake inventory holder to only log "removing" item. - $this->blocksQueries->addItemFrameLogByPlayer($player, $clickedBlock, $tile->getItem(), Action::REMOVE()); + $this->blocksQueries->addItemFrameLogByPlayer($player, $tile, $tile->getItem(), Action::REMOVE()); } } } elseif ($event->getAction() === PlayerInteractEvent::RIGHT_CLICK_BLOCK) { @@ -161,7 +161,9 @@ public function trackPlayerInteraction(PlayerInteractEvent $event): void $tile = BlockUtils::asTile($clickedBlock); if ($tile instanceof TileItemFrame && !$tile->hasItem() && !$itemInHand->isNull()) { //I consider the ItemFrame as a fake inventory holder to only log "adding" item. - $this->blocksQueries->addItemFrameLogByPlayer($player, $clickedBlock, $itemInHand->setCount(1), Action::ADD()); + $this->blocksQueries->addItemFrameLogByPlayer($player, $tile, $itemInHand->setCount(1), Action::ADD()); + } else { + $this->blocksQueries->addItemFrameLogByPlayer($player, $tile, $tile->getItem(), Action::CLICK()); } } else { $this->blocksQueries->addBlockLogByEntity($player, $clickedBlock, $clickedBlock, Action::CLICK()); diff --git a/src/matcracker/BedcoreProtect/storage/queries/BlocksQueries.php b/src/matcracker/BedcoreProtect/storage/queries/BlocksQueries.php index 6712fb30..5ca5a57e 100644 --- a/src/matcracker/BedcoreProtect/storage/queries/BlocksQueries.php +++ b/src/matcracker/BedcoreProtect/storage/queries/BlocksQueries.php @@ -34,7 +34,6 @@ use matcracker\BedcoreProtect\utils\EntityUtils; use matcracker\BedcoreProtect\utils\Utils; use pocketmine\block\Block; -use pocketmine\block\ItemFrame; use pocketmine\block\Leaves; use pocketmine\entity\Entity; use pocketmine\inventory\InventoryHolder; @@ -43,9 +42,11 @@ use pocketmine\math\Vector3; use pocketmine\Player; use pocketmine\Server; +use pocketmine\tile\ItemFrame; use pocketmine\tile\Tile; use poggit\libasynql\DataConnector; use SOFe\AwaitGenerator\Await; +use function array_map; use function count; use function is_array; use function microtime; @@ -160,19 +161,28 @@ function () use ($name, $oldBlock, $oldNbt, $newBlock, $newNbt, $pos, $worldName */ public function addItemFrameLogByPlayer(Player $player, ItemFrame $itemFrame, Item $item, Action $action): void { - $nbt = BlockUtils::serializeTileTag($itemFrame); + $item = clone $item; + $oldNbt = Utils::serializeNBT($nbt = $itemFrame->saveNBT()); + + $nbt->setTag($item->nbtSerialize(-1, ItemFrame::TAG_ITEM)); + if ($action->equals(Action::CLICK())) { + $nbt->setByte(ItemFrame::TAG_ITEM_ROTATION, ($itemFrame->getItemRotation() + 1) % 8); + } + $newNbt = Utils::serializeNBT($nbt); + + $itemFrameBlock = $itemFrame->getBlock(); $position = $itemFrame->asVector3(); $worldName = $itemFrame->getLevel()->getName(); $time = microtime(true); Await::f2c( - function () use ($player, $itemFrame, $nbt, $position, $worldName, $action, $time) : Generator { + function () use ($player, $itemFrameBlock, $oldNbt, $newNbt, $position, $worldName, $action, $time) : Generator { yield $this->addRawBlockLog( EntityUtils::getUniqueId($player), - $itemFrame, - $nbt, - $itemFrame, - $nbt, + $itemFrameBlock, + $oldNbt, + $itemFrameBlock, + $newNbt, $position, $worldName, $action, @@ -180,7 +190,9 @@ function () use ($player, $itemFrame, $nbt, $position, $worldName, $action, $tim ); }, function () use ($player, $item, $action, $itemFrame): void { - $this->inventoriesQueries->addItemFrameSlotLog($player, $item, $action, $itemFrame); + if (!$action->equals(Action::CLICK())) { + $this->inventoriesQueries->addItemFrameSlotLog($player, $item, $action, $itemFrame); + } } ); } diff --git a/src/matcracker/BedcoreProtect/storage/queries/InventoriesQueries.php b/src/matcracker/BedcoreProtect/storage/queries/InventoriesQueries.php index f27fa7ed..978842b6 100644 --- a/src/matcracker/BedcoreProtect/storage/queries/InventoriesQueries.php +++ b/src/matcracker/BedcoreProtect/storage/queries/InventoriesQueries.php @@ -139,7 +139,6 @@ final protected function addInventorySlotLog(int $logId, int $slot, Item $oldIte */ public function addItemFrameSlotLog(Player $player, Item $item, Action $action, Position $position): void { - $item = clone $item; $worldName = $position->getLevel()->getName(); $time = microtime(true);