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

How to get Full Plugin Name

Comments in 'Plugin Development' started by korado531m7, Dec 12, 2015.

  1. korado531m7
    Offline

    korado531m7 Active Member

    Joined:
    Apr 4, 2015
    Posts:
    158
    Minecraft User:
    korado531m7
    Hi. Sorry for my too many threads...
    I want to use get plugin full name.
    I wrote codes, but it didn't get FULL NAME.

    Ex, Plugin : test_v1.0.0.phar

    PHP:
    $this->getServer()->getPluginManager()->getPlugin("test")->getFullName();
    It result:
    test v1.0.0

    It's not all plugin name.
    please how to get, thank you for answering.
  2. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    that's the full name.. then how do you want it to be? o_O
    *sigh* create as much threads you want.
  3. korado531m7
    Offline

    korado531m7 Active Member

    Joined:
    Apr 4, 2015
    Posts:
    158
    Minecraft User:
    korado531m7
    I want to get 'test_v1.0.0.phar'.
    It is impossible?
  4. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    that's the file name of the plugin.. but ok
    PHP:
    echo str_replace(" ""_"$this->getServer()->getPluginManager()->getPlugin("test")->getFullName()) . ".phar";
  5. korado531m7
    Offline

    korado531m7 Active Member

    Joined:
    Apr 4, 2015
    Posts:
    158
    Minecraft User:
    korado531m7
    Thank you. It worked!
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    PHP:
    $file = (new \ReflectionClass($this->getServer()->getPluginManager()->getPlugin("test")))->getFilename();
    $pos strrpos($file".phar");
    $pharPath substr($file0$pos 5);
    What if the file isn't named as its version?
    HotFireyDeath likes this.
  7. wolfdale
    Offline

    wolfdale Active Member Plugin Developer

    Joined:
    Dec 3, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    ace
    Or this
    PHP:
    $plugin $this->getServer()->getPluginManager()->getPlugin("test");
    if(
    $plugin->isPhar()) $file $plugin->getFile();
    else echo 
    plugin is not in phar;
  8. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    getFile() is a protected function, not a public function.

    I think you can get it from another PluginBase's context though.
  9. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    Yeah, you should tell him about ReflectionClass.
  10. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Alright, getFile works, but it must be called from your main class.
    Screenshot_2015-12-13-13-26-41.png

    Class A represents PluginBase class. Class B represents the other plugin. Class C represents a call from your PluginBase. Class D is a control set to show that outside it won't work.
    Last edited: Dec 13, 2015
  11. wolfdale
    Offline

    wolfdale Active Member Plugin Developer

    Joined:
    Dec 3, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    ace
    I didn't know that :p
    Now i know :p
  12. korado531m7
    Offline

    korado531m7 Active Member

    Joined:
    Apr 4, 2015
    Posts:
    158
    Minecraft User:
    korado531m7
    Thank you for answering!
    I created new plugin!

Share This Page

Advertisement