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

Plugin crash. incorrect string?

Discussion in 'Development' started by rektpixel, Oct 1, 2017.

  1. rektpixel

    rektpixel Baby Zombie

    Messages:
    186
    Hello, I recently updated my server to pocketmine but a large majority of my plugins are having this error:
    Code:
    Fatal error: Declaration of friends\Main::onCommand(pocketmine\command\CommandSender $sender, pocketmine\command\Command $command, $label, array $args) must be compatible with pocketmine\plugin\PluginBase::onCommand(pocketmine\command\CommandSender $sender, pocketmine\command\Command $command, string $label, array $args): bool in C:\Users\Admin\Creative Cloud Files\Desktop\PrymePE Test Server\plugins\Friends-master\src\friends\main.php on line 15
    
    I have no idea how to fix this, I looked on the forums for a solution but couldn't find anything :/
    this is the friends plugin main.php:
    PHP:
    <?php
    namespace friends;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandExecutor;
    use 
    pocketmine\utils\TextFormat;
    use 
    pocketmine\Player;
    use 
    pocketmine\event\player\PlayerJoinEvent;
    use 
    pocketmine\utils\Config;
    use 
    pocketmine\event\entity\EntityDamageEvent;

    class 
    Main extends PluginBase implements Listener{
        
        public 
    $request = array();
        public function 
    onEnable(){
            
    $this->getLogger()->info("Loaded!");
            
    $this->getServer()->getPluginManager()->registerEvents($this ,$this);
            @
    mkdir($this->getDataFolder());
            @
    mkdir($this->getDataFolder()."players/");
        }
        
    //events
        
    public function onJoin(PlayerJoinEvent $ev){
            if (!
    file_exists($this->getDataFolder()."players/".$ev->getPlayer()->getName().".yml")){
                
    $config = new Config($this->getDataFolder()."players/".strtolower($ev->getPlayer()->getName()).".yml"Config::YAML);
                
    $config->set("friends", array());
                
    $config->save();
            }
        }
        
    //commands
        
    public function onCommand(CommandSender $senderCommand $command$label, array $args){
            switch(
    $command->getName()){
                case 
    "friend":
                if (
    $sender instanceof Player){
                if (isset(
    $args[0])){
                    switch (
    $args[0]){
                        case 
    "add":
                            if (
    $sender->hasPermission("friend.add")){
                            if (isset(
    $args[1])){
                                
    $player $this->getServer()->getPlayer($args[1]);
                                if(!
    $player == null){
                                    
    $this->addRequest($player$sender);
                                }    else {
                                    
    $sender->sendMessage("§c" $args[1] . " §cis not online");
                                }
                            }
                            return ;
                            }{
                                
    $sender->sendMessage(TextFormat::RED."You do not have permission for that command :(");
                            }
                        break;
                        case 
    "remove":
                            if (
    $sender->hasPermission("friend.remove")){
                            if (isset(
    $args[1])){
                                if (
    $this->removeFriend($sender$args[1])){
                                    
    $sender->sendMessage("§c" $args[1] . " §cremoved as your friend");
                                }else{
                                    
    $sender->sendMessage("§cFriend not found do /friend list to list your friends");
                                }
                            }else{
                                
    $sender->sendMessage("§eUsage: /friend remove [name]");
                            }
                            return ;
                            }else{
                                
    $sender->sendMessage(TextFormat::RED."You do not have permission for that command :(");
                            }
                        break;
                        case 
    "list":
                            if (
    $sender->hasPermission("friend.list")){
                            
    $config = new Config($this->getDataFolder()."players/"strtolower($sender->getName()).".yml"Config::YAML);
                            
    $array $config->get("friends", []);
                            
    $sender->sendMessage(TextFormat::GOLD.TextFormat::BOLD."Friends:");
                            foreach (
    $array as $friendname){
                                
    $sender->sendMessage(TextFormat::GREEN."* ".$friendname);
                            }
                            return ;
                            }else {
                                
    $sender->sendMessage(TextFormat::RED."You do not have permission for that command :(");
                            }
                        break;
                        
                    }
                }}else{
            
    $sender->sendMessage("Must use command in-game");
        }
                break;
                case 
    "accept":
                    if (
    $sender->hasPermission("friend.accept")){
                    
    //echo var_dump($this->request);
                    
    if (in_array($sender->getName(), $this->request)){
                        
    //echo "added";
                        
    foreach ($this->request as $target => $requestp){
                            
    $target $this->getServer()->getPlayer($target);
                            
    $requestp $this->getServer()->getPlayer($requestp);
                            echo 
    $target->getName().$requestp->getName();
                            if (
    $requestp->getName() === $sender->getName()){
                                
    //echo "yes";
                                
    $this->addFriend($target$requestp);
                                
    $this->addFriend($requestp$target);
                            }
                            
                        }
                        return ;
                    }else{
                        
    $sender->sendMessage("§cNo pending friend requests");
                    }
                    return ;
                    }else{
                        
    $sender->sendMessage(TextFormat::RED."You do not have permission for that command");
                    }
                break;
            }
        }
        
        
    //api
        
    public function addRequest(Player $target,Player $requestp){
            if (!
    $this->isFriend($requestp$target->getName())){
            
    $requestp->sendMessage("Sent request to ".$target->getName());
            
    $this->request[$requestp->getName()] = $target->getName();
            
    $target->sendMessage(TextFormat::GREEN.$requestp->getName()." has requested you as a friend do /accept to accept or ignore the request");
            echo 
    var_dump($this->request);
             
    $task = new cancelrequest($this$target$requestp);
             
    $this->getServer()->getScheduler()->scheduleDelayedTask($task20*60);
             return ;
            }else{
                
    $requestp->sendMessage("§c".$target->getName." is already your friend");
            }
        }
        
        public function 
    removeRequest(Player $target,Player $requestp$reason){
            if (
    in_array($target->getName(), $this->request)){
                if (
    $reason == 0){
                    
    $requestp->sendMessage("§c".$target->getName()." did not accept your friend request");
                }
                unset(
    $this->request[$requestp->getName()]);
            }
        }
        
        public function 
    addFriend(Player $player,Player $friend){
            
    $player->sendMessage("added friend".$friend->getName());
            
    $friend->sendMessage("added friend ".$player->getName());
            
    $config = new Config($this->getDataFolder()."players/"strtolower($player->getName()).".yml"Config::YAML);
            
    $array $config->get("friends", []);
            
    $array[] = $friend->getName();
            
    $config->set("friends"$array);
            
    $config->save();
            
    $this->removeRequest($friend$player1);
        }
        
        public function 
    removeFriend(Player $player$friendname){
            if (
    $this->isFriend($player$friendname)){
                
    $config = new Config($this->getDataFolder()."players/"strtolower($player->getName()).".yml"Config::YAML);
                
    $array $config->get("friends", []);
                
    $id array_search($friendname$array);
                unset(
    $array[$id]);
                
    $config->set("friends"$array);
                
    $config->save();
                return 
    true;
            }
            return 
    false;
        }
        
        public function 
    isFriend(Player $player$isfriendname){
            
    $config = new Config($this->getDataFolder()."players/"strtolower($player->getName()).".yml"Config::YAML);
            
    $array $config->get("friends", []);
            if (
    in_array($isfriendname$array)){
                return 
    true;
            }
            return 
    false;
        }
    }
     
  2. XdmingXD

    XdmingXD Baby Zombie

    Messages:
    158
    GitHub:
    xdmingxd
    Spot differents
    Easy right?
     
  3. rektpixel

    rektpixel Baby Zombie

    Messages:
    186
    o so..
    PHP:
    public function onCommand(CommandSender $senderCommand $commandstring $label, array $args) : bool {
     
    Last edited: Oct 1, 2017
    jasonwynn10, NickTehUnicorn and Levi like this.
  4. NickTehUnicorn

    NickTehUnicorn Zombie

    Messages:
    200
    GitHub:
    unickorn
    Try and find out yourself!
    Wow. It's correct. You understood it! You might be the first one who asked this AND figured it out himself. I'm surprised.
     
    rektpixel and jasonwynn10 like this.
  5. rektpixel

    rektpixel Baby Zombie

    Messages:
    186
    I'm just a boy making a gr8 network with very little php knowledge XD
     
    jasonwynn10 likes this.
  6. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    Then start learning php now!
     
  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.