1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Make plugin install plugin

Discussion in 'Development' started by ethaniccc, Apr 18, 2020.

  1. ethaniccc

    ethaniccc Baby Zombie

    Messages:
    189
    GitHub:
    ethaniccc
    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!
     
    HimbeersaftLP likes this.
  2. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    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
     
    ethaniccc likes this.
  3. ethaniccc

    ethaniccc Baby Zombie

    Messages:
    189
    GitHub:
    ethaniccc
    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 :D
     
    Last edited: Apr 18, 2020
    HimbeersaftLP likes this.
  4. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    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...");
            }
        }
     
    ethaniccc likes this.
  5. ethaniccc

    ethaniccc Baby Zombie

    Messages:
    189
    GitHub:
    ethaniccc
    Made your suggested changes, thanks alot :D !
     
    HimbeersaftLP likes this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.