I want to check if the player has the same name as this in config.yml, how do I? PHP: $player = $event->getPlayer();$cfgPlayer= $this->config["Names"]->getAll();if($player == $cfgPlayer){$player->sendMessage("you're on the list");}else{$player->sendMessage("you are not on the list");}
PHP: $names = $config->get("Names");if(isset($names[$player->getName()]))$player->sendMessage("you are on the list");else$player->sendMessage("you are not on the list");
PHP: //I use, should I change?//config if(!is_dir($this->getDataFolder())) @mkdir($this->getDataFolder()); $this->saveDefaultConfig(); $this->config = (new Config($this->getDataFolder()."config.yml", Config::YAML))->getAll();
The error is not in the code you posted, please post full code and error if you dont know where is it, alternatively use an IDE to help you
Oops ... it works, thx. I only know for 2 commands, how can I for more? /ku msg1 msg2 or /ku msg1 / /ku msg2? Using: PHP: switch($command->getName()){ case "ku":if (!isset($args[0])){$sender->sendMessage("§7Plugin em beta, tente: §a/ku msg");return; }if(strtolower($args[0]) == "msg"){$page1 = $this->config["Grupos"];$sender->sendMessage($page1["Admin"]);return true;} }
For /ku msg1 /ku msg2 you can use PHP: switch($args[0]??null){case "msg1": break;case "msg2": break;default://not set or none of the above break;}//for /ku msg1 msg2if(($args[0]??null) === "msg1" && ($args[1]??null) === "msg2"){}
Thx,If it is not abuse, how do I get what the player typed in the command? Example: :alert (PlayerMsg)
I do not unserstand what you are trying to do, but basically $args is an array of words after the command /ku test test2 $args will contain [test,test2] in this case, $args[0] will be test $args[1] will be test2
I want: "/ ku set blabla blabla" (and more) but only works "/ ku set blabla" the rest of the message does not work. PHP: public function onCommand(CommandSender $sender, Command $command, $label, array $args){ switch($command->getName()){ case "ku":{ if(isset($args[0]) == "set"){ } if(isset($args[1])){ $player = $args[1];$sender->sendMessage("§7Work, you say:§6 $player");return true;}else $sender->sendMessage("Don't work. Try /ku set <msg>");}}}
If you want to join all args after the first argument Do a array_shift($args) to remove the first argument and implode(" ",$args) to join the rest of the args
What is necessary, is to send a normal text message, for example, I type the text of the command only takes the first word.
PHP: public function onCommand(CommandSender $sender, Command $command, string $label, array $args): bool{ switch($command->getName()){ case "ku": if(isset($args[0])){ if($args[0] == "set"){ if(isset($args[1])){ unset($args[0], $args[1]); $sender->sendMessage(implode(" ", $args)); }else{ $sender->sendMessage("Message not set"); } }else{ $sender->sendMessage("Usage: /ku set <msg>"); } }else{ $sender->sendMessage("argument one not set"); } break; } return true;}
PHP: public function onCommand(CommandSender $sender, Command $command, $label, array $args){ switch($command->getName()){ case "ku": if($args[0] == "set"){ array_shift($args); $player = implode(" ", $args); $sender->sendMessage("It worked, you said: §6".$player); return true; }else{ $sender->sendMessage("Usage: /ku set <message>"); } break; } }
Thx all, solved. PHP: $cfg = $this->getConfig();$cfg->get("Groups");$cfg->set("Savage", "joined in the server!");$cfg->save(); Change value in savage don't work, why?
PHP: if(!is_dir($this->getDataFolder())) @mkdir($this->getDataFolder()); $this->saveDefaultConfig(); $this->config = (new Config($this->getDataFolder()."config.yml", Config::YAML))->getAll();//Config::YAML, array("Groups" => array("Savage" => "any msg")); Everything works, but the code should be edited, but he is adding another "Savage: msg"
use this: PHP: $this->config = new Config($this->getDataFolder() . "config.yml", Config::YAML, [ "Groups" => [ ], "Savage" => "any msg"]); then to fetch it: PHP: $this->config->set("Savage", "joined in the server!");$this->config->save();
But "Savage: any msg" have to stay within "Groups" there is not only "Savage" there, if I take things from within "Groups" outside, would have to change a lot in other lines