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 get the file name of an plugin?

Comments in 'Plugin Development' started by Survingo, Jul 23, 2016.

  1. Survingo
    Offline

    Survingo Active Member

    Joined:
    Dec 6, 2015
    Posts:
    221
    Hello community,

    I want to code an Auto Updater for pugins.
    Everything is alright, but I can't find an way to get the file name of the current running plugin to unlink() it, like plugin-856.phar or InvClear_v6.9.0.phar.
    Is there a way to do that dynamicly?

    Thanks,
    S~
  2. MCPEPIG
    Offline

    MCPEPIG Notable Member

    Joined:
    Jun 22, 2014
    Posts:
    349
    Minecraft User:
    MCPEPIG
    Survingo likes this.
  3. SOFe
    Offline

    SOFe Banned

    Joined:
    May 28, 2016
    Posts:
    386
    Minecraft User:
    Herobrine
    Don't try to delete the currently running phar! If you have to load new classes from your plugin after that, the server may crash! In the auto loading mechanism in PocketMine, some classes may not be loaded even though the server is still running.
    And replacing the files won't cause the current classes to be unloaded! Without restarting a server, your classes will still be there, and new classes won't be auto loaded!

    Also, if you just want to delete yourself, try Phar::running(true).
    PocketKiller likes this.
  4. Survingo
    Offline

    Survingo Active Member

    Joined:
    Dec 6, 2015
    Posts:
    221
    But who said that I try to delete a running phar and that I don't restart the server?
  5. SOFe
    Offline

    SOFe Banned

    Joined:
    May 28, 2016
    Posts:
    386
    Minecraft User:
    Herobrine
    Even if you restart the server immediately, there is still a shutdown period that new classes might be loaded. Even if a plugin is disabled, there may still be things running on another thread.

    Aren't you asking about the file name of a plugin, which means a plugin being loaded? And then you want to unlink() it? Then doesn't that mean you want to delete a phar currently running? Even if the plugin is no longer running, as long as it has been loaded in that runtime, something might still go wrong.

    Also, beware opcache!

Share This Page

Advertisement