Hi! I've executed several commands to confirm that my code is working perfectly.. Executed Commands: PHP: [05:30:19] [Server thread/INFO]: Done (1.254s)! For help, type "help" or "?"review[05:30:21] [Server thread/INFO]: Usage: /review add {review}review add[05:30:24] [Server thread/INFO]: Usage: /review add [review]review add Hey Testing[05:30:44] [Server thread/INFO]: [Review] You review has been added! Main File: PHP: <?phpnamespace RTG\GitHub;/* * All rights reserved RTGNetworkkk *//* Essentials */use pocketmine\Player;use pocketmine\Server;use pocketmine\plugin\PluginBase;use RTG\GitHub\Command\MyCommand;use pocketmine\utils\Config;class Review extends PluginBase { public function onEnable() { @mkdir($this->getDataFolder()); @mkdir($this->getDataFolder() . "players"); $this->getLogger()->warning("[Review] DIR has been made!"); $this->getLogger()->warning("Loaded!"); /* Execution */ $this->getCommand("review")->setExecutor(new MyCommand($this)); $this->getLogger()->warning("[Review] Everything has been loaded!"); } public function onDisable() { } } My Command: PHP: <?phpnamespace RTG\GitHub\Command;use pocketmine\command\Command;use pocketmine\command\CommandSender;use pocketmine\command\CommandExecutor;use pocketmine\utils\Config;use RTG\GitHub\Review;use pocketmine\utils\TextFormat as TF;class MyCommand implements CommandExecutor { public function __construct(Review $plugin) { $this->plugin = $plugin; } public function onCommand(CommandSender $sender, Command $cmd, $label, array $param) { switch($cmd->getName()) { case "review": if(isset($param[0])) { switch($param[0]) { case "add": if($sender->hasPermission("review.add")) { $n = $sender->getName(); if(isset($param[1])) { if(count($param) < 1) { $sender->sendMessage("You args are incorrect!"); return false; } else { $msg = trim(implode(" ", $param)); $this->cfg = new Config($this->plugin->getDataFolder() . "players/" . strtolower($sender->getName()) . ".txt", Config::ENUM); $this->cfg->set($msg); $this->cfg->save(); $sender->sendMessage("[Review] You review has been added!"); } } else { $sender->sendMessage("Usage: /review add [review]"); } } else { $sender->sendMessage(TF::RED . "You have no permission to use this command!"); } return true; break; } } else { $sender->sendMessage("Usage: /review add {review}"); } return true; break; } } } but it's logging weirdly on my Config: :/ Config: PHP: add Hey Testing
You're imploding the entire argument array and saving it to your config, you need to get rid off the sub-command input before you implode the array. I'd personally just call array_shift($args) when I switch the sub-command. PHP: switch(strtolower(array_shift($args))){ case "add": $msg = implode(" ", $args); // your code here break;}
I really don't understand this http://php.net/manual/en/function.array-shift.php , can u explain more in depth?
The function takes an array as an argument, it takes the first entry of that array and returns the value of the entry it removed. The array that you pass to the function is edited by the function so that the value it returns will be removed from the array. PHP: $myArray = [ "first value", "second value", "third value"];array_shift($myArray); //returns "first value"// $myArray now looks like this: ["second value", "third value"]array_shift($myArray); // returns "second value"// $myArray now looks like: ["third value"] Whilst this is not a PHP forum I'm still answering your question because you're trying to understand the code instead of the usual copy-paste response, props to you for that.