<commit_before><?php

declare(strict_types=1);

namespace BlockHorizons\BlockSniper\brush;

use BlockHorizons\BlockSniper\brush\async\BlockSniperChunkManager;
use BlockHorizons\BlockSniper\brush\registration\TypeRegistration;
use BlockHorizons\BlockSniper\exceptions\InvalidBlockException;
use pocketmine\block\Block;
use pocketmine\level\ChunkManager;
use pocketmine\level\Level;
use pocketmine\math\Vector2;
use pocketmine\math\Vector3;
use pocketmine\Server;
use pocketmine\utils\TextFormat;
use function array_rand;
use function strtolower;

abstract class BaseType{

	public const ID = -1;

	public const TYPE_BIOME = 0;
	public const TYPE_CLEAN_ENTITIES = 1;
	public const TYPE_CLEAN = 2;
	public const TYPE_DRAIN = 3;
	public const TYPE_EXPAND = 4;
	public const TYPE_FILL = 5;
	public const TYPE_FLATTEN_ALL = 6;
	public const TYPE_FLATTEN = 7;
	public const TYPE_LAYER = 8;
	public const TYPE_LEAF_BLOWER = 9;
	public const TYPE_MELT = 10;
	public const TYPE_OVERLAY = 11;
	public const TYPE_REPLACE_ALL = 12;
	public const TYPE_REPLACE = 13;
	public const TYPE_SNOW_CONE = 14;
	public const TYPE_TOP_LAYER = 15;
	public const TYPE_TREE = 16;
	public const TYPE_REGENERATE = 17;
	public const TYPE_FREEZE = 18;
	public const TYPE_WARM = 19;
	public const TYPE_HEAT = 20;
	public const TYPE_SMOOTH = 21;

	/** @var int */
	protected $level = 0;
	/** @var \Generator */
	protected $blocks = [];
	/** @var Block[] */
	protected $brushBlocks = [];

	/** @var null|BlockSniperChunkManager */
	protected $chunkManager = null;
	/** @var bool */
	protected $myPlotChecked = false;
	/** @var bool */
	private $async = false;
	/** @var Vector2[][] */
	private $plotPoints = [];

	/**
	 * @param Brush $brush
	 * @param ChunkManager $manager
	 * @param \Generator   $blocks
	 */
	public function __construct(Brush $brush, ChunkManager $manager, \Generator $blocks = null){
		$this->blocks = $blocks;
		if($manager instanceof Level){
			$this->level = $manager->getId();
		}else{
			$this->async = true;
			$this->chunkManager = $manager;
		}
		try{
			$this->brushBlocks = $brush->getBlocks();
		}catch(InvalidBlockException $exception){
			$brush->getPlayer()->sendMessage(TextFormat::RED . $exception->getMessage());
		}
	}

	/**
	 * @param Vector2[][] $plotPoints
	 *
	 * @return \Generator|null
	 */
	public final function fillShape(array $plotPoints = []) : ?\Generator{
		$this->plotPoints = $plotPoints;
		if(!empty($plotPoints)){
			$this->myPlotChecked = true;
		}
		if(($this->async && $this->canBeExecutedAsynchronously()) || !$this->async){
			return $this->fill();
		}
		return null;
	}
<commit_msg>Don't crash getting brush blocks when there aren't any.<commit_after><?php

declare(strict_types=1);

namespace BlockHorizons\BlockSniper\brush;

use BlockHorizons\BlockSniper\brush\async\BlockSniperChunkManager;
use BlockHorizons\BlockSniper\brush\registration\TypeRegistration;
use BlockHorizons\BlockSniper\exceptions\InvalidBlockException;
use pocketmine\block\Block;
use pocketmine\level\ChunkManager;
use pocketmine\level\Level;
use pocketmine\math\Vector2;
use pocketmine\math\Vector3;
use pocketmine\Server;
use pocketmine\utils\TextFormat;
use function array_rand;
use function strtolower;

abstract class BaseType{

	public const ID = -1;

	public const TYPE_BIOME = 0;
	public const TYPE_CLEAN_ENTITIES = 1;
	public const TYPE_CLEAN = 2;
	public const TYPE_DRAIN = 3;
	public const TYPE_EXPAND = 4;
	public const TYPE_FILL = 5;
	public const TYPE_FLATTEN_ALL = 6;
	public const TYPE_FLATTEN = 7;
	public const TYPE_LAYER = 8;
	public const TYPE_LEAF_BLOWER = 9;
	public const TYPE_MELT = 10;
	public const TYPE_OVERLAY = 11;
	public const TYPE_REPLACE_ALL = 12;
	public const TYPE_REPLACE = 13;
	public const TYPE_SNOW_CONE = 14;
	public const TYPE_TOP_LAYER = 15;
	public const TYPE_TREE = 16;
	public const TYPE_REGENERATE = 17;
	public const TYPE_FREEZE = 18;
	public const TYPE_WARM = 19;
	public const TYPE_HEAT = 20;
	public const TYPE_SMOOTH = 21;

	/** @var int */
	protected $level = 0;
	/** @var \Generator */
	protected $blocks = [];
	/** @var Block[] */
	protected $brushBlocks = [];

	/** @var null|BlockSniperChunkManager */
	protected $chunkManager = null;
	/** @var bool */
	protected $myPlotChecked = false;
	/** @var bool */
	private $async = false;
	/** @var Vector2[][] */
	private $plotPoints = [];

	/**
	 * @param Brush $brush
	 * @param ChunkManager $manager
	 * @param \Generator   $blocks
	 */
	public function __construct(Brush $brush, ChunkManager $manager, \Generator $blocks = null){
		$this->blocks = $blocks;
		if($manager instanceof Level){
			$this->level = $manager->getId();
		}else{
			$this->async = true;
			$this->chunkManager = $manager;
		}
		try{
			$this->brushBlocks = $brush->getBlocks();
		}catch(InvalidBlockException $exception){
			$brush->getPlayer()->sendMessage(TextFormat::RED . $exception->getMessage());
			$this->brushBlocks = [Block::get(Block::AIR)];
		}
	}

	/**
	 * @param Vector2[][] $plotPoints
	 *
	 * @return \Generator|null
	 */
	public final function fillShape(array $plotPoints = []) : ?\Generator{
		$this->plotPoints = $plotPoints;
		if(!empty($plotPoints)){
			$this->myPlotChecked = true;
		}
		if(($this->async && $this->canBeExecutedAsynchronously()) || !$this->async){
			return $this->fill();
		}
		return null;
	}

{'fraction_non_alphanumeric': 0.13253012048192772, 'fraction_numerical': 0.015436746987951807, 'mean_word_length': 4.449230769230769, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 36, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '522348', 'n_tokens_mistral': 1967, 'n_tokens_neox': 1778, 'n_words': 444}