BlockPlaceEvent: ensure that getPosition() is always correct

since BlockTransaction was designed to be World-agnostic, it can't position() any blocks, since Position requires a World.

This workaround is the best we can do for now; however, it would probably be wise to deprecate getTransaction() in favour of a dedicated getBlocks() method which takes care of this, as BlockPlaceEvent is currently quite obnoxious to use.
This commit is contained in:
Dylan K. Taylor 2023-06-21 15:36:48 +01:00
parent 391732f00c
commit 9d0d60afd1
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -43,7 +43,12 @@ class BlockPlaceEvent extends Event implements Cancellable{
protected BlockTransaction $transaction, protected BlockTransaction $transaction,
protected Block $blockAgainst, protected Block $blockAgainst,
protected Item $item protected Item $item
){} ){
$world = $this->blockAgainst->getPosition()->getWorld();
foreach($this->transaction->getBlocks() as [$x, $y, $z, $block]){
$block->position($world, $x, $y, $z);
}
}
/** /**
* Returns the player who is placing the block. * Returns the player who is placing the block.