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

Solved What im doing wrong?

Discussion in 'Plugin Help' started by IvanCraft623, Oct 5, 2020.

  1. IvanCraft623

    IvanCraft623 Baby Zombie

    Messages:
    105
    GitHub:
    IvanCraft623
    Im new in pocketmine and my knowledge in PHP is null

    I have the error:
    [22:58:05] [Server thread/CRITICAL]: ParseError: "syntax error, unexpected ';'" (EXCEPTION) in "plugins/RestartTransfer/src/IvanCraft623/RestartTransfer/RestartTransfer" at line 75
    PHP:
    <?php

    namespace IvanCraft623\RestartTransfer;

    use 
    pocketmine\event\Listener;
    use 
    pocketmine\Player;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\utils\Config;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\command\ConsoleCommandSender;

    class 
    RestartTransfer extends PluginBase implements Listener {
      
        public static 
    $settings;
        public 
    $taskIDs;

        public function 
    onEnable(){
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
            
    $this->saveDefaultConfig();
            
    $this->config = new Config($this->getDataFolder() . "config.yml"Config::YAML);
            
    self::$settings $this->config->getAll();
            if(!
    is_numeric(self::$settings["Server"]["Port"])){
                
    $this->getLogger()->critical("Port must be numeric. Disabling Plugin...");
                
    $this->getServer()->getPluginManager()->disablePlugin($this);
            }
            
    $this->getLogger()->info("Transferring players to " self::$settings["Server"]["Address"] . ":" self::$settings["Server"]["Port"] . " on server restart or crash");
            
    $this->CheckEnabledReload();
        }

        public function 
    onCommand(CommandSender $senderCommand $cmdstring $label,array $args) : bool {
            switch (
    $cmd->getName()) {
                case 
    'restart':
                if (
    $sender->hasPermission("restart.command")){
                    
    $players $this->getServer()->getLoggedInPlayers();
                    if(!
    self::$settings["Restart"]["Enabled"] || self::$settings["Restart"]["Delay"] <= 0){
                        
    $this->transferPlayers($players);
                        
    $server $this->getServer();
                        
    $server->dispatchCommand(new ConsoleCommandSender(), 'stop');
                    }
                    for(
    $i self::$settings["Restart"]["Delay"]; $i >= 0$i--){
                        if(
    $i === 0){
                            
    $this->transferPlayers($players);
                            
    $server $this->getServer();
                            
    $server->dispatchCommand(new ConsoleCommandSender(), 'stop');
                        }
                        
    $this->getServer()->broadcastMessage(str_replace("{seconds-left}"$iRestartTransfer::$settings["Restart"]["Message"]));
                        
    sleep(1);
                    }
                }
                break;
            }
            return 
    true;
        }

        public function 
    onDisable(){
            if(
    $this->getServer()->isRunning()) return;
            
    $players $this->getServer()->getLoggedInPlayers();
            if(
    sizeof($players) === 0) return;
            
    $this->transferPlayers($players);
        }

        public function 
    transferPlayers(array $players){
            
    $this->getLogger()->notice("Transferring players...");
            foreach(
    $players as $player){
                if(!
    $player instanceof Player) continue;
                
    $player->transfer(self::$settings["Server"]["Address"], self::$settings["Server"]["Port"]);
                
    $this->getLogger()->notice("Transferring " $player->getName());
            }
            
    $this->getLogger()->notice("Players have been transferred");
        }

        public function 
    CheckEnabledReload(){
            if(
    self::$settings["Restart"]["Reload"] {
                
    $this->RealoadServers();
            }
        }

        public function 
    RealoadServers(){
            if(
    self::$settings["Restart_Now"]{
                
    $config = new Config($this->plugin->getDataFolder()."config.yml"Config::YAML);
                
    $config->set("Restart_Now"false);
                
    $config->save();
                
    $server $this->getServer();
                
    $server->dispatchCommand(new ConsoleCommandSender(), 'reload');
            }
        }
    }
     
  2. NutXzG

    NutXzG Baby Zombie

    Messages:
    132
    GitHub:
    NutXzG
    You forgot add ) in if
    Code I fix
    PHP:
    <?php

    namespace IvanCraft623\RestartTransfer;

    use 
    pocketmine\event\Listener;
    use 
    pocketmine\Player;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\utils\Config;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\command\ConsoleCommandSender;

    class 
    RestartTransfer extends PluginBase implements Listener {
     
        public static 
    $settings;
        public 
    $taskIDs;

        public function 
    onEnable(){
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
            
    $this->saveDefaultConfig();
            
    $this->config = new Config($this->getDataFolder() . "config.yml"Config::YAML);
            
    self::$settings $this->config->getAll();
            if(!
    is_numeric(self::$settings["Server"]["Port"])){
                
    $this->getLogger()->critical("Port must be numeric. Disabling Plugin...");
                
    $this->getServer()->getPluginManager()->disablePlugin($this);
            }
            
    $this->getLogger()->info("Transferring players to " self::$settings["Server"]["Address"] . ":" self::$settings["Server"]["Port"] . " on server restart or crash");
            
    $this->CheckEnabledReload();
        }

        public function 
    onCommand(CommandSender $senderCommand $cmdstring $label,array $args) : bool {
            switch (
    $cmd->getName()) {
                case 
    'restart':
                if (
    $sender->hasPermission("restart.command")){
                    
    $players $this->getServer()->getLoggedInPlayers();
                    if(!
    self::$settings["Restart"]["Enabled"] || self::$settings["Restart"]["Delay"] <= 0){
                        
    $this->transferPlayers($players);
                        
    $server $this->getServer();
                        
    $server->dispatchCommand(new ConsoleCommandSender(), 'stop');
                    }
                    for(
    $i self::$settings["Restart"]["Delay"]; $i >= 0$i--){
                        if(
    $i === 0){
                            
    $this->transferPlayers($players);
                            
    $server $this->getServer();
                            
    $server->dispatchCommand(new ConsoleCommandSender(), 'stop');
                        }
                        
    $this->getServer()->broadcastMessage(str_replace("{seconds-left}"$iRestartTransfer::$settings["Restart"]["Message"]));
                        
    sleep(1);
                    }
                }
                break;
            }
            return 
    true;
        }

        public function 
    onDisable(){
            if(
    $this->getServer()->isRunning()) return;
            
    $players $this->getServer()->getLoggedInPlayers();
            if(
    sizeof($players) === 0) return;
            
    $this->transferPlayers($players);
        }

        public function 
    transferPlayers(array $players){
            
    $this->getLogger()->notice("Transferring players...");
            foreach(
    $players as $player){
                if(!
    $player instanceof Player) continue;
                
    $player->transfer(self::$settings["Server"]["Address"], self::$settings["Server"]["Port"]);
                
    $this->getLogger()->notice("Transferring " $player->getName());
            }
            
    $this->getLogger()->notice("Players have been transferred");
        }

        public function 
    CheckEnabledReload(){
            if(
    self::$settings["Restart"]["Reload"] ){
                
    $this->RealoadServers();
            }
        }

        public function 
    RealoadServers(){
            if(
    self::$settings["Restart_Now"]){
                
    $config = new Config($this->plugin->getDataFolder()."config.yml"Config::YAML);
                
    $config->set("Restart_Now"false);
                
    $config->save();
                
    $server $this->getServer();
                
    $server->dispatchCommand(new ConsoleCommandSender(), 'reload');
            }
        }
    }
    I recommend app or program Acode, Vscode
     
  3. IvanCraft623

    IvanCraft623 Baby Zombie

    Messages:
    105
    GitHub:
    IvanCraft623
    Ohh thanks, what I wanted to do in the plugin is detect true or false but I could not. Might you help me? :D
     
  4. IvanCraft623

    IvanCraft623 Baby Zombie

    Messages:
    105
    GitHub:
    IvanCraft623
    I want to detect if is true in config Reload but the plugin reload even if it is false.

    PHP:
    <?php

    namespace IvanCraft623\RestartTransfer;

    use 
    pocketmine\event\Listener;
    use 
    pocketmine\Player;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\utils\Config;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\command\ConsoleCommandSender;

    class 
    RestartTransfer extends PluginBase implements Listener {
        
        public static 
    $settings;
        public 
    $taskIDs;

        public function 
    onEnable(){
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
            
    $this->saveDefaultConfig();
            
    $this->config = new Config($this->getDataFolder() . "config.yml"Config::YAML);
            
    self::$settings $this->config->getAll();
            if(!
    is_numeric(self::$settings["Server"]["Port"])){
                
    $this->getLogger()->critical("Port must be numeric. Disabling Plugin...");
                
    $this->getServer()->getPluginManager()->disablePlugin($this);
            }
            
    $this->getLogger()->info("Transferring players to " self::$settings["Server"]["Address"] . ":" self::$settings["Server"]["Port"] . " on server restart or crash");
            
    $this->CheckEnabledReload();
        }

        public function 
    onCommand(CommandSender $senderCommand $cmdstring $label,array $args) : bool {
            switch (
    $cmd->getName()) {
                case 
    'restart':
                if (
    $sender->hasPermission("restart.command")){
                    
    $players $this->getServer()->getLoggedInPlayers();
                    if(!
    self::$settings["Restart"]["Enabled"] || self::$settings["Restart"]["Delay"] <= 0){
                        
    $this->transferPlayers($players);
                        
    $server $this->getServer();
                        
    $server->dispatchCommand(new ConsoleCommandSender(), 'stop');
                    }
                    for(
    $i self::$settings["Restart"]["Delay"]; $i >= 0$i--){
                        if(
    $i === 0){
                            
    $this->transferPlayers($players);
                            
    $server $this->getServer();
                            
    $server->dispatchCommand(new ConsoleCommandSender(), 'stop');
                        }
                        
    $this->getServer()->broadcastMessage(str_replace("{seconds-left}"$iRestartTransfer::$settings["Restart"]["Message"]));
                        
    sleep(1);
                    }
                }
                break;
            }
            return 
    true;
        }

        public function 
    onDisable(){
            
    $config = new Config($this->getDataFolder()."config.yml"Config::YAML);
            
    $config->remove("Reload_Now"false);
            
    $config->set("Reload_Now"true);
            
    $config->save();
            if(
    $this->getServer()->isRunning()) return;
            
    $players $this->getServer()->getLoggedInPlayers();
            if(
    sizeof($players) === 0) return;
            
    $this->transferPlayers($players);
        }

        public function 
    transferPlayers(array $players){
            
    $this->getLogger()->notice("Transferring players...");
            foreach(
    $players as $player){
                if(!
    $player instanceof Player) continue;
                
    $player->transfer(self::$settings["Server"]["Address"], self::$settings["Server"]["Port"]);
                
    $this->getLogger()->notice("Transferring " $player->getName());
            }
            
    $this->getLogger()->notice("Players have been transferred");
        }

        public function 
    CheckEnabledReload(){
            
    $reloadEnabled = (new Config($this->getDataFolder()."config.yml"Config::YAML, array("Reload" => true,)))->getAll();
            if(
    $reloadEnabled->get("Reload")){
                
    $this->CheckReloadServer();
            }
        }

        public function 
    CheckReloadServer(){
            
    $reloadNow = (new Config($this->getDataFolder()."config.yml"Config::YAML, array("Reload_Now" => true,)))->getAll();
            if(
    $reloadNow->get("Reload_Now")){
                
    $config = new Config($this->getDataFolder()."config.yml"Config::YAML);
                
    $config->remove("Reload_Now"true);
                
    $config->set("Reload_Now"false);
                
    $config->save();
                
    $server $this->getServer();
                
    $server->dispatchCommand(new ConsoleCommandSender(), 'reload');
            } elseif(
    $config->get("Reload_Now") == false) {
                return 
    true;
            }
        }
    }
     
  5. NutXzG

    NutXzG Baby Zombie

    Messages:
    132
    GitHub:
    NutXzG
    Uhmmm I don't know This is what you think.
    PHP:
    <?php

    namespace IvanCraft623\RestartTransfer;

    use 
    pocketmine\event\Listener;
    use 
    pocketmine\Player;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\utils\Config;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\command\ConsoleCommandSender;

    class 
    RestartTransfer extends PluginBase implements Listener {
       
        public static 
    $settings;
        public 
    $taskIDs;

        public function 
    onEnable(){
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
            
    $this->saveDefaultConfig();
            
    $this->config = new Config($this->getDataFolder() . "config.yml"Config::YAML);
            
    self::$settings $this->config->getAll();
            if(!
    is_numeric(self::$settings["Server"]["Port"])){
                
    $this->getLogger()->critical("Port must be numeric. Disabling Plugin...");
                
    $this->getServer()->getPluginManager()->disablePlugin($this);
            }
            
    $this->getLogger()->info("Transferring players to " self::$settings["Server"]["Address"] . ":" self::$settings["Server"]["Port"] . " on server restart or crash");
            
    $this->CheckEnabledReload();
        }

        public function 
    onCommand(CommandSender $senderCommand $cmdstring $label,array $args) : bool {
            switch (
    $cmd->getName()) {
                case 
    'restart':
                if (
    $sender->hasPermission("restart.command")){
                    
    $players $this->getServer()->getLoggedInPlayers();
                    if(!
    self::$settings["Restart"]["Enabled"] || self::$settings["Restart"]["Delay"] <= 0){
                        
    $this->transferPlayers($players);
                        
    $server $this->getServer();
                        
    $server->dispatchCommand(new ConsoleCommandSender(), 'stop');
                    }
                    for(
    $i self::$settings["Restart"]["Delay"]; $i >= 0$i--){
                        if(
    $i === 0){
                            
    $this->transferPlayers($players);
                            
    $server $this->getServer();
                            
    $server->dispatchCommand(new ConsoleCommandSender(), 'stop');
                        }
                        
    $this->getServer()->broadcastMessage(str_replace("{seconds-left}"$iRestartTransfer::$settings["Restart"]["Message"]));
                        
    sleep(1);
                    }
                }
                break;
            }
            return 
    true;
        }

        public function 
    onDisable(){
            
    $config = new Config($this->getDataFolder()."config.yml"Config::YAML);
            
    $config->remove("Reload_Now"false);
            
    $config->set("Reload_Now"true);
            
    $config->save();
            if(
    $this->getServer()->isRunning()) return;
            
    $players $this->getServer()->getLoggedInPlayers();
            if(
    sizeof($players) === 0) return;
            
    $this->transferPlayers($players);
        }

        public function 
    transferPlayers(array $players){
            
    $this->getLogger()->notice("Transferring players...");
            foreach(
    $players as $player){
                if(!
    $player instanceof Player) continue;
                
    $player->transfer(self::$settings["Server"]["Address"], self::$settings["Server"]["Port"]);
                
    $this->getLogger()->notice("Transferring " $player->getName());
            }
            
    $this->getLogger()->notice("Players have been transferred");
        }

        public function 
    CheckEnabledReload(){
            
    $reloadEnabled = (new Config($this->getDataFolder()."config.yml"Config::YAML, array("Reload" => true,)))->getAll();
            if(
    $reloadEnabled->get("Reload")){
                
    $this->CheckReloadServer();
            }
        }

        public function 
    CheckReloadServer(){
            
    $reloadNow = (new Config($this->getDataFolder()."config.yml"Config::YAML, array("Reload_Now" => true,)))->getAll();
            if(
    $reloadNow->get("Reload_Now") === true){
                
    $config = new Config($this->getDataFolder()."config.yml"Config::YAML);
                
    $config->remove("Reload_Now"true);
                
    $config->set("Reload_Now"false);
                
    $config->save();
                
    $server $this->getServer();
                
    $server->dispatchCommand(new ConsoleCommandSender(), 'reload');
            } elseif(
    $config->get("Reload_Now") == false) {
                return 
    true;
            }
        }
    }
     
  6. IvanCraft623

    IvanCraft623 Baby Zombie

    Messages:
    105
    GitHub:
    IvanCraft623
    THAANKS!

    Now I want to make the config change Reload_Now to false but it doesn't work for me

    PHP:
        public function CheckReloadServer(){
            
    $config = new Config($this->getDataFolder()."config.yml"Config::YAML);
            if(
    $config->get("Reload_Now") === true){
                
    $config->remove("Reload_Now"true);
                
    $config->set("Reload_Now"false);
                
    $config->save();
                
    $server $this->getServer();
                
    $server->dispatchCommand(new ConsoleCommandSender(), 'reload');
            } elseif(
    $config->get("Reload_Now") == false) {
                return 
    true;
            }
        }
    that's what I use, could you help me?
     
  7. NutXzG

    NutXzG Baby Zombie

    Messages:
    132
    GitHub:
    NutXzG
    Uhmmmm
    PHP:
     public function CheckReloadServer(){
            
    $config = new Config($this->getDataFolder()."config.yml"Config::YAML);
            if(
    $config->get("Reload_Now") === true){
                
    $config->set("Reload_Now"false);
                
    $config->save();
                
    $server $this->getServer();
                
    $server->dispatchCommand(new ConsoleCommandSender(), 'reload');
            } elseif(
    $config->get("Reload_Now") == false) {
                return 
    true;
            }
        }
     
  8. IvanCraft623

    IvanCraft623 Baby Zombie

    Messages:
    105
    GitHub:
    IvanCraft623
    Thank you very much for your help!
     
  9. NutXzG

    NutXzG Baby Zombie

    Messages:
    132
    GitHub:
    NutXzG
    edit title Solved it
     
  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.