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

Error in my plugin

Comments in 'Plugin Development' started by Edgar_SM, Jan 13, 2015.

  1. Edgar_SM
    Offline

    Edgar_SM New Member

    Joined:
    Oct 11, 2014
    Posts:
    20
    Minecraft User:
    evermine
    Please help
    Pocketmine Error:
    [CRITICAL] ClassNotFoundException: "Class serverrestart not found" (EXCEPTION) in "/src/spl/BaseClassLoader" at line 122

    Plugin.yml
    Code:
    name: ServerRestart
    main: serverrestart/Loader
    version: 1.0
    api: [1.9.0, 1.10.0, 1.11.0]
    load: STARTUP
    author: evermine
    description: Restarts your server .
    commands:
    sr:
      description: "Set Restart Time"
      permission: sr.command.asr
    restart:
      description: "Check Restart Time"
      permission: sr.command.restart
    permissions:
    asr.command.asr:
      description: "Usage: /setrestart <value>"
      default: op
    asr.command.restart:
      description: "Usage: /restart"
      default: true
    Loader.php
    PHP:
    <?php

    namespace edgar\serverrestart;

    use 
    pocketmine\Server;
    use 
    pocketmine\Player;

    use 
    pocketmine\scheduler\CallbackTask;

    use 
    pocketmine\plugin\PluginBase;

    use 
    pocketmine\utils\Config;
    use 
    pocketmine\utils\TextFormat;

    class 
    Loader extends PluginBase{

        private 
    $count_down 60//secs
        
    public $time_count = array();

        public function 
    onEnable(){
            
    //Commands
            
    $this->getCommand("sr")->setExecutor(new Commands($this));
            
    $this->getCommand("restart")->setExecutor(new Commands($this));
            
    //Task
            
    $this->initial_start(2);
            
    $this->loadConfigurations();
        }
       
        
    /***************************
        *==========================*
        *====[ External APIs ]=====*
        *==========================*
        ***************************/
       
        
    public function setValueTimer($value){
            
    $this->preferences->set("TimeToRestart"$value);
            
    $this->preferences->save();
        }
       
        public function 
    getTimer(){
            if(isset(
    $this->time_count['time'])){
                return 
    $this->time_count['time'];
            }else{
                
    $this->setTimer($this->restart_time"mins.");
                return 
    $this->time_count['time'];
            }
        }
       
        public function 
    setTimer($time$offset){
            if(isset(
    $this->time_count['time'])){
                unset(
    $this->time_count['time']);
                
    $this->time_count['time'] = "$time $offset";
            }else{
                
    $this->time_count['time'] = "$time $offset";
            }
        }

        
    /*************************
        *========================*
        *====[ Plugin APIs ]=====*
        *========================*
        *************************/
       
        
    public function initial_start($timer){
        
    /*
         The Reason of this function is to set an allowance on the main timer not to start once the plugin is enabled.
        */
            
    if($timer == 1){
                
    $this->start($this->restart_time 1);
                return;
            }else{
                
    $timer--;
                
    $this->getServer()->getScheduler()->scheduleDelayedTask(new CallbackTask([$this,"initial_start" ], [$timer]), 20);
            }
        }
       
        public function 
    start($time_target){
            
    $time_target--;
            if(
    $time_target == 1$offset "min.";
            else 
    $offset "mins.";
            
    $this->broadcast("Server will restart in $time_target $offset");
            if(
    $time_target == 1){
                
    $this->count_down($this->count_down 1);
                return;
            }
            
    $this->setTimer($time_target$offset);
            
    $this->getServer()->getScheduler()->scheduleDelayedTask(new CallbackTask([$this,"start" ], [$time_target]), 1200);
        }
       
        public function 
    count_down($seconds){
            if(
    $seconds == 1){
                foreach(
    $this->getServer()->getOnlinePlayers() as $p){
                    
    $p->kick("Server Restart");
                }
                
    $this->getServer()->shutdown();
                return;
            }else{
                
    $seconds--;
                
    $this->setTimer($seconds"secs.");
                if(
    $seconds == 30$this->broadcast("Server will restart in $seconds seconds.");
                if(
    $seconds == 10$this->broadcast("Server will restart in $seconds seconds.");
                if(
    $seconds 6$this->broadcast("Server will restart in $seconds.");
                
    $this->getServer()->getScheduler()->scheduleDelayedTask(new CallbackTask([$this,"count_down" ], [$seconds]), 20);
            }
        }
       
        
    /************************
        *=======================*
        *====[ Non - APIs ]=====*
        *=======================*
        ************************/
       
        
    public function broadcast($msg){
            return 
    $this->getServer()->broadcastMessage($this->prefix $msg");
        }
       
        public function 
    loadConfigurations(){
            if(!
    file_exists($this->getDataFolder())){
                @
    mkdir($this->getDataFolder(), 0777true);
                
    $this->preferences = new Config($this->getDataFolder() . "config.yml"Config::YAML);
                
    $this->preferences->set("Version""2.0.0");
                
    $this->preferences->set("TimeToRestart"30);
                
    $this->preferences->set("Prefix""[ASR]");
                
    $this->preferences->save();
            }else{
           
            
    /*    This would be useful when I make some further updates e.g. Multi Lingual Support.
                If you are worrying about if there's version 3.0.0 or more, don't worry, I'll deal
                with it :)                                                                            */
               
                
    $this->preferences = new Config($this->getDataFolder() . "config.yml"Config::YAML);
                
    $version $this->preferences->get("Version");
                if(
    $version !== "2.0.0"){
                    
    $this->getServer()->getLogger()->info(TextFormat::YELLOW "[ASR] It Seems you're using an old version of ASR.");
                    
    $this->getServer()->getLogger()->info(TextFormat::YELLOW "[ASR] Applying Configuration Updates [...]");
                    
    $this->preferences->set("Version""2.0.0");
                    
    $this->preferences->set("TimeToRestart"30);
                    
    $this->preferences->set("Prefix""[ASR]");
                    
    $this->preferences->save();
                    
    $this->getServer()->getLogger()->info(TextFormat::GREEN "[ASR] Done!");
                }
               
            }
           
            
    $this->restart_time $this->preferences->get("TimeToRestart");
            
    $this->prefix $this->preferences->get("Prefix");
        }

    }
    Commands.php
    PHP:
    <?php

    namespace edgar\serverrestart;

    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandExecutor;
    use 
    pocketmine\command\CommandSender;

    class 
    Commands implements CommandExecutor{

        public function 
    __construct(Loader $plugin){
            
    $this->plugin $plugin;
        }
       
        public function 
    onCommand(CommandSender $senderCommand $command$label, array $args){
            switch(
    strtolower($command->getName())){
           
                case 
    "asr":
                    if(isset(
    $args[0])){
                        if(!
    is_numeric($args[0])){
                            
    $sender->sendMessage("[Server Restart] Only Numbers.");
                            return;
                        }
                        if(
    $args[0] > 60){
                            
    $sender->sendMessage("[Server Restart] You can not put the value of more than 60. If you want to put it, edit the configuration file plugin");
                            return;
                        }
                        
    $this->plugin->setValueTimer($args[0]);
                        
    $sender->sendMessage("[Server Restart] You have set the timer to " $args[0] . " min/s. The changes will apply after the next server restart.");
                    }else{
                        
    $sender->sendMessage("Usage: /setrestart <value>");
                    }
                break;
           
                case 
    "restart":
                    
    $time $this->plugin->getTimer();
                    
    $sender->sendMessage("[Server Restart] The server will restart in $time");
                break;
           
            }
           
        }

    }
    Thanks for your help!

    Attached Files:

  2. Edgar_SM
    Offline

    Edgar_SM New Member

    Joined:
    Oct 11, 2014
    Posts:
    20
    Minecraft User:
    evermine
    Thanks
  3. Edgar_SM
    Offline

    Edgar_SM New Member

    Joined:
    Oct 11, 2014
    Posts:
    20
    Minecraft User:
    evermine
    Another error :(
    I can not find the error:mad:,
    I will continue looking. But if someone help me with this other error is greatly appreciate it;)

    [CRITICAL] ClassNotFoundException: "Class serverrestart\Loader not found" (EXCEPTION) in "/src/spl/BaseClassLoader" at line 111
  4. iksaku
    Offline

    iksaku Notable Member Plugin Developer

    Joined:
    Sep 2, 2013
    Posts:
    1,130
    Plugins:
    4
    Minecraft User:
    iksaku
    No, according to the file... You should change the serverrestart/Loader, to edgar\serverrestart\Loader ;)
    Also, in the plugin.yml, don't put all the "Compatible API versions" inside an Array, it's better to only write the lowest compatible one, so all the APIs above it will also be compatible ;)
    iJoshuaHD, Edgar_SM and PEMapModder like this.
  5. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    1.9.0 is compatible for 1.(9+).0 but not 2.0.0
  6. iksaku
    Offline

    iksaku Notable Member Plugin Developer

    Joined:
    Sep 2, 2013
    Posts:
    1,130
    Plugins:
    4
    Minecraft User:
    iksaku
    There's no API 2.0.0 xD
    xpyctum likes this.
  7. Angelo Vidrio
    Offline

    Angelo Vidrio Active Member Plugin Developer

    Joined:
    Jan 16, 2014
    Posts:
    123
    Plugins:
    5
    Minecraft User:
    LilCrispy45
    1.9,1.10,1.11
  8. iJoshuaHD
    Offline

    iJoshuaHD Notable Member Plugin Developer

    Joined:
    Nov 7, 2013
    Posts:
    1,167
    Plugins:
    4
    Minecraft User:
    iJoshuaHD
    are you sure this is your plugin? you just ripped off my ASR plugin :( bad! bad!
    Edgar_SM and Angelo Vidrio like this.
  9. Angelo Vidrio
    Offline

    Angelo Vidrio Active Member Plugin Developer

    Joined:
    Jan 16, 2014
    Posts:
    123
    Plugins:
    5
    Minecraft User:
    LilCrispy45
    I thought someone had made this already.
  10. iJoshuaHD
    Offline

    iJoshuaHD Notable Member Plugin Developer

    Joined:
    Nov 7, 2013
    Posts:
    1,167
    Plugins:
    4
    Minecraft User:
    iJoshuaHD
    take a look at my ASR source, he just made renames on it ... what a bummer. it wont get posted in this forums anyways if he plans to rerelease it.
    https://github.com/iJoshuaHD/ASR
    xFlare and Angelo Vidrio like this.
  11. iJoshuaHD
    Offline

    iJoshuaHD Notable Member Plugin Developer

    Joined:
    Nov 7, 2013
    Posts:
    1,167
    Plugins:
    4
    Minecraft User:
    iJoshuaHD
  12. Exxarion
    Offline

    Exxarion Active Member Plugin Developer

    Joined:
    Jan 5, 2014
    Posts:
    242
    Plugins:
    1
    Minecraft User:
    Notch
    Wow.

    I looked at the source codes side-by-side, and I saw the source codes were EXACTLY the same. He only renamed it.
    iksaku and iJoshuaHD like this.
  13. Exxarion
    Offline

    Exxarion Active Member Plugin Developer

    Joined:
    Jan 5, 2014
    Posts:
    242
    Plugins:
    1
    Minecraft User:
    Notch
    It even says [ASR] in the code XD
    iksaku, Angelo Vidrio and iJoshuaHD like this.
  14. iksaku
    Offline

    iksaku Notable Member Plugin Developer

    Joined:
    Sep 2, 2013
    Posts:
    1,130
    Plugins:
    4
    Minecraft User:
    iksaku
    TROOOOOOOL XD
    Angelo Vidrio likes this.
  15. Angelo Vidrio
    Offline

    Angelo Vidrio Active Member Plugin Developer

    Joined:
    Jan 16, 2014
    Posts:
    123
    Plugins:
    5
    Minecraft User:
    LilCrispy45
    This is a no no.
  16. Edgar_SM
    Offline

    Edgar_SM New Member

    Joined:
    Oct 11, 2014
    Posts:
    20
    Minecraft User:
    evermine
    I canceled my plugin,
  17. Edgar_SM
    Offline

    Edgar_SM New Member

    Joined:
    Oct 11, 2014
    Posts:
    20
    Minecraft User:
    evermine
    wanted to improve the ARS plugin. But'll do another plugin
  18. xFlare
    Offline

    xFlare Active Member Plugin Developer

    Joined:
    Sep 28, 2014
    Posts:
    199
    Plugins:
    1
    Minecraft User:
    xFlare
    No.

    Make a pull request on GitHub rather then changing a plugins name and calling it your own.
    iJoshuaHD and Edgar_SM like this.
  19. Edgar_SM
    Offline

    Edgar_SM New Member

    Joined:
    Oct 11, 2014
    Posts:
    20
    Minecraft User:
    evermine
    Sorry:(. I do my own plugin called DeadBack, I have already finished but ... I jump an error:confused:
  20. Edgar_SM
    Offline

    Edgar_SM New Member

    Joined:
    Oct 11, 2014
    Posts:
    20
    Minecraft User:
    evermine
    Sorry iJoshuaHD. In compensation for the inconvenience, will recommend your pluggin in my plugin page, then make the realse

Share This Page

Advertisement