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

Get caller

Comments in 'Plugin Development' started by Primus, Sep 14, 2015.

  1. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Is it possible to get method who called an function for example:

    PHP:
    public function sendName(Player $player){ // line 1
    $player->sendMessage('Your name is: '.$this->getPlayerName($player));
    }

    public function 
    getPlayerName(Player $player){
    return 
    $player->getName();
    echo 
    __CALLER__;
    // __CALLER__ ... Is function from where this function was called from. 
    // outputs ex: Main::sendName(Player $player), at line: 1
    }
  2. EvolSoft
    Offline

    EvolSoft Notable Member Plugin Developer

    Joined:
    Sep 10, 2014
    Posts:
    821
    Plugins:
    15
    Minecraft User:
    Flavius12
    You must call it before getting it. What do you want to do exactly?
  3. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Sometimes in events i got error that is in other method not in $this - scope! i want to know what event has used that function where it crashed. I hope you can understand it :D
  4. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    PHP:
    public function onDeath(...){
    $player $event->getPlayer()->getName(); // I get string to make an error
    $this->owner->isInTeam($player); // Where the error will be shown
    }

    class 
    Main {
    public function 
    isInTeam($player){ // not (Player $player)
    return in_array($player->getName(), $this->gametrue); // ERROR_SOURCE
    }
  5. EvolSoft
    Offline

    EvolSoft Notable Member Plugin Developer

    Joined:
    Sep 10, 2014
    Posts:
    821
    Plugins:
    15
    Minecraft User:
    Flavius12
    You forgot a semicolon on that line
  6. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Dang it :D, but not the problem.
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    EvolSoft, wies and Falk like this.
  8. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV

Share This Page

Advertisement