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

[New API]How to load another PHP?

Comments in 'Plugin Development' started by steveng, Jun 28, 2014.

  1. steveng
    Offline

    steveng New Member Plugin Developer

    Joined:
    Feb 5, 2014
    Posts:
    29
    Plugins:
    1
    Devtools use
    PHP:
            $this->getServer()->getPluginManager()->registerInterface("FolderPluginLoader\\FolderPluginLoader");
            
    $this->getServer()->getPluginManager()->loadPlugins($this->getServer()->getPluginPath(), array("FolderPluginLoader\\FolderPluginLoader"));
            
    $this->getServer()->enablePlugins(PluginLoadOrder::STARTUP);
    to load FolderPluginLoader.How can I load another php file in the \src folder?For example,my main file is in \src\test,I want to load test2.php in \src\test\api
    Can someone help me?Thanks
    Last edited: Jun 28, 2014
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    1. Name your files according to their class names and namespaces.
    2. Mention the name of your class. SPL auto loader will load it automatically.

    OR (not sure they will approve a plugin that uses this)

    PHP:
    require_once(dirname(__FILE__)."test2.php");
    Also, DevTools does NOT use that at all.
    steveng and BlinkSun like this.
  3. BlinkSun
    Offline

    BlinkSun Active Member Plugin Developer

    Joined:
    Mar 26, 2014
    Posts:
    128
    Plugins:
    4
    Minecraft User:
    BlinkSun
    The real issue is about the 2. from @PEMapModder my guess ! SPL ll autoload it and ll try to consider it like a plugins itself and maybe ll crash because your test2.php ll not have the regular plugin functions to handle it !
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    When you load a plugin, PocketMine will register another source path (phar://MyPlugin.phar/src/) to SPL class loader and then when you mention the class name my\plugin\Test, if this class doesn't already exist, SPL will try to laod from each registered source path (phar://PocketMine-MP.phar/src/my/plugin/Test.php, which doesn't exist; phar://MyPlugin.phar/src/my/plugin/Test.php, which should exist in your plugin). If there is none that matches, then it will generate the RuntimeException:
    This avoids the potential crashing for multiple plugins that use the same library with the same class name, but that library is the same one.
  5. steveng
    Offline

    steveng New Member Plugin Developer

    Joined:
    Feb 5, 2014
    Posts:
    29
    Plugins:
    1
    So,I should use such as "use test\api\test2" to let SPL load text2.php,is that right?
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    It will only affect compile time. First, what is in test2.php?
  7. steveng
    Offline

    steveng New Member Plugin Developer

    Joined:
    Feb 5, 2014
    Posts:
    29
    Plugins:
    1
    $this->getServer()->getLogger->info
  8. steveng
    Offline

    steveng New Member Plugin Developer

    Joined:
    Feb 5, 2014
    Posts:
    29
    Plugins:
    1
    It doesn't work
  9. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    What is the content in test2.php and test.php?
  10. steveng
    Offline

    steveng New Member Plugin Developer

    Joined:
    Feb 5, 2014
    Posts:
    29
    Plugins:
    1
    Eh,this is just a example.My plugin has APIs,Modules,just like PocketFactions.I want to use a loader to load all modules,APIs.You can use $this->API->plugin->load to load a file.I don't know how to load a file in new API.
  11. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Are you talking about old API or new API?
  12. steveng
    Offline

    steveng New Member Plugin Developer

    Joined:
    Feb 5, 2014
    Posts:
    29
    Plugins:
    1
    New API
    bad English:D
  13. MinecrafterJPN
    Offline

    MinecrafterJPN Active Member Plugin Developer

    Joined:
    Aug 26, 2013
    Posts:
    154
    Plugins:
    9
    Minecraft User:
    MinecrafterJPN
    Use "namespace"
    steveng likes this.
  14. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Then there isn't "$this->API"...
  15. steveng
    Offline

    steveng New Member Plugin Developer

    Joined:
    Feb 5, 2014
    Posts:
    29
    Plugins:
    1
    Sorry,mistakes there.I mean $this->api->plugin->load were used to load plugins in old api.I don't know whats that in new api.I'll try namespsce and such as "use".
  16. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,707
    Plugins:
    22
    Minecraft User:
    Falkirknh
  17. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Look at PluginManager.php
    steveng likes this.
  18. steveng
    Offline

    steveng New Member Plugin Developer

    Joined:
    Feb 5, 2014
    Posts:
    29
    Plugins:
    1
    I'll check it out.Thanks.
  19. steveng
    Offline

    steveng New Member Plugin Developer

    Joined:
    Feb 5, 2014
    Posts:
    29
    Plugins:
    1
    And how to get all Tile::SIGNs?
  20. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    $pos->getLevel()->getTile($pos)

    here.

Share This Page

Advertisement