i'm having issues with my code and it's the block isn't breaking after 30 seconds PHP: class EVEvents implements Listener { public function __construct(Main $plugin) { $this->plugin = $plugin; $this->time = 30; } public function onBlockPlace(BlockPlaceEvent $event) { $Player = $event->getPlayer(); $ev = $event->getBlock()->getId(); $block = $event->getBlock(); $x = $block->getX(); $y = $block->getY(); $z = $block->getZ(); $evdamage = $event->getBlock()->getDamage(); if ($ev === 120 || $evdamage === 1) { $Player->addTitle("§8§l[§5!§8]§r§e Opening an Ender Vault §8§l[§5!§8]", "§8§l[§5!§8]§r§7 The ender vault will automatically break after 30 seconds! §8§l[§5!§8]§r"); $block->getLevel()->addParticle(new FloatingTextParticle(new Vector3($x + 0.5, $y + 2.5, $z + 0.5), "", "§8§l[§5!§8] §r§d Rewards §l§8[§5!§8]§r")); } $timer = $this->time--; if ($timer == 30) { $ev = $event->getBlock()->getId(); $block = $event->getBlock(); if ($ev === 120 || $evdamage === 1) { $x = $block->getX(); $y = $block->getY(); $z = $block->getZ(); $pos = new Vector3($x, $y, $z); $replacement = Item::AIR; $level = $Player->getLevel(); $level->setBlock($pos, $replacement, true); $block->getLevel()->addParticle(new FloatingTextParticle(new Vector3($x + 0.5, $y + 2.5, $z + 0.5), "", "")); } } }}
Best Create the Task in Separate Classes and Place the BlockPlaceEvent Function on Proper Main and When Activated Call the Task That in Time Removes the Block in Main.php: public function blockPlace(BlockPlaceEvent $ev){ $b = $ev->getBlock(); if($b->getId() == 120 and $b->getDamage() == 1){ $this->getServer()->getScheduler()->scheduleRepeatingTask(new remove($this, $b), 20); //define name to task *remove.php* return true; } } inTask : public function __construct(Main $pl, $b){ $this->pl = $pl; $this->b = $b; } public $time = 30; public function onRun($tick){ $this->time--; if($this->time == 0){ $b = $this->b; $b->getLevel()->setBlock($b, Block::get(block::AIR)); $this->getServer()->cancelTask($this->getTaskId()); } }