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

commands

Discussion in 'Development' started by Teamblocket, Jun 3, 2017.

  1. Teamblocket

    Teamblocket Zombie

    Messages:
    301
    GitHub:
    teamblocket
    how can i do /hi <player> and send the message to the player given?
     
  2. Thouv

    Thouv Slime

    Messages:
    84
    GitHub:
    adeynes
    PHP:
    public function onCommand(CommandSender $senderCommand $cmd$label, array $args)
    {
        if(
    $cmd->getName() === "hi"// checks that the command is /hi
        
    {
            if(isset(
    $args[0])) // check that <player> was given
            
    {
                
    $sendTo $this->getServer()->getPlayer($args[0])
                if(
    $sendTo !== null && $sendTo->isOnline()) // check that the given player is online
                
    {
                    
    $sendTo->sendMessage("your message goes here")
                } else
                {
                    
    $sender->sendMessage(TextFormat::WHITE$args[0] .TextFormat::RED." is not online!")
                }
            } else
            {
                
    $sender->sendMessage(TextFormat::RED."Please specify a player!")
            }
        }
    }
    In the future, please show what you've tried to do, because it won't help you if we just give you code and you don't try :)
     
    Teamblocket likes this.
  3. Teamblocket

    Teamblocket Zombie

    Messages:
    301
    GitHub:
    teamblocket
     
  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.