So I decided to work as a plugin developer for another server just for fun, and he wants me to make a ShopGUI. At first, I was going about it, then I thought about something. I asked the owner if he/she was using EconomyAPI and when he said no I got shaken, because all the other plugins the other developers he/she hired also were making plugins that depended on it. I want to see if there is any way to install plugins through another plugin, so I don't have to deal with the stubborn owner. Thank you so much in advance!
Sure you can, just download a phar from Poggit using a preferred method (file_get_contents, curl, BulkCurlTask) and save it to the plugins folder, then force stop the server so the owner has to restart it
Thank you so much! After doing some Google searches, I found a way to install plugins using file_get_contents, here is my code: PHP: private $forced = false; public function onEnable(){ Server::getInstance()->getLogger()->info(TextFormat::GREEN . "ShopUI by TheSacrafice (@ethaniccc) has been enabled!"); $this->loadCommands(); $this->getScheduler()->scheduleDelayedTask(new ClosureTask(function(int $currentTick) : void{ $economy = Server::getInstance()->getPluginManager()->getPlugin("EconomyAPI"); if($economy === null || $economy->isDisabled()){ $this->forced = true; Server::getInstance()->getLogger()->error("EconomyAPI is not installed on the server! Attempting to install!"); $download = file_get_contents('https://poggit.pmmp.io/r/34531/EconomyAPI.phar'); if($download === false){ Server::getInstance()->getLogger()->emergency("EconomyAPI failed to install! Disabling ShopUI!"); Server::getInstance()->getPluginManager()->disablePlugin($this); } else { file_get_contents('https://poggit.pmmp.io/r/34531/EconomyAPI.phar'); $filename = 'plugins/EconomyAPI.phar'; $save = file_put_contents($filename, $download); if($save === false){ Server::getInstance()->getLogger()->emergency("EconomyAPI failed to install! Disabling ShopUI!"); Server::getInstance()->getPluginManager()->disablePlugin($this); } else { file_put_contents($filename, $download); } } //Server::getInstance()->getPluginManager()->disablePlugin($this); } }), 60); if(!InvMenuHandler::isRegistered()){ InvMenuHandler::register($this); } } public function onDisable(){ Server::getInstance()->getLogger()->warning("ShopUI by TheSacrafice (@ethaniccc) has been disabled!"); if($this->forced === true){ Server::getInstance()->getLogger()->info(TextFormat::GREEN . "EconomyAPI has been installed on the server! Please wait a few seconds..."); } } Forgot to shutdown the server, but it still works
PHP: private $forced = false; public function onEnable(){ Server::getInstance()->getLogger()->info(TextFormat::GREEN . "ShopUI by TheSacrafice (@ethaniccc) has been enabled!"); $this->loadCommands(); $this->getScheduler()->scheduleDelayedTask(new ClosureTask(function(int $currentTick) : void{ // why did you put it in a task? $economy = Server::getInstance()->getPluginManager()->getPlugin("EconomyAPI"); if($economy === null || $economy->isDisabled()){ $this->forced = true; Server::getInstance()->getLogger()->error("EconomyAPI is not installed on the server! Attempting to install!"); $download = file_get_contents('https://poggit.pmmp.io/r/34531/EconomyAPI.phar'); if($download === false){ Server::getInstance()->getLogger()->emergency("EconomyAPI failed to install! Disabling ShopUI!"); Server::getInstance()->getPluginManager()->disablePlugin($this); } else { file_get_contents('https://poggit.pmmp.io/r/34531/EconomyAPI.phar'); // why are you downloading it again $filename = 'plugins/EconomyAPI.phar'; // I recommend using Server->getPluginPath() instead $save = file_put_contents($filename, $download); if($save === false){ Server::getInstance()->getLogger()->emergency("EconomyAPI failed to install! Disabling ShopUI!"); Server::getInstance()->getPluginManager()->disablePlugin($this); } else { file_put_contents($filename, $download); // why are you saving it again? } } //Server::getInstance()->getPluginManager()->disablePlugin($this); } }), 60); if(!InvMenuHandler::isRegistered()){ InvMenuHandler::register($this); } } public function onDisable(){ Server::getInstance()->getLogger()->warning("ShopUI by TheSacrafice (@ethaniccc) has been disabled!"); if($this->forced === true){ Server::getInstance()->getLogger()->info(TextFormat::GREEN . "EconomyAPI has been installed on the server! Please wait a few seconds..."); } }