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

Solved How to provide an plugin API

Comments in 'Plugin Development' started by Tim // robske Büba, Dec 19, 2015.

  1. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    I have one plugin with that cmd:
    PHP:
    switch($command->getName())
         {
      case 
    "spawn":
               {
      
    $mapname "world";
      
    $sender->getPlayer()->sendMessage("[rBServer] Teleportiere zum Spawn");
               }
      
    //Prevents most crashes
      
    if(Server::getInstance()->loadLevel($mapname) != false)
               {
      
    $sender->getPlayer()->teleport(Server::getInstance()->getLevelByName($mapname)->getSafeSpawn()); //$sender->teleport($this->main->getServer()->getDefaultLevel()->getSpawnLocation());
      
    }
               else
               {
      
    $sender->getPlayer()->sendMessage("[CRITICAL_ERROR] ERR_005_sp_'".$mapname."' DAS IST EIN KRITISCHER FEHLER! BITTE REPORTE IHN UMGEHEND AUF http://robskebueba.de.tl/PSR.htm");
      }              
      return 
    true;   
         }
    And I have another plugin that handles effects, I want to provide an api for the other plugin like

    On command in first plugin:
    call(PlayerIssuedSpawnCommand,$sender)

    On call PlayerIssuedSpawnCommand in the other plugin
    get(PlayerIssuedSpawnCommand,$sender)
    ...
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Make your command implementation into an independent public function (with proper parameters passed). Then you can call that function directly from the other plugin.
  3. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    public function onCommand(CommandSender $sender, Command $command, $label, array $args){
    like that?

    //realy nooby in php
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Just look at the source code of DevTools, how it handles commands.

    https://github.com/PocketMine/DevTools/blob/master/src/DevTools/DevTools.php#L59

    If the functions become public, then they are what you are looking for.



    I just reread your posts, and this doesn't seem to be what you are looking for. Can you state your purpose of making this, for example, what you want to achieve in these plugins?
  5. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    Ok, i tried to use that:
    (Will now provide full codes for better understanding)
    PHP:
      public function onCommand(CommandSender $senderCommand $command$label, array $args){
      switch(
    $command->getName())
         {
      case 
    "spawn":
               {
      
    $mapname "world";
      
    $sender->getPlayer()->sendMessage("[rBServer] Teleportiere zum Spawn");
               }
      
    //Prevents most crashes
      
    if(Server::getInstance()->loadLevel($mapname) != false)
               {
      
    $sender->getPlayer()->teleport(Server::getInstance()->getLevelByName($mapname)->getSafeSpawn()); //$sender->teleport($this->main->getServer()->getDefaultLevel()->getSpawnLocation());
      
    return $this->spawnCommand($sender$command$label$args);
      }
               else
               {
      
    $sender->getPlayer()->sendMessage("[CRITICAL_ERROR] ERR_005_sp_'".$mapname."' DAS IST EIN KRITISCHER FEHLER! BITTE REPORTE IHN UMGEHEND AUF http://robskebueba.de.tl/PSR.htm");
      }             
      return 
    true;  
         }
    }
    and in the other plugin:
    PHP:
    public function spawnCommand(CommandSender $senderCommand $command$label, array $args){
    //code
    }
    Now, when i issue /spawn it says:
    Call to undefined method robske\SignPortal\Main::spawnCommand()
  6. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    Still didn't figured out how to do this
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Define spawnCommand in the first plugin. $this means the current class you're writing the code in, so why would you put the function in another plugin?

Share This Page

Advertisement