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

Developer API

Comments in 'Plugin Development' started by JackboyPlay, Feb 9, 2016.

  1. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    How can I add a developer API to my plugin like on Economy?
  2. xBeastMode
    Offline

    xBeastMode Active Member

    Joined:
    Nov 27, 2015
    Posts:
    292
    Now if you know proper php, you can do YourClassAPI::getInstance()->whatEverFunction()
    PHP:
    private static $instance;//instance
    public function onLoad(){
    self::$instance $this;//your plugin class
    }
    public static function 
    getInstance(){
    return 
    self::$instance;//get class
    }
    applqpak and Vaivez66 like this.
  3. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    As @PEMapModder previously told me, that is a kind of bad practice :p
    AndrewBit and HotFireyDeath like this.
  4. xBeastMode
    Offline

    xBeastMode Active Member

    Joined:
    Nov 27, 2015
    Posts:
    292
    He wanted an api, "like on Economy" by @onebone . Like when you do EconomyAPI::getInstance()->addMoney("dot", 1);. The other way is $this->getServer()->getPluginManager()->getPlugin("YourPluginName")->whatEverFunction();
    ;)
  5. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Does he want to USE an API or MAKE one.
  6. Exxarion
    Offline

    Exxarion Active Member Plugin Developer

    Joined:
    Jan 5, 2014
    Posts:
    242
    Plugins:
    1
    Minecraft User:
    Notch
    Do not use ::getInstance. That is some bad practice right there.
  7. xBeastMode
    Offline

    xBeastMode Active Member

    Joined:
    Nov 27, 2015
    Posts:
    292
    That's why I said he can get the plugin directly, I know it is much faster than static functions/methods. Either way, there are still ways to make an API.
  8. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
  9. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay

Share This Page

Advertisement