Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Weird Error

Comments in 'Plugin Development' started by Angelo Vidrio, Mar 27, 2015.

  1. Angelo Vidrio
    Offline

    Angelo Vidrio Active Member Plugin Developer

    Joined:
    Jan 16, 2014
    Posts:
    123
    Plugins:
    5
    Minecraft User:
    LilCrispy45
    When I use this code
    PHP:
    public function onPlayerHurt(EntityDamageEvent $event){
            
    $entity $event->getEntity();
            if((
    $entity instanceof Player) && $entity->getPlayer()->getLevel()->getName() == $this->getConfig()->get("SpawnWorld")) {
              
    $event->setCancelled();
            }
            if(isset(
    $this->gamePlayers[$entity->getPlayer()->getName()])) { //<--- Line 919
                
    $event->setCancelled();
            }
        }
    I get this error and it crashes the server when a player joins...help please.
    Code:
    Fatal error: Call to undefined method pocketmine\entity\Item::getPlayer() in C:\Users\Crispeh\Downloads\PocketMine-MP\plugins\bh\src\BlockHunt\Main.php on line 919
    
    LDX likes this.
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    It is $entity not $entity->getPlayer()... If you need I check whether it is a player, use if($entity instanceof Player). Who taught you to do that... :(
  3. Angelo Vidrio
    Offline

    Angelo Vidrio Active Member Plugin Developer

    Joined:
    Jan 16, 2014
    Posts:
    123
    Plugins:
    5
    Minecraft User:
    LilCrispy45
    Ohhh my bad aha thanks, I thought it was like this for some reason. Also,
    PHP:
            if(($entity instanceof Player) && $entity->getPlayer()->getLevel()->getName() == $this->getConfig()->get("SpawnWorld")) { //I CHECK HERE!
    }
  4. Angelo Vidrio
    Offline

    Angelo Vidrio Active Member Plugin Developer

    Joined:
    Jan 16, 2014
    Posts:
    123
    Plugins:
    5
    Minecraft User:
    LilCrispy45
    Ok now im getting
    Code:
    Fatal error: Call to undefined method pocketmine\entity\Item::getName() in C:\Users\Crispeh\Downloads\PocketMine-MP\plugins\bh\src\BlockHunt\Main.php on line 941
    
    And I removed ->getPlayer() :/. I think this is a bug in pocketmine :(
    LDX likes this.
  5. LDX
    Offline

    LDX Notable Member Plugin Developer

    Joined:
    Oct 2, 2013
    Posts:
    1,434
    Plugins:
    14
    PHP:
    public function onPlayerHurt(EntityDamageEvent $event){
            
    $entity $event->getEntity();
            if(!(
    $entity instanceof Player)) {
                return;
            }
            if(
    $entity->getLevel()->getName() == $this->getConfig()->get("SpawnWorld")) {
                
    $event->setCancelled();
            }
            if(isset(
    $this->gamePlayers[$entity->getName()])) {
                
    $event->setCancelled();
            }
        }
    Last edited: Mar 28, 2015
    Angelo Vidrio likes this.
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Why getPlayer()?
    LDX likes this.
  7. LDX
    Offline

    LDX Notable Member Plugin Developer

    Joined:
    Oct 2, 2013
    Posts:
    1,434
    Plugins:
    14
    I just copy/pasted what he had and edited it. I missed that one. I fixed it now. It technically still would have worked, as the Player object has a getPlayer function that returns itself, and by that point in his code, the entity was already confirmed as a player.

Share This Page

Advertisement