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

Solved Unhandled exception Error

Comments in 'Plugin Development' started by ImagicalGamer, Apr 21, 2016.

  1. ImagicalGamer
    Offline

    ImagicalGamer Active Member

    Joined:
    Feb 25, 2016
    Posts:
    141
    Minecraft User:
    ImagicalGamer
    This is the error I'm getting:
    Code:
    [15:11:13] critical> Unhandled exception executing command 'pig remove SwaggyHUD' in pig: Argument 1 passed to pocketmine\plugin\PluginManager::disablePlugin() must implement interface pocketmine\plugin\Plugin, string given, called in C:\Users\Jake\Downloads\ImagicalMine\plugins\Pig-master\src\ImagicalGamer\Pig\Pig.php on line 33 [15:11:13] critical> TypeError: "Argument 1 passed to pocketmine\plugin\PluginManager::disablePlugin() must implement interface pocketmine\plugin\Plugin, string given, called in C:\Users\Jake\Downloads\ImagicalMine\plugins\Pig-master\src\ImagicalGamer\Pig\Pig.php on line 33" (EXCEPTION) in "/src/pocketmine/plugin/PluginManager" at line 648
    This is the code:
    PHP:
    <?php
    namespace ImagicalGamer\Pig;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\scheduler\PluginTask;
    use 
    pocketmine\Server;
    use 
    pocketmine\utils\TextFormat as C;
    use 
    pocketmine\utils\Config;
    class 
    Pig extends PluginBase implements Plugin{
     
      public function 
    onEnable(){
        
    $this->getLogger()->info(C::GREEN "Enabled!");
      }
      public function 
    onCommand(CommandSender $sCommand $cmd$label, array $args){
            if(
    $cmd->getName() == "pig"){
               if(
    $args[0] === "install"){
                 
    copy("http://8.26.94.171/ImagicalGamer/" $args[1], $this->getServer()->getDataPath() . "plugins/" $args[1] . ".phar");
                 
    $s->sendMessage(C::GREEN $args[1] . " Installed Successfully!");
                 
    $path $this->getServer()->getDataPath() . "plugins/" $args[1] . ".phar";
                 
    $plugin $this->getServer()->getPluginManager()->loadPlugin($path);
                 
    $this->getServer()->getPluginManager()->enablePlugin($plugin);
               }
               if(
    $args[0] === "remove"){
                
    $plugin = ($this->getServer()->getDataPath() . "plugins/" $args[1] . ".phar");
                 if(
    file_exists($plugin)){
                   
    $this->getServer()->getPluginManager()->disablePlugin($plugin);
                   
    unlink($this->getServer()->getDataPath() . "plugins/" $args[1] . ".phar");
                   
    $s->sendMessage(C::GREEN $args[1] . " Removed Successfully!");
                 }
                 else{
                   
    $s->sendMessage(C::RED $args[1] . " Does not exist!");
                 }
               }
               if(
    $args[0] === "help"){
                 
    $s->sendMessage(C::GREEN C::BOLD "Pig-Help!" C::RESET C::GREEN "\nInstall: /pig install <PluginName>\nRemove: /pig remove <PluginName>");
               }
            }
         }
       }
    I'm implementing Plugin and I have all the other classes I need, I can't figure out why I keep getting this error.
  2. xiaoq
    Offline

    xiaoq Active Member

    Joined:
    Dec 23, 2014
    Posts:
    232
    Minecraft User:
    xiaoq
    Use
    PHP:
    $this->getServer()->getPluginManager()->disablePlugin($this->getServer()->getPluginManager()->getPlugin($args[1]));
    'must implement interface pocketmine\plugin\Plugin, string given'
    This is pocketmine\plugin\Plugin: $this->getServer()->getPluginManager()->getPlugin($args[1]) This is String $args[1]
    You give string, but it need pocketmine\plugin\Plugin
    HotFireyDeath likes this.
  3. HotFireyDeath
    Offline

    HotFireyDeath Notable Member Plugin Developer

    Joined:
    Mar 19, 2015
    Posts:
    328
    Plugins:
    1
    Minecraft User:
    HotFireyDeath
    When you call $this->getServer()->getPluginManager()->disablePlugin(), it needs a Plugin class, not a string.
    You are simply giving the file name of your plugin as a parameter. What you need is to get your plugin instance, so that it is a Plugin class as the perimeter.

    Implementing Plugin will do nothing to solve your problem.
  4. HotFireyDeath
    Offline

    HotFireyDeath Notable Member Plugin Developer

    Joined:
    Mar 19, 2015
    Posts:
    328
    Plugins:
    1
    Minecraft User:
    HotFireyDeath
    As an example:
    PHP:
    // Example: Turn off "SwaggyHUD".
    $plugin $this->getServer()->getPluginManager()->getPlugin("SwaggyHUD");
    $this->getServer()->getPluginManager()->disablePlugin($plugin);
    ImagicalGamer likes this.
  5. ImagicalGamer
    Offline

    ImagicalGamer Active Member

    Joined:
    Feb 25, 2016
    Posts:
    141
    Minecraft User:
    ImagicalGamer
    Thanks!

Share This Page

Advertisement