Code: PHP: public function onBlock(BlockBreakEvent $event){ $player = $event->getPlayer(); $block = $event->getBlock() $x = $block->getX(); $y = $block->getY(); $z = $block->getZ(); //$text = "TEXT HERE"; //$block->getLevel()->addParticle(new FloatingTextParticle(new Vector3($x + 0.5, $y + 3, $z + 0.5), "", $text)); $block->getLevel()->setBlockIdAt($x, $y + 1, $z, 55); $player->sendMessage("The chest has been added");} public function onCommand(CommandSender $sender, Command $command, string $label, array $args) : bool{ if($sender instanceof Player){ if($command->getName() == 'addchest'){ $sender->sendMessage("Break a block"); //TODO } } return true; } if the player breaks a block after executing the command alord a chest appears. but only after executing the command
Do you mean that it's supposed to do that and doesn't work, or that it does do that but isn't supposed to? Please explain.
do this, PHP: public $block;public function onBlock(BlockBreakEvent $event){ $player = $event->getPlayer(); if(!isset($this->block[$player->getName()]) return; $block = $event->getBlock() $x = $block->getX(); $y = $block->getY(); $z = $block->getZ(); //$text = "TEXT HERE"; //$block->getLevel()->addParticle(new FloatingTextParticle(new Vector3($x + 0.5, $y + 3, $z + 0.5), "", $text)); $block->getLevel()->setBlockIdAt($x, $y + 1, $z, 55); $player->sendMessage("The chest has been added"); unset($this->block[$player->getName()];} public function onCommand(CommandSender $sender, Command $command, string $label, array $args) : bool{ if($sender instanceof Player){ if($command->getName() == 'addchest'){ $sender->sendMessage("Break a block"); $this->block[$sender->getName()] = true; } } return true; }