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

Solved adding a usage message on command

Discussion in 'Development' started by rektpixel, Jan 7, 2018.

  1. rektpixel

    rektpixel Baby Zombie

    Messages:
    186
    Hello, I have this code from a friend plugin which I'm trying to edit into a party plugin
    PHP:
        public function onCommand(CommandSender $senderCommand $command$label, array $args) : bool{
            switch(
    $command->getName()){
                case 
    "friend":
                if (
    $sender instanceof Player){
                    if (isset(
    $args[0])){
                        switch (
    $args[0]){
                            case 
    "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");
                                }
                            }else{
                                
    $sender->sendMessage("§eUsage: /friend add [name]");
                            }
                        break;
                        case 
    "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]");
                            }
                        break;
                        case 
    "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);
                            }
                        break;
                      
                    }
                }}else{
            
    $sender->sendMessage("Must use command in-game");
        }
                break;
                case 
    "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);
                            }
                          
                        }
                    }else{
                        
    $sender->sendMessage("§cNo pending friend requests");
                    }
            }
            return 
    true;
        }
    What I'm trying to do is add a usage message such as $sender->sendMessage("showing friend commands") when the player types /friend I don't know where it goes :/ help
     
  2. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    PHP:
    }}else{
    $sender->(no pending)
    Should be changed to
    PHP:
    }else{
        
    $sender->sendMessage(“Showing friend commands”);
    }else{
    ... (
    no pending)
     
    rektpixel likes this.
  3. rektpixel

    rektpixel Baby Zombie

    Messages:
    186
    thanks :)
     
  4. iCirgio

    iCirgio Slime

    Messages:
    92
    GitHub:
    lolnova
    Please put [Solved] tag thank you :)
     
  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.