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

Error with my function

Discussion in 'Development' started by DanielYTK, Feb 10, 2017.

  1. DanielYTK

    DanielYTK Zombie

    Messages:
    227
    Error:
    Code:
    [19:01:46] [Server thread/CRITICAL]: "Could not pass event 'pocketmine\event\block\BlockPlaceEvent' to 'Admin v1': Call to undefined method pocketmine\Player::isAdmin() on DanielYTK\Coder\code
    [19:01:46] [Server thread/CRITICAL]: Error: "Call to undefined method pocketmine\Player::isAdmin()" (EXCEPTION) in "/Admin/src/DanielYTK/Coder/code" at line 173
     
    Code:
    PHP:
    public function aoQuebrar(BlockPlaceEvent $ev){
        
    $player $ev->getPlayer();
        
    $id $ev->getBlock()->getId();
        if(
    $player->isAdmin()){
            if(
    $id === 101){
                
    $ev->setCancelled(true);
            }
        }
     }
     
    Function isAdmin():
    PHP:
    public function isAdmin(Player $p){
        if(isset(
    $this->admin[$p->getName()])){
            return 
    true;
        }
     }
     
     
  2. DanielYTK

    DanielYTK Zombie

    Messages:
    227
    The line 173 is:
    PHP:
     if($player->isAdmin()) 
     
  3. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    You need to do $this->isAdmin($player) not $player->isAdmin();
    unless you encapsulate isadmin inside a custom player class that expands on player
     
  4. DanielYTK

    DanielYTK Zombie

    Messages:
    227
    Haaa THX
     
  5. SkySeven

    SkySeven Baby Zombie

    Messages:
    145
    GitHub:
    SkySevenMC
    replace
    PHP:
    $player->isAdmin()
    by

    PHP:
    $this->isAdmin($p)
     
  6. SkySeven

    SkySeven Baby Zombie

    Messages:
    145
    GitHub:
    SkySevenMC
    PHP:
    public function aoQuebrar(BlockPlaceEvent $ev){
        
    $p $ev->getPlayer();
        
    $id $ev->getBlock()->getId();
        if(
    $this->isAdmin($p)){
            if(
    $id === 101){
                
    $ev->setCancelled(true);
            }
        }
     }
     
  7. DanielYTK

    DanielYTK Zombie

    Messages:
    227
    if id has Custom Name, it's is problem?
     
  8. DanielYTK

    DanielYTK Zombie

    Messages:
    227
    All is working perfect, but $ev->setCancelled() no .-.
     
  9. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    try var_dump()ing the ID
    AND STOP USING HARDCODED IDS.
     
    Jack Noordhuis 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.