When i break a Block then comes this Error: Code: [Server] Warning: in_array() expects parameter 2 to be array, string given in /storage/emulated/0/PocketMine/plugins/Protector/src/Protector/Main.php on line 32 Here is my Code: PHP: <?phpnamespace Protector;use pocketmine\event\Listener;use pocketmine\plugin\PluginBase;use pocketmine\event\block\BlockBreakEvent;use pocketmine\command\Command;use pocketmine\command\CommandSender;use pocketmine\utils\Config;use pocketmine\utils\TextFormat as C;class Main extends PluginBase implements Listener { public $prefix = C::GRAY. "[". C::RED. "ProtectionManager". C::GRAY. "]". C::WHITE; public $welten = []; public function onEnable() { $this->getLogger()->info($this->prefix. "Lade Plugin"); @mkdir($this->getDataFolder()); $cfg = new Config($this->getDataFolder(). "Config.yml", Config::YAML); if(empty($cfg->get("NoBlockBreak"))){ $cfg->set("NoBlockBreak", "lobby"); } $this->welten = $cfg->get("NoBlockBreak"); $cfg->save(); $this->getServer()->getPluginManager()->registerEvents($this, $this); $this->getLogger()->info($this->prefix. "Plugin geladen"); } public function onBreak(BlockBreakEvent $event) { if(in_array($event->getBlock()->getLevel()->getName(), $this->welten)) { $event->setCancelled(); $player->sendMessage($this->prefix. " Du darfst in der Lobby nichts Abbauen"); } }}
Make sure $this->welten is an array, it seems to be a string currently. Can you also show us your config file?
This is workaround, not a fix! PHP: if(in_array($event->getBlock()->getLevel()->getName(), $this->welten)) { to PHP: if(in_array($event->getBlock()->getLevel()->getName(), [$this->welten], true)) {
How can i make this so? I ve been trying to tap Tap and it will change this to this: Code: --- NoBlockBreak: - lobby ...
No. You're making an array of it. So if it is an array, you're making an array of array, and afaik in_array does not accept the second parameter recursively/doesn't merge its contents automatically.
Just make sure NoBlockBreak is an array in your config if you need help handling arrays in the config, there are alot of threads that have been solved about this question.