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

Using plugin API

Discussion in 'Low-Quality / Outdated' started by Ragnok123, Jan 22, 2017.

  1. Ragnok123

    Ragnok123 Silverfish

    Messages:
    22
    GitHub:
    Ragnok123
    Hello, guys. TodayI will show how to use functions from anotherplugin on your server.
    Firstly, we will get this plugin.
    PHP:
    $this->pl=$this->getServer()->getPluginManager()->getPlugin("MyPlugin");
    Than, for example, want make mysql connections for our plugins.
    And we will make one thing in onEnable() function:
    PHP:
    $this->mysqli=new \mysqli("ip""user""password""database");
    But we know, that some users have limit of mysql connections to mysql database.
    So with this function we can make 1 connection for 2 plugins.
    But how?
    To do this, we must have in second plugin some function, that uses mysql. Example getParticle()
    PHP:
    public function getParticle($player){
       
    $player=strtolower($player);
       
    $result $this->pl->mysqli->query("SELECT FROM `table` WHERE `nick` = "'.$player.'"");
       
    $data=$result->fetch_assoc();
       return 
    $data['particle'];
    }
    That we used mysql function from another plugin to use mysql or second plugin.
     
  2. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    This is not plugin API at all. This is just a way of sharing database instance.
    For real plugin APIs, the getParticle() method should be located in the first plugin. Sharing database instance is not what a plugin API should do.
     
  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.