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

Questions about the API

Comments in 'Plugin Development' started by Jordan Waughtal, Jan 28, 2014.

  1. Jordan Waughtal
    Offline

    Jordan Waughtal New Member

    Joined:
    Jan 28, 2014
    Posts:
    7
    Minecraft User:
    Thewafflication
    Hello all. I am new here.
    My first question is: how can I access a public function defined in one of the <Namehere>API.php files from a plugin.
    For instance, how would I access the harm function defined in the entilietyAPI.php file from a plugin.

    My second question is what is the order of inheritance in the api.
    This may answer the first question.
    (More questions to come...)
  2. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,707
    Plugins:
    22
    Minecraft User:
    Falkirknh
    You can access all public API functions using:
    $this->api->{NAME}->{FUNCTION}({PARAMS});
  3. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Not the exact answer. The name of the api is defined at lines 199-207 at ServerAPI.php
    If you make a plugin's api like economys, you can also define ir like this.

    And @Falk, there is no any rules on the plugin development that you must have a field called api in a plugin. For instance, I like to use, like in function init(), I like to write:
    PHP:
    $s=ServerAPI:: request ();
    $c=$s->api->console;
    $s->schedule...
    $s->addHandler...
    $c->register...
    xktiverz likes this.
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    I am pointing this out just to remind people not to use $this->api when they are working with multiple classes.
  5. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,707
    Plugins:
    22
    Minecraft User:
    Falkirknh
    Sorry, I was going to write a bit about that but I figured that most developers stick with $this->api, clearly I am wrong :)
    PEMapModder likes this.
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    What? There are no any relationship between APIs, except that Server API contains fields of other APIs.
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Anyway whatever u mean, there is no API extending another.
  8. Jordan Waughtal
    Offline

    Jordan Waughtal New Member

    Joined:
    Jan 28, 2014
    Posts:
    7
    Minecraft User:
    Thewafflication
    Another question

    why does
    PHP:
            $po[] = $this->api->player->online();
            echo 
    $po[0];
    Return:
    Arrary
  9. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,707
    Plugins:
    22
    Minecraft User:
    Falkirknh
    Because $po is an array, and you need to use a foreach if you want to echo an array.
  10. Jordan Waughtal
    Offline

    Jordan Waughtal New Member

    Joined:
    Jan 28, 2014
    Posts:
    7
    Minecraft User:
    Thewafflication
    Now with this:
    PHP:
            $po[] = $this->api->player->online();
            echo 
    $po[0];
            foreach(
    $po as $key => &$pyr){
                echo 
    $pyr;
                }
            unset(
    $pyr);
            echo 
    "\n";
    I get ArrayArray.
    What am I doing wrong?
    I don't use php often.
  11. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Use implode()
  12. Jordan Waughtal
    Offline

    Jordan Waughtal New Member

    Joined:
    Jan 28, 2014
    Posts:
    7
    Minecraft User:
    Thewafflication
    now with
    Code:
                    $po[] = $this->api->player->online();
            echo "".implode($po, "',");
            echo "\n";
    returns
    Array
  13. xktiverz
    Offline

    xktiverz Active Member

    Joined:
    Dec 20, 2013
    Posts:
    61
    Minecraft User:
    64FF00
    Yup! :D
  14. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Why don't you use $this->api->player->getAll()? This will return an array of online Player objects.
    xktiverz likes this.
  15. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,707
    Plugins:
    22
    Minecraft User:
    Falkirknh
    I think he just wants a list of usernames though.
  16. Jordan Waughtal
    Offline

    Jordan Waughtal New Member

    Joined:
    Jan 28, 2014
    Posts:
    7
    Minecraft User:
    Thewafflication
    So
    $po[] = $this->api->player->getAll();
    echo $po[0];
    echo "\n";
    returns
    Array

Share This Page

Advertisement