I want to limit the amount of tnt that can be placed near each other in an amount of block radius to prevent lag.
Simple and short answer: Store all TNT coordinates, then when a TNT is placed, search your stored coordinates to see if there were TNTs nearby. Make sure you delete them with BlockBreakEvent. Long and optimized answer: Index the coordinates by clusters, probably in different files. When a player places a TNT, check for all TNTs in the nearby clusters. The best size of a "cluster" is a cube of r*r*r blocks (or r*256*r blocks if r is not very small), where r is comparable to your "nearby" definition. For example, if TNTs have to be at least 10 blocks away from each other, each cluster can be 8*8*8 lage or 16*16*16 large. When a TNT is placed, divide ach coordinate by 16 and take the floor value (i.e. bitshift the integer 4 times to the right), and store it in a list file of such coordinates. When you check for nearby blocks, you only need to load the nearby files (don't just load the exact file, because a TNT block can be in the adjacent cluster).
To store blocks placed save number of placed blocks to array Example: PHP: /** @var array $break */public $break = array();public function onPlace(BlockPlaceEvent $e){ $p = $e->getPlayer(); if(!isset($this->break[strtolower($p->getName())])){ $this->break[strtolower($p->getName())] = 0; return false; } $this->break[strtolower($p->getName())]++; if($this->break[strtolower($p->getName())]) >= 20){ $e->setCancelled(); $p->sendMessage("You reached limit!"); }}