Look at this code. How to add cooldown to generate stone for this code $gracz->getLevel()->setBlock(new Vector3($blok->getFloorX(), $blok->getFloorY()+1, $blok->getFloorZ()), new Stone()); public function onPlace(BlockPlaceEvent $event){ $blok = $event->getBlock(); $gracz = $event->getPlayer(); $y = $blok->getFloorY(); $x = $blok->getFloorX(); $z = $blok->getFloorZ(); if($blok->getId() == 121){ if(!($event->isCancelled())){ $gracz->getLevel()->setBlock(new Vector3($blok->getFloorX(), $blok->getFloorY()+1, $blok->getFloorZ()), new Stone()); $gracz->sendMessage("• Postawiles stoniarke! •"); $center = new Vector3($x, $y, $z); $particle = new LavaParticle($center); for($yaw = 0, $y = $center->y; $y < $center->y + 3; $yaw += (M_PI * 2) / 20, $y += 1 / 20) { $x = -sin($yaw) + $center->x; $z = cos($yaw) + $center->z; $particle->setComponents($x, $y, $z); } }else{ $gracz->sendMessage("• Nie możesz postawić tutaj stoniarki, ten teren jest zabezpieczony •"); } } }
He said: I was just asking here exactly the same. So much for another chapter. For the first time you see, I thought you knew such things . Would you be interested in co-operation? And by associating this plugin, I have onBreak event and canceled after some time
That's probably because Position::getPlugin() isn't a valid method or attribute, Plugin::getLevel() isn't a valid method or attribute, and that line makes no sense. I assume you are trying to set stone, and since you seem to have tried yourself, you can use this to set a block: PHP: /** @var Position $position */ $this->position->getLevel()->setBlock($this->position, Block::get(Block::STONE); Also, you need to make $position a global variable for use later on. Do that by adding $this->position = $position; under parent::__construct().
You need to remove the ->getPlugin in $this->position->getPlugin->getLevel->setBlock... and add a () right after getLevel. You also need to make $position a global variable in the constructor method. I mentioned how to do that before(basically, do the same thing you did with $plugin). Thanks for clearing that up. I knew Item::get() was the suggested method of constructing an item object, but I see a lot of stuff like "new Obsidian()" around here, so I wasn't sure. I'll edit my post to reflect this.
You should schedule a DelayedTask instead of a RepeatingTask, since you only need to run it once. I suggest using this to schedule the task if you want to make a 3 second delay: PHP: $this->getServer()->getScheduler()->scheduleDelayedTask(new Task($this, $blok), 20 * 3); //20 * 3 = 3 seconds And if you use a delayed task, you won't need to cancel it.
That's because you are cancelling the event. If you cancel the event, the block will be replaced and it won't drop anything.
And then setBlock.. Right? Stone will not appear at all when i remove $evenf->setCanceled()... It is onBreak event
Are you testing it by breaking a stone block that is on top of a block with ID 121? Are there any errors? Do you know if the task runs at all? Try debugging to see.
Wait... Whoooa it WORKS!!!! That You Very Very much for help , i just gave too many ticks, and it was reloading too slow. Thank you!