By default a player has disabled the BlockBreakEvent: PHP: public function onBreak(BlockBreakEvent $event) { $name = $event->getPlayer()->getName(); if(!in_array($name, $this->buildmode)) { $event->setCancelled(); } } I tried to make the event to enable and disable with a command but my code doesn't work: PHP: public function onCommand(CommandSender $sender, Command $command, string $label, array $args) : bool{ $name = $sender->getName(); $this->buildmode[] = $name; if ($cmd->getName() == "build" && $sender->hasPermission("permission.build")) { if (!in_array($name, $this->buildmode)) { $sender->sendMessage($this->prefix . TextFormat::GREEN . "You can build now."); } else { unset($this->buildmode[array_search($name, $this->buildmode)]); $sender->sendMessage($this->prefix . TextFormat::RED . "You can't build anymore."); } } }}
Be more specific on 'what does not work. But anyhow, you have Code: this->buildmode[] = $name; inside the onCommand (very first beginning), Which means that the player name would always be in the array, so checking it has no point.
I made it better. Forgot to update the $cmd to $command (from the ALPHA7 and higher you need to change that). Now how to make the event to get enabled? PHP: public function onCommand(CommandSender $sender, Command $command, string $label, array $args) : bool{ $name = $sender->getName(); $this->buildmode[] = $name; if ($command->getName() == "build" && $sender->hasPermission("permission.build")) { if (!in_array($name, $this->buildmode)) { $sender->setGamemode(1); $sender->sendMessage($this->prefix . TextFormat::GREEN . "You can build now."); } else { unset($this->buildmode[array_search($name, $this->buildmode)]); $sender->sendMessage($this->prefix . TextFormat::RED . "You can't build anymore."); } } }
PHP: $event->setCancelled(false); That's wrong. Since PocketMine API 3.0.0-ALPHA7 you need to add a bool typehint to your onCommand() method. You can set the parameter variable names to anything you want. This is also valid: PHP: public function onCommand(CommandSender $commandSender, Command $commandRan, string $commandLabel, array $commandArguments) : bool{ Keep an eye out for updates to the CommandExecutor interface and you will not get in problems.