Skip to content

Commit

Permalink
Fixed ItemFrame not correctly logged.
Browse files Browse the repository at this point in the history
  • Loading branch information
matcracker committed Jun 4, 2020
1 parent 8141db0 commit 01ffeb1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
6 changes: 4 additions & 2 deletions src/matcracker/BedcoreProtect/listeners/PlayerListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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());
Expand Down
28 changes: 20 additions & 8 deletions src/matcracker/BedcoreProtect/storage/queries/BlocksQueries.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -160,27 +161,38 @@ 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,
$time
);
},
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);
}
}
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 01ffeb1

Please sign in to comment.