Skip to content

Commit

Permalink
Fixed #78
Browse files Browse the repository at this point in the history
  • Loading branch information
matcracker committed Nov 17, 2023
1 parent 717848e commit 7cb5f4f
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/matcracker/BedcoreProtect/storage/queries/BlocksQueries.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,18 @@ function () use ($entity, $oldBlocks, $oldBlocksNbt, $action, $time): void {
/** @var string[]|null[] $newBlocksNbt */
$newBlocksNbt = [];

$validatePosition = $oldBlocks[0]->getPosition();
if (!$validatePosition->isValid()){
$this->plugin->getLogger()->debug("Invalid block position, the world has been unloaded.");
return;
}

$world = $validatePosition->getWorld();
$worldName = $world->getFolderName();

foreach ($oldBlocks as $key => $oldBlock) {
$pos = $oldBlock->getPosition();
$newBlock = $pos->getWorld()->getBlockAt($pos->x, $pos->y, $pos->z);
$newBlock = $world->getBlockAt($pos->x, $pos->y, $pos->z);
if ($newBlock->isSameState($oldBlock)) {
unset($oldBlocks[$key], $oldBlocksNbt[$key]);
} else {
Expand All @@ -197,22 +206,20 @@ function () use ($entity, $oldBlocks, $oldBlocksNbt, $action, $time): void {
ArrayUtils::resetKeys($oldBlocks, $oldBlocksNbt);

Await::g2c(self::getMutex()->runClosure(
function () use ($entity, $oldBlocks, $oldBlocksNbt, $newBlocks, $newBlocksNbt, $action, $time): Generator {
function () use ($entity, $oldBlocks, $oldBlocksNbt, $newBlocks, $newBlocksNbt, $worldName, $action, $time): Generator {
yield from $this->entitiesQueries->addEntity($entity);

yield from $this->connector->asyncGeneric(QueriesConst::BEGIN_TRANSACTION);
$generators = [];
foreach ($oldBlocks as $key => $oldBlock) {
$oldPosition = $oldBlock->getPosition();

$generators[] = $this->addRawBlockLog(
EntityUtils::getUniqueId($entity),
$oldBlock,
$oldBlocksNbt[$key],
$newBlocks[$key],
$newBlocksNbt[$key],
$oldPosition->asVector3(),
$oldPosition->getWorld()->getFolderName(),
$oldBlock->getPosition(),
$worldName,
$action,
$time
);
Expand Down

0 comments on commit 7cb5f4f

Please sign in to comment.