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

TypeError: "Return value of MarcosDEV\TopWins\Main::onCommand() must be of the type boolean, none re

Discussion in 'Plugin Help' started by Mochi, Jun 14, 2019.

  1. Mochi

    Mochi Baby Zombie

    Messages:
    113
    Error line 82
    Code :
    PHP:
        public function onCommand(CommandSender $senderCommand $cmd$lbl, array $args):bool{
            if(
    $cmd->getName() == "topfarm"){
                
    $item Item::get(Item::STICK01);
                
    $item->setCustomName("§r§7TopFarm MAGIC");
                
    $sender->getInventory()->addItem($item);
                
    $sender->sendMessage("§9[ §6MARCOS §9]§7 Varinha adiciona ao seu inventário");
            }
        }
    public function onCommand(CommandSender $sender, Command $cmd, $lbl, array $args):bool{
    if($cmd->getName() == "topfarm"){
    $item = Item::get(Item::STICK, 0, 1);
    $item->setCustomName("§r§7TopFarm MAGIC");
    $sender->getInventory()->addItem($item);
    $sender->sendMessage("§9[ §6MARCOS §9]§7 Varinha adiciona ao seu inventário");
    }
    }
     
  2. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    Add a return true at the last line of the function
     
  3. Swourire

    Swourire Spider Jockey

    Messages:
    49
    GitHub:
    swourire
    No, no and no.
    return statement stops the execution of a function.
    when onCommand is returned false, it sends the usage.

    So, at the end return false, so if the if condition is not met it sends the usage.
    After "$sender->sendMessage("§9[ §6MARCOS §9]§7 Varinha adiciona ao seu inventário");", add a return true.
     
  4. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    PHP:
        public function onCommand(CommandSender $senderCommand $cmd$lbl, array $args):bool{
            if(
    $cmd->getName() == "topfarm"){
                
    $item Item::get(Item::STICK01);
                
    $item->setCustomName("§r§7TopFarm MAGIC");
                
    $sender->getInventory()->addItem($item);
                
    $sender->sendMessage("§9[ §6MARCOS §9]§7 Varinha adiciona ao seu inventário");
            }
            return 
    true;
        } 
     
  5. Swourire

    Swourire Spider Jockey

    Messages:
    49
    GitHub:
    swourire
    Read what I said, stop pasting code and you don’t understand.
     
  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.