Error help

Discussion in 'Development' started by Kyd, May 19, 2017.

  1. Kyd

    Kyd Zombie Pigman

    Messages:
    672
    Im trying to check if player is in array
    Main class:
    PHP:
    /**
    * @param Player $p
    * @return Game
    */
    public function getPlayerArena(Player $p){
        foreach(
    $this->arenas as $arena){
            if(
    $arena->inArena($p)){
                return 
    $arena;
            }
        }
        return 
    false;
    }

    public function 
    onCommand(CommandSender $senderCommand $cmd$label, array $args)
    {
        if (
    $sender instanceof Player){
            
    $arena $this->getPlayerArena($sender);
        switch (
    $cmd->getName()) {
            case 
    'vote':
                if (
    $arena === false) {
                    break;
                }
                if (isset(
    $args[1]) || !isset($args[0])) {
                    
    $sender->sendMessage($this->getPrefix() . TextFormat::GRAY "use /vote [map]");
                    break;
                }
                
    $arena->votingManager->onVote($senderstrtolower($args[0]));
                break;
        }
    }
    }
    inArena function in my Game.php
    PHP:
    /** var Player[] $players */
    public $players = [];

    public function 
    inArena(Player $p){
       if(isset(
    $this->players[strtolower($p->getName())])){
           return 
    true;
       }else{
           return 
    false;
       }
    }
    After I use /vote I get this error
    Code:
    [19:06:40] |CRITICAL| Unhandled exception executing command 'vote Canyon' in vote: Call to a member function inArena() on array
    [19:06:40] |CRITICAL| Error: "Call to a member function inArena() on array" (EXCEPTION) in "/plugins/Annihilation/src/Annihilation/Annihilation" at line 102
     
  2. [deleted]

    [deleted] Guest

    Use in_array() to check if something is in a array.
     
  3. SkySeven

    SkySeven Baby Zombie

    Messages:
    145
    GitHub:
    SkySevenMC
    i think in inArena() , $p is an array, not a string
     
  4. corytortoise

    corytortoise Skeleton

    Messages:
    840
    GitHub:
    corytortoise
    What is $this->arenas? The error implies that when you call $arena->inArena(), $arena is actually an array, not an object.
    1) None of that is true. $p is a Player object.
    2) Nothing implies that $p is a string.
    3) That's not causing the issue.
    From what little information is provided by OP, I gather that he is not checking if something is in an array. He is checking if a value is set for a certain key. isset() works just fine in this case.
     
    jasonwynn10 and [deleted] like this.
  5. Kyd

    Kyd Zombie Pigman

    Messages:
    672
    $this->arenas is game.php
    PHP:
    /** @ var Game $arenas */
      
    public $arenas = [];
     
    Last edited: May 20, 2017
  6. Kyd

    Kyd Zombie Pigman

    Messages:
    672
    I solved I used bad array this must be moved to dev faceplam :D :facepalm: :facepalm: :facepalm: :facepalm: :facepalm:
     
    jasonwynn10 likes this.
  7. CV71-codes

    CV71-codes Spider

    Messages:
    7
    GitHub:
    craveyou-newcoder
    Can Anyone help me with ores pls
     
  8. Levi

    Levi Skeleton

    Messages:
    954
    GitHub:
    captainleviftw
    send code
     
  9. mmm545

    mmm545 Baby Zombie

    Messages:
    100
    GitHub:
    mmm545
    why are you bumping old threads and posting comments on ppl profiles to help you with ores?
     
  10. CV71-codes

    CV71-codes Spider

    Messages:
    7
    GitHub:
    craveyou-newcoder
    Because I am tryna learn how to code Annihilation but I keep getting internal server error and there is barely any Anni posts
     
  11. CV71-codes

    CV71-codes Spider

    Messages:
    7
    GitHub:
    craveyou-newcoder
    this Plugin gives me Internal server error bug TypeError: Return value of
    When I write command
     

    Attached Files:

Share This Page

  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.