Hey Guys....:layer should spawn at special coordinates in a special world! So I wrote this code!:: PHP: public function onJoin(PlayerJoinEvent $event) {$data = new Config($this->getDataFolder() . "config.yml" . strtolower($player->getName()), Config::YAML, array()); $player->teleport(new Position($this->$data->get("lobby_spawn_x"), $this->$data->get("lobby_spawn_y"), $this->$data->get("lobby_spawn_z"), $this->getServer()->getLevelByName($this->$data->get("lobby_spawn_world")))); } ::But i don't understand why it won't work! INFO:: The "config.yml" alreday exist! And insert the config.yml it looks like that: Code: --- loby_spawn_world: McKaff lobby_spawn_x: 134.400000 lobby_spawn_y: 4.000000 lobby_spawn_z: 124.600000 ... __________ This is the Error from the Console when a player join: Code: [18:47:37] [Server thread/CRITICAL]: "Could not pass event 'pocketmine\event\player\PlayerJoinEvent' to 'McKaff_Settings v0.1.0': Object of class pocketmine\utils\Config could not be converted to string on McKaff_Settings\Main [18:47:37] [Server thread/NOTICE]: ClassCastException: "Object of class pocketmine\utils\Config could not be converted to string" (E_RECOVERABLE_ERROR) in "/McKaff_Settings/src/McKaff_Settings/Main" at line 668 _________ Hope you can help..Thx
PHP: $data = new Config($this->getDataFolder() . "config.yml" . strtolower($player->getName()), Config::YAML, array()); ^Do you even know what you're trying to do with this? use this instead: PHP: $data = new Config($this->getDataFolder() . "config.yml", Config::YAML, array()); Also, PHP: $this->$data would give a syntax error. You could simply just use $data directly.
Ok...now I changed a few things,but it won't work.... New Code: PHP: $data = new Config($this->getDataFolder() . "config.yml", Config::YAML, array()); $player->teleport(new Position($data->get("lobby_spawn_x"), $data->get("lobby_spawn_y"), $data->get("lobby_spawn_z"), $data->getServer()->getLevelByName($this->$data->get("lobby_spawn_world")))); Error in the console when a player join: Code: [19:30:02] [Server thread/CRITICAL]: "Could not pass event 'pocketmine\event\player\PlayerJoinEvent' to 'McKaff_Settings v0.1.0': Object of class pocketmine\utils\Config could not be converted to string on McKaff_Settings\Main [19:30:02] [Server thread/NOTICE]: ClassCastException: "Object of class pocketmine\utils\Config could not be converted to string" (E_RECOVERABLE_ERROR) in "/McKaff_Settings/src/McKaff_Settings/Main" at line 668 Hope you can help.Thx
Just use $this->getConfig()->get("lobby_spawn_x"); Make you you save it too. $this->saveDefaultConfig();
PHP: public function onJoin(PlayerJoinEvent $event) {$player = $event->getPlayer();$this->config = new Config($this->getDataFolder() . "config.yml" . Config::YAML, array());$player->teleport(new Position($this->config->get("lobby_spawn_x"), $this->config->get("lobby_spawn_y"), $this->config->get("lobby_spawn_z"), $this->getServer()->getLevelByName($this->config->get("lobby_spawn_world")))); }
Actually, it doesn't cause a syntax error. PHP will attempt to convert $data into a string, then resolve a class property from $this. This is why it shows the message about conversion to string. However, this is not what you are trying to do anyway. Also, not "could simply just use", but you mustn't relate it to $this at all. He is not using a config.yml from the plugin resource folder!
I didn't do that. I mean, he should use $data instead of $this->data because he still use $this->data in his code. Sorry, my English might be bad, so you didn't understand what I mean
Now it Works and there are no ERRORS but it didn't work corectly! The Server Take the false coordinates.... What to Do?