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

Solved Get player ip

Discussion in 'Plugin Help' started by NatanM, Nov 18, 2018.

  1. NatanM

    NatanM Spider

    Messages:
    10
    Hey...

    I must get a player IP, I'm using:
    Code:
    $ip = $player->getPlayer()->getAddress();
    
    or
    Code:
    $ip = $player->getAddress();
    
    but it's crashing
     
  2. Th3Ang3lo

    Th3Ang3lo Spider Jockey

    Messages:
    32
    GitHub:
    Th3Ang3lo
    The first method is correct, the Player must be offline or not found ... Show the error that appears
     
  3. NatanM

    NatanM Spider

    Messages:
    10
    The error is:

     
  4. Th3Ang3lo

    Th3Ang3lo Spider Jockey

    Messages:
    32
    GitHub:
    Th3Ang3lo
    So the player is not being found ... Can I know what's in the $player?
     
  5. NatanM

    NatanM Spider

    Messages:
    10
    It's no necessary, I found the error !
     
  6. Enrico Angelon

    Enrico Angelon Spider Jockey

    Messages:
    37
    GitHub:
    herryyt
    if you have to get player from a event:
    PHP:
            $player $event->getPlayer();

            if(!
    $player->isOnline()) return;

            
    $address $player->getAddress();
    else if you just wanna get player from somewhere that's not a event:
    PHP:
    $player $this->getServer()->getPlayer("PlayerName");

    if (!
    $player->isOnline()) return;

    $address $player->getAddress();
    EDIT: to get the exact player: $this->getServer()->getPlayerExact("PlayerName");
     
  7. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Calling getPlayer() on a player is pointless. Stop using that.
     
  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.