Use Event::hasHandlers() for a few more hot events

This commit is contained in:
Dylan K. Taylor 2023-08-09 15:45:15 +01:00
parent a5d8ef7a6c
commit 447f061566
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
3 changed files with 24 additions and 12 deletions

View File

@ -145,9 +145,13 @@ class Fire extends BaseFire{
private function burnBlock(Block $block, int $chanceBound) : void{
if(mt_rand(0, $chanceBound) < $block->getFlammability()){
$ev = new BlockBurnEvent($block, $this);
$ev->call();
if(!$ev->isCancelled()){
$cancelled = false;
if(BlockBurnEvent::hasHandlers()){
$ev = new BlockBurnEvent($block, $this);
$ev->call();
$cancelled = $ev->isCancelled();
}
if(!$cancelled){
$block->onIncinerate();
$world = $this->position->getWorld();

View File

@ -116,10 +116,15 @@ class Leaves extends Transparent{
public function onRandomTick() : void{
if(!$this->noDecay && $this->checkDecay){
$ev = new LeavesDecayEvent($this);
$ev->call();
$cancelled = false;
if(LeavesDecayEvent::hasHandlers()){
$ev = new LeavesDecayEvent($this);
$ev->call();
$cancelled = $ev->isCancelled();
}
$world = $this->position->getWorld();
if($ev->isCancelled() || $this->findLog($this->position)){
if($cancelled || $this->findLog($this->position)){
$this->checkDecay = false;
$world->setBlock($this->position, $this, false);
}else{

View File

@ -972,14 +972,17 @@ class World implements ChunkManager{
$block = $replacement;
}
$ev = new BlockUpdateEvent($block);
$ev->call();
if(!$ev->isCancelled()){
foreach($this->getNearbyEntities(AxisAlignedBB::one()->offset($x, $y, $z)) as $entity){
$entity->onNearbyBlockChange();
if(BlockUpdateEvent::hasHandlers()){
$ev = new BlockUpdateEvent($block);
$ev->call();
if($ev->isCancelled()){
continue;
}
$block->onNearbyBlockChange();
}
foreach($this->getNearbyEntities(AxisAlignedBB::one()->offset($x, $y, $z)) as $entity){
$entity->onNearbyBlockChange();
}
$block->onNearbyBlockChange();
}
$this->timings->scheduledBlockUpdates->stopTiming();