Hi. Should this code work? PHP: if ($cmd->getName() == "sethome"){ if (isset($args[0]) and !( isset($args[1]))){ if ($sender->hasPermission("homes.sethome." . $args[0]) || $sender->hasPermission("homes") || $sender->hasPermission("homes.sethome")){ $name = $args[0]; $info = array($sender->getX(), $sender->getY(), $sender->getZ(), $sender->getLevel()); $this->cfg->set($name, $info); } else {$sender->sendMessage(TextFormat::DARK_RED . "You haven't got permission");}return false;}break;if ($cmd->getName() == "home"){ if (isset($args[0] and !(isset($args[1]))){ if ($sender->hasPermission("homes") || $sender->hasPermission("homes.home") || $sender->hasPermission("homes.home.".$args[0])){ $name = $args[0]; $a = $this->cfg->get($name); $sender->setLevel($a[3]); $sender->teleport(new Vector3($a[0], $a[1], $a[2]);}else {$sender->sendMessage(TextFormat::DARK_RED."You haven't got permission");}return false;}break;}
So "replace": PHP: $lv = $sender->getLevel()->getName():$sender->setLevel($this->getServer()->getLevelByName($lv)); ?
Don't use setLevel. Use teleport instead, with the first parameter being a Position object containing the target level.
Also, what are you doing? You are setting the player's level to the player's current level? What's the point of that?
It's home plugin. onCommand /sethome <home>, I get players level and x,y,z and write it into config (homes.yml). onCommand /home <home> player is teleported to x,y,z,level from config
Then why did you use $sender->getLevel()? I asked you to save the name in the config, not to search levels by name -_-
These are how I do to my code to save something into array PHP: $tmp = $this->getConfig()->getAll();$tmp[$name]["x"] = $player->x;$tmp[$name]["y"] = $player->y;$tmp[$name]["z"] = $player->z;$tmp[$name]["world"] = $player->getLevel()->getName();$this->getConfig()->setAll($tmp);$this->getConfig()->save(); To get 'x', PHP: $tmp = $this->getConfig()->getAll();return $tmp[$name]["x"];
Code: hoyinm14mc: x: 123 y: 123 z: 123 world: survival Pemapmodder: x: 256 y: 0 z: 256 world: survival KelvinKamHK: x: 0 y: 1 z: 2 world: Factions GBernard2000: x: 3 y: 2 z: 1 world: Creative ...