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: <?phpnamespace 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 $sender, Command $cmd, string $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}", $i, RestartTransfer::$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'); } }}
You forgot add ) in if Code I fix PHP: <?phpnamespace 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 $sender, Command $cmd, string $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}", $i, RestartTransfer::$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
Ohh thanks, what I wanted to do in the plugin is detect true or false but I could not. Might you help me?
I want to detect if is true in config Reload but the plugin reload even if it is false. PHP: <?phpnamespace 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 $sender, Command $cmd, string $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}", $i, RestartTransfer::$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; } }}
Uhmmm I don't know This is what you think. PHP: <?phpnamespace 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 $sender, Command $cmd, string $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}", $i, RestartTransfer::$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; } }}
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?
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; } }