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{ private function burnBlock(Block $block, int $chanceBound) : void{
if(mt_rand(0, $chanceBound) < $block->getFlammability()){ if(mt_rand(0, $chanceBound) < $block->getFlammability()){
$ev = new BlockBurnEvent($block, $this); $cancelled = false;
$ev->call(); if(BlockBurnEvent::hasHandlers()){
if(!$ev->isCancelled()){ $ev = new BlockBurnEvent($block, $this);
$ev->call();
$cancelled = $ev->isCancelled();
}
if(!$cancelled){
$block->onIncinerate(); $block->onIncinerate();
$world = $this->position->getWorld(); $world = $this->position->getWorld();

View File

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

View File

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