I want to know how to break certain block and get a popup that says # has been added to your account. Also when block is broken turns to obsidian. Now after a while block turns back to it's original block. I still a noob at coding and I would like to know
Register an Event Listener class which implements Listener. Create a function within the class with a single argument for BlockBreakEvent. Within the created function, add an if statement which checks if the block broken's id matches the block you want broken (also be sure to check the damage for meta-specific blocks like wool with color). If the ids and damages match, then use the Player::sendPopup() function to send a message to the player in the form of a popup. Make sure you access that function by getting the Player instance from BlockBreakEvent::getPlayer(); Please show proof of a previous attempt before asking for code
In your main PHP file: PHP: use pocketmine\event\block\BlockBreakEvent; // don’t forget to add the needed classes (and register the Listener)use pocketmine\command\ConsoleCommandSender;public function onBreak(BlockBreakEvent $event) { $player = $event->getPlayer(); $block = $event->getBlock(); if($block->getId() . ":" . $block->getDamage() === "1:6") { // "1:6" = Polished Obsidian, <ID>:<meta> $this->getServer()->getScheduler()->scheduleDelayedTask(new BlockReplaceTask($this, $block), 1200); // runs the ’BlockReplaceTask‘ after 1,200 ticks (60 seconds/1 minute) $block->getLevel()->setBlock($block, Block::OBSIDIAN, true, true); // replaces the block by Obsidian $this->getServer()->dispatchCommand(new ConsoleCommandSender(), "givemoney " . $player->getName() . " 10"); // gives the player 10 $player->sendMessage("Added " . $block->getName() . " (" . $block->getId() . ":" . $block->getDamage() . ") has been added."); // just use ’sendPopup()‘ or ’sendTip()‘ instead of ’sendMessage()‘ if you want }} Your file (’BlockReplaceTask‘ in the code above): PHP: public $block;public function __construct(Main $main, Block $block) { $this->main = $main; $this->block = $block; parent::__construct($main);}public function onRun(int $tick) { $block = $this->block; $level = $block->getLevel(); $level->setBlock($block->getX(), $block->getY(), $block->getZ(), $block, true, true); // replaces the Obsidian by old block’s version (1:6, Polished Obsidian)}