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

Plugin Path

Comments in 'Plugin Development' started by MrGenga, Oct 2, 2015.

  1. MrGenga
    Offline

    MrGenga Active Member

    Joined:
    Jul 24, 2015
    Posts:
    75
    Minecraft User:
    MrGenga
    Hello! How to get plugin path? Example: (server-path)/plugins/Example.phar
    And.... How to create phar, if phar.readonly is enabled? I can use other websites? :)
  2. FlamingGenius
    Offline

    FlamingGenius Active Member

    Joined:
    Sep 23, 2015
    Posts:
    173
    Minecraft User:
    FlamingGenius
  3. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
  4. MrGenga
    Offline

    MrGenga Active Member

    Joined:
    Jul 24, 2015
    Posts:
    75
    Minecraft User:
    MrGenga
  5. MrGenga
    Offline

    MrGenga Active Member

    Joined:
    Jul 24, 2015
    Posts:
    75
    Minecraft User:
    MrGenga
    I want to the plugin creates phar, аnd I can do this with pmt.mcpe.me
    I think this has other answers..
  6. aliuly
    Offline

    aliuly Notable Member Plugin Developer

    Joined:
    Feb 8, 2014
    Posts:
    1,086
    Plugins:
    17
    In your plugin code:

    PHP:
    $phar $this->getFile();
    Note that getFile is a protected function so only works on your plugin.
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Actually, to get the path of your current running phar, it is simpler to use:

    PHP:
    Phar::running(false)
    Note that it may return something strange if you are not in a phar.
    Last edited: Oct 4, 2015
  8. MrGenga
    Offline

    MrGenga Active Member

    Joined:
    Jul 24, 2015
    Posts:
    75
    Minecraft User:
    MrGenga
    Protected? :( I want to get path of other plugin :(
  9. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    I am not sure, but try this:

    PHP:
    /** @var \pocketmine\plugin\Plugin $plugin */
    $class = new \ReflectionClass($plugin);
    $filename $class->getFilename();
    So, you should be able to find out the phar file by this:
    PHP:
    $path substr($filename7);
    if(
    Utils::getOS() !== "win"$path "/" ltrim($path"/");
    else 
    $path str_replace("\\""/"$path);
    // WINDOWS I HATE YOU
    $truncated $path;
    while(
    true){
      
    $truncated substr($truncated0strrpos($truncated".phar/") + 5);
      if(
    is_file($truncated)) break;
    }
    if(
    is_file($truncated)){
      
    $phar realpath($truncated);
      
    // execute logic
    }else{
      
    // something really wrong has attempted. android.util.Log.wtf
    }
  10. Yoyo95220
    Offline

    Yoyo95220 New Member

    Joined:
    Sep 2, 2015
    Posts:
    8
    Minecraft User:
    Yoyo95220
    PHP:
    $path $this->getServer()->getDataPath() . "plugins/" $pluginName;
  11. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    It may not always be true. Plugins are sometimes loaded from other directories.
  12. Yoyo95220
    Offline

    Yoyo95220 New Member

    Joined:
    Sep 2, 2015
    Posts:
    8
    Minecraft User:
    Yoyo95220
    What directories?
  13. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Anything. For example, you can create a new plugin loader that loads plugins from the internet (or is that PocketMine-Soft?).
  14. aliuly
    Offline

    aliuly Notable Member Plugin Developer

    Joined:
    Feb 8, 2014
    Posts:
    1,086
    Plugins:
    17
  15. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

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

    aliuly Notable Member Plugin Developer

    Joined:
    Feb 8, 2014
    Posts:
    1,086
    Plugins:
    17
  17. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    That's hacky. What if the field name is changed from `file` to something else?

    You can use reflections to make the use of getFile() accessible though, since it is part of the API. But that other plugin has the right to change getFile() into something that does something else, since it is a protected method that is supposed to be used only by that plugin.
  18. aliuly
    Offline

    aliuly Notable Member Plugin Developer

    Joined:
    Feb 8, 2014
    Posts:
    1,086
    Plugins:
    17
    Yes, it is hacky. Then again, anything that works around protections is hacky. The proper way is if that the API were to make that function public.

    BTW, I got this method of obtaining the phar file from DevTools.
  19. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    @shoghicp always loves to hack himself :p

Share This Page

Advertisement