please help, how to solve this problem. example: I make keyshop with code. if a player uses a name with a space number (for example: Steve 123) and buys the item, the number of items received does not match the config, but the total is 123 items, the same as the player's gamertag number. This applies if the player uses spaces $this->getServer()->dispatchCommand(new \pocketmine\command\ConsoleCommandSender(), "key Common ".$sender->getName()." ".$this->getConfig()->get("common.amount"));
That is one of the reasons why dispatching commands are discouraged! Why don't you use the plugin's API to give the key?
I'd suggest looking into what Primus wrote, but if you insist on doing it your way, it is of course possible to solve this issue. All arguments which contain spaces and are used in a command string should be encapsulated in quotation marks. Example: Instead of "key Common Steve 123" you should use this as the command string: key Common "Steve 123" That way Steve and 123 are interpreted as a single command argument, hence "Steve 123".
Why do you need a sample code? You really just have to add quotation marks around the player name: PHP: $playerName = "Steve 123";$cmdString = "key Common \"".$playerName."\""; // Notice the use of the backslash in \" which is used to escape the " character
sorry, if I use this code it only works with the player name steve 123? Isn't it for all players with space names?
No, this works for all player names, even those without any spaces at all. You just have to replace the variable $playerName.
Use this code: PHP: $keyAmount = $this->getConfig()->get("common.amount"));$lowercaseCrateType = "Common";$this->getServer()->getPluginManager()->getPlugin("MysteryCrate")->giveKey($sender, $lowercaseCrateType, $keyAmount);$sender->sendMessage("§aYou got one Common Key")
sorry, I tried and there were some error ErrorException: "Undefined variable: lowercaseCrateType" (EXCEPTION)