1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Hi , i have a error whit my homes

Discussion in 'Plugin Help' started by Ayzrix, Dec 2, 2018.

  1. Ayzrix

    Ayzrix Witch

    Messages:
    66
    GitHub:
    Ayzrix
    Error

    [13:13:47] [Server thread/CRITICAL]: TypeError: "Argument 1 passed to Msg\commands\Home::__construct() must be of the type string, object given, called in /home/Faction(2)/plugins/SkyMsg/src/Msg/SkyMsg.php on line 66" (EXCEPTION) in "SkyMsg/src/Msg/commands/Home" at line 13]

    Here is my code

    <?php
    namespace Msg\commands;
    use pocketmine\command\Command;
    use pocketmine\command\CommandSender;
    use pocketmine\Server;
    use pocketmine\Player;
    use pocketmine\level\Level;
    use pocketmine\level\Position;
    use pocketmine\utils\TextFormat as TX;
    use pocketmine\utils\Config;
    use Msg\SkyMsg;
    class Home extends Command {
    public function __construct(string $name){
    parent::__construct(
    $name,
    "Teleport to your home or See the list of yours homes",
    "/home <nameofthehome-list>",
    ["maison"]
    );
    }


    public function nombreHome(Player $player){
    $main = Main::getInstance();
    if(!file_exists($main->getDataFolder()."/homes/".$player->getName().".yml")) return false;
    $homes = new Config($main->getDataFolder()."/homes/".$player->getName().".yml",Config::YAML);
    return count($homes->getAll());
    }
    public function execute(CommandSender $sender, $command, array $args){
    if(!$sender instanceof Player) return false;
    $main = Main::getInstance();
    $sr = Server::getInstance();
    if (count($args) != 1) return $sender->sendMessage(TX::RED."[EasyServer] Error: ".TX::RESET." Bad usage! Good usage: /home name-of-the-home OR /home list");

    if(!file_exists($main->getDataFolder()."/homes/".$sender->getName().".yml")){
    $sender->sendMessage(TX::RED."[EasyServer] Error:".TX::RESET." It seems that you don't have homes create one with /sethome name");
    return false;
    }
    $homes = new Config($main->getDataFolder()."/homes/".$sender->getName().".yml",Config::YAML);

    if($args[0] == "list" OR $args[0] == "ls" ){
    $lst =$homes->getAll();
    $sender->sendMessage(TX::RED."[EasyServer]: You have ".count($lst)." homes:");
    foreach($lst as $hm){
    $tt = explode("_",$hm);
    $sender->sendMessage("- ".$tt[0]);
    }
    }else{
    if(!$homes->exists($args[0])){
    return $sender->sendMessage(TX::RED."[EasyServer] Error:".TX::RESET."You don't have a home with that name!");
    }
    $all = explode("_",$homes->get($args[0]));
    $x = (float) $all[1];
    $y = (float) $all[2];
    $z = (float) $all[3];
    $level = $sr->getLevelByName($all[4]);
    if(!$level instanceof Level){
    $sender->sendMessage(TX::RED."[EasyServer] Error:".TX::RED." ...I tried ".mt_rand(0,100)." times and the level where your home is don't reply! re-Try later");
    return false;
    }
    $sender->teleport(new Position($x, $y, $z, $level));
    $sender->sendMessage(TX::GREEN."[EasyServer] Welcome back to your home!");
    return true;
    }


    }
    }


     
  2. ZackyVN

    ZackyVN Baby Zombie

    Messages:
    150
  3. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    Look at SkyMsg/src/Msg/SkyMsg.php on line 66, there should be something like new Home(...)
    It requires a string as the first argument but an object is passed to it
     
    corytortoise likes this.
  4. Ayzrix

    Ayzrix Witch

    Messages:
    66
    GitHub:
    Ayzrix
    $this->getServer()->getCommandMap()->register("home", new Home($this));

    But its not working
     
  5. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Pretty easy to understand. Your Home class's constructor requires first parameter to be a string but you fed it a plugin instance. Why?
     
    Diduhless and corytortoise like this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.