public function onExplosion(EntityExplodeEvent $event)
{
$levelName = $event->getEntity()->getLevel()->getName();
if (!$this->plugin->isLevelLoaded($levelName)) {
return;
}
$plot = $this->plugin->getPlotByPosition($event->getPosition());
if ($plot === null) {
$event->setCancelled(true);
return;
}
$beginPos = $this->plugin->getPlotPosition($plot);
$endPos = clone $beginPos;
$plotSize = $this->plugin->getLevelSettings($levelName)->plotSize;
$endPos->x += $plotSize;
$endPos->z += $plotSize;
$blocks = array_filter($event->getBlockList(), function ($block) use($beginPos, $endPos) {
if ($block->x >= $beginPos->x and $block->z >= $beginPos->z and $block->x < $endPos->x and $block->z < $endPos->z) {
return true;
}
return false;
});
$event->setBlockList($blocks);
}