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

Help undifined offset 1

Discussion in 'Plugin Help' started by Mochi, Jun 13, 2020.

  1. Mochi

    Mochi Baby Zombie

    Messages:
    113
    [11:00:40] [Server thread/CRITICAL]: ErrorException: "Undefined offset: 1" (EXCEPTION) in "plugins/KartAPI/src/leinne/plugin/kartapi/command/KartCommand" at line 34

    Code:
    PHP:
    public function execute(CommandSender $senderstring $commandLabel, array $args) : void{
            if(!
    $sender instanceof Player || !$this->testPermission($sender)){
                return;
            }
                if(!isset(
    $args[0])) {
                
    $sender->sendMessage("§r§l§b[Automotive Core]§r§f How to use: /$commandLabel <buy|sell>[<name>]");
                return;
            }
            switch (
    $args[0]) { 
                case 
    "buy":
                    
    $kart KartAPI::getInstance()->getKart($args[1]);
                    if(
    $kart === null){
                        
    $sender->sendMessage("§r§l§b[Automotive Core]§r§f It doesn't exist..");
                        return;
                    }
                    
    KartAPI::getInstance()->buyKart($sender$kart);
                    break;
                case 
    "sell":
                    
    KartAPI::getInstance()->sellKart($sender);
                    break;
            }
        }

    }
     
  2. alvin0319

    alvin0319 Creeper

    Messages:
    5
    GitHub:
    alvin0319
    public function execute(CommandSender $sender, string $commandLabel, array $args) : void{
    if(!$sender instanceof Player || !$this->testPermission($sender)){
    return;
    }
    if(!isset($args[0])) {
    $sender->sendMessage("§r§l§b[Automotive Core]§r§f How to use: /$commandLabel <buy|sell>[<name>]");
    return;
    }
    switch ($args[0]) {
    case "buy":
    if(!isset($args[1])){
    $sender->sendMessage("/$commandLabel buy <name>");
    return;
    }
    $kart = KartAPI::getInstance()->getKart($args[1]);
    if($kart === null){
    $sender->sendMessage("§r§l§b[Automotive Core]§r§f It doesn't exist..");
    return;
    }
    KartAPI::getInstance()->buyKart($sender, $kart);
    break;
    case "sell":
    KartAPI::getInstance()->sellKart($sender);
    break;
    }
    }
     
  3. Diduhless

    Diduhless Baby Zombie

    Messages:
    199
    GitHub:
    Diduhless
    Change
    PHP:
    if(!isset($args[0])) {
    to
    PHP:
    if(!isset($args[1])) {
     
  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.