Hey Guys i am editing a plugin and in that plugin i need to execute this command 'wreset restore sw1'
P.S i tried this: $command = "lagg clearall";$this->getServer()->dispatchCommand(new ConsoleCommandSender(), $command)) but it returns a syntax error
Try this, you just had a couple of things out of place, it should be: PHP: $command = "wreset restore sw1";$this->getServer()->dispatchCommand(new ConsoleCommandSender($command));
So far so good Classpath Inspection result: Passed Info Main class scanned: GamesLoad\SurvivalGames\Main Main class file found at src/GamesLoad/SurvivalGames/Main.php Bad practice Inspection result: Passed Syntax errors Inspection result: Passed Info 1 good PHP file(s) and 0 bad PHP file(s) found. Checked with PHP 7.0.4
Hmmm, can you send me the whole section that's meant to be running the command, I'm not sure why it's not working, you do have the wreset command on the server don't you?
here is the section of the plugin Im working on PHP: else { $aop = count($levelArena->getPlayers()); if($aop==1) { foreach($playersArena as $pl) { foreach($this->plugin->getServer()->getOnlinePlayers() as $plpl) { $playerlang = new Config($this->plugin->getDataFolder() . "/languages.yml", Config::YAML); $lang = new Config($this->plugin->getDataFolder() . "/lang.yml", Config::YAML); $toUse = $lang->get($playerlang->get($plpl->getName())); $plpl->sendMessage($this->prefix . $pl->getName() . " " . $toUse["won"]); $command = "wreset restore sw1"; $this->getServer()->dispatchCommand(new ConsoleCommandSender($command)); }
Use Statements: PHP: use pocketmine\plugin\PluginBase;use pocketmine\scheduler\PluginTask;use pocketmine\event\Listener;use pocketmine\event\player\PlayerInteractEvent;use pocketmine\event\player\PlayerLoginEvent;use pocketmine\command\CommandSender;use pocketmine\command\Command;use pocketmine\utils\TextFormat;use pocketmine\utils\Config;use pocketmine\math\Vector3;use pocketmine\level\Position;use pocketmine\command\ConsoleCommandSender;use pocketmine\Player;use pocketmine\block\Block;use pocketmine\tile\Sign;use pocketmine\level\Level;use pocketmine\item\Item;use pocketmine\event\block\BlockBreakEvent;use pocketmine\event\block\BlockPlaceEvent;use pocketmine\event\player\PlayerMoveEvent;use pocketmine\event\player\PlayerDeathEvent;use pocketmine\event\entity\EntityDamageEvent;use pocketmine\event\entity\EntityDamageByEntityEvent;use pocketmine\entity\Effect;use pocketmine\tile\Chest;use pocketmine\inventory\ChestInventory;
Change to your first method. Server::dispatchCommand() requires 2 argument How many time i have to say that that method would never work...
Just post the problem here... Change it to $this->getServer()->dispatchCommand(new ConsoleCommandSender(), $command); then report the error message...
Ok i just tried that and there isn't any error message the command just doesn't execute and i am sure i have that command because i can run it just fine myself.