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

Command to function

Discussion in 'Development' started by Vaxrp, Oct 27, 2017.

  1. Vaxrp

    Vaxrp Witch

    Messages:
    73
    GitHub:
    Vaxrp
    How can I set the command to edit the $args I set up most of it I just dont know what to use to edit the args.

    PHP:
    class Main extends PluginBase implements Listener{

      public function 
    onEnable() {
         
    $this->getServer()->getPluginManager()->registerEvents($this,$this);      
      }
     
      public function 
    onCommand(CommandSender $senderCommand $cmdstring $label, array $args): bool {
          if(
    $cmd == "Knockback"){
           
       
      }
     
      public function 
    onDamage(EntityDamageEvent $event){
        
    $event->getEntity()->setMotion(new Vector3($args[0],$args[1]],0.3));
      }
    }
     
  2. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    btw, I suggest you go learn php first.
    anyways here's the "solution" (temporary, not saved to disk currently)
    PHP:
    class Main extends PluginBase implements Listener{
      private 
    $args = [11]; //default vals
      
    public function onEnable() {
         
    $this->getServer()->getPluginManager()->registerEvents($this,$this);     
      }
     
      public function 
    onCommand(CommandSender $senderCommand $cmdstring $label, array $args): bool {
          if(
    $cmd->getName() == "knockback"){
                if(
    is_numeric($args[0]) && is_numeric($args[1]) & is_numeric($args[2])){
                    
    $this->args $args;
                }
          }
      }
     
      public function 
    onDamage(EntityDamageEvent $event){
        
    $event->getEntity()->setMotion(new Vector3($this->args[0],$this->args[1]],0.3));
      }
    }
     
    jasonwynn10 and Muqsit like this.
  3. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    And also int-cast the args.
    PHP:
    array_map("intval"$args);
     
    jasonwynn10 likes 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.