hello so am trying to code a home plugin into my core and i cant get the /home , and then a list of homes show up , work :{ if someone can help me please do HomeCommand.php PHP: public function execute(CommandSender $sender, $commandLabel, array $args) { if(isset($args[0])){ $homes = new Config($this->plugin->getDataFolder()."Homes/".$sender->getName().".yml", CONFIG::YAML, array()); $home = $homes->get($args[0]); if($home["world"] instanceof Level){ $sender->setLevel($home["world"]); $sender->teleport(new Vector3($home["x"], $home["y"], $home["z"])); $sender->sendMessage($this->plugin->prefix . "Teleporting to home ".$args[0]."."); } else { $sender->sendMessage($this->plugin->prefix . "This home doesnt exists!"); } } else { $homes = new Config($this->plugin->getDataFolder()."Homes/".$sender->getName().".yml", CONFIG::YAML, array()); foreach($homes as $listed){ $sender->sendMessage($this->plugin->prefix . "Listed Homes: " . $listed . "."); } } }} this works just fine i just get this error, Code: 08.06 18:32:28 [Server] INFO Notice: Array to string conversion in /plugins/VortexCore/src/TB/VortexCore/commands/HomeCommand.php on line 39
For the second time, you can't store a level object directly in a file. That means $home["world"] will NEVER be an instanceof Level, because it's a string (I assume/hope) you put in. There's also no point in constructing a new config object for every single action you do with it. Could you point out where line 39 is?
Maybe PHP: $level = $this->getLevel($home["world"]); // now an instance of Level$sender->setLevel($level); ?
No-o. You can only use getLevel() if you have a level ID, which you do not. Instead use $server->getLevelByName($name) as I mentioned before.
PHP: public function execute (CommandSender $sender, $commandLabel, array $args) { $homes = new Config($this->plugin->getDataFolder() . "Homes/" . $sender->getName() . ".yml", Config::YAML); if (isset($args[0])) { $home = $homes->get($args[0]); if ($this->plugin->getServer()->getLevelByName($home["world"]) instanceof Level) { $sender->teleport(new Position($home["x"], $home["y"], $home["z"], $home["world"])); $sender->sendMessage($this->plugin->prefix . "Teleporting to home " . $args[0] . "."); } else { $sender->sendMessage($this->plugin->prefix . "This home doesn't exist!"); } } else { $listedHomes = array(); foreach ($homes->getAll() as $name => $values) { $listedHomes[] = $name; } $sender->sendMessage($this->plugin->prefix . "Your homes: " . implode(", ", $listedHomes)); } }}