mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-13 05:15:13 +00:00
BlockPlaceEvent: use BlockTransaction, closes #1760
BlockPlaceEvent no longer extends BlockEvent, since it's now a multi-block event getBlockReplaced() is removed getTransaction() is added to be honest, BlockPlaceEvent should be something like PlayerBlockPlaceEvent...
This commit is contained in:
parent
92896c78da
commit
cbaff1caec
@ -26,24 +26,24 @@ namespace pocketmine\event\block;
|
|||||||
use pocketmine\block\Block;
|
use pocketmine\block\Block;
|
||||||
use pocketmine\event\Cancellable;
|
use pocketmine\event\Cancellable;
|
||||||
use pocketmine\event\CancellableTrait;
|
use pocketmine\event\CancellableTrait;
|
||||||
|
use pocketmine\event\Event;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\player\Player;
|
use pocketmine\player\Player;
|
||||||
|
use pocketmine\world\BlockTransaction;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a player places a block
|
* Called when a player initiates a block placement action.
|
||||||
|
* More than one block may be changed by a single placement action, for example when placing a door.
|
||||||
*/
|
*/
|
||||||
class BlockPlaceEvent extends BlockEvent implements Cancellable{
|
class BlockPlaceEvent extends Event implements Cancellable{
|
||||||
use CancellableTrait;
|
use CancellableTrait;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
protected Player $player,
|
protected Player $player,
|
||||||
Block $blockPlace,
|
protected BlockTransaction $transaction,
|
||||||
protected Block $blockReplace,
|
|
||||||
protected Block $blockAgainst,
|
protected Block $blockAgainst,
|
||||||
protected Item $item
|
protected Item $item
|
||||||
){
|
){}
|
||||||
parent::__construct($blockPlace);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the player who is placing the block.
|
* Returns the player who is placing the block.
|
||||||
@ -59,8 +59,15 @@ class BlockPlaceEvent extends BlockEvent implements Cancellable{
|
|||||||
return clone $this->item;
|
return clone $this->item;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getBlockReplaced() : Block{
|
/**
|
||||||
return $this->blockReplace;
|
* Returns a BlockTransaction object containing all the block positions that will be changed by this event, and the
|
||||||
|
* states they will be changed to.
|
||||||
|
*
|
||||||
|
* This will usually contain only one block, but may contain more if the block being placed is a multi-block
|
||||||
|
* structure such as a door or bed.
|
||||||
|
*/
|
||||||
|
public function getTransaction() : BlockTransaction{
|
||||||
|
return $this->transaction;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getBlockAgainst() : Block{
|
public function getBlockAgainst() : Block{
|
||||||
|
@ -2051,7 +2051,7 @@ class World implements ChunkManager{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if($player !== null){
|
if($player !== null){
|
||||||
$ev = new BlockPlaceEvent($player, $hand, $blockReplace, $blockClicked, $item);
|
$ev = new BlockPlaceEvent($player, $tx, $blockClicked, $item);
|
||||||
if($player->isSpectator()){
|
if($player->isSpectator()){
|
||||||
$ev->cancel();
|
$ev->cancel();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user