When i use Code: /cmd ex args how can i get the "args" in config file Code: - Example: - args - args1 - args2 with the PHP code
PHP: public function onCommand(CommandSender $sender, Command $command, $label, array $args){ $conf = new Config($this->getDataFolder(), Config::YAML); $cmd = $command->getName(); if($cmd[0] == "cmd"){ if($cmd[1] == "ex"){ array_shift($cmd); array_shift($cmd); $i = 0; foreach($cmd as $arg){ $conf->set($i, $arg); $i++; } $conf->save(); }}} basic idea..
You can always use this for configs Code: $conf->getNested("blah.blah"); Or this for arguments Code: $test = $args[0]; // that above, gets the first argument. Replace 0 with 1, etc for each other(S)
How can I get "args" (args have been saved) in Code: -Example: - args - args1 - args2 When i use /cmd args ($args[0] is args) and it will check in the Example
Try this: PHP: $argsArray = $cfgObject->get("Example"); //Get the array under 'Example'var_dump($argsArray); //Outputs sth like:array(3) { [0]=> string(4) "args" [1]=> string(5) "args1" [2]=> string(5) "args2"}
Or you guys check for me about my code PHP: $this->code = new Config($this->getDataFolder() . "code.yml", Config::YAML, array( "Code" => "TESTINGC",));if(($this->code->getAll("Code"))){ $sender->sendMessage("Yes"); return true; } else { $sender->sendMessage("No"); return true; } when i use /cmd TESTINGC it show "Yes" but when i use /cmd blahblah it also "Yes" although it doesn't in array
To do's 1) Please add this PHP: $this->code = new Config($this->getDataFolder() . "code.yml", Config::YAML, array( "Code" => "TESTINGC",)); on enable() 2) You dont need to add return everywhere, PHP: if(($this->code->getAll("Code"))) { $sender->sendMessage("Yes");} else { $sender->sendMessage("No");} You can use this code when youre calling a command.. or if u wanna do on start use PHP: $this->getLogger()->warning("yes");
Try it out . Your issues: - You didnt know when to call that getAll() method! - How would the server know who is the "$sender" without u calling it? - You didnt add the config method onEnable();
actruelly i add the config method onEnable() But how when to call that getAll() method and the code have to be what ? It's so confused with me to check this
Example: PHP: public function onCommand(CommandSender $sender, Command $cmd, $label, array $args) { if($cmd->getName() === "list") { if($this->code->get("Code") === true) { $sender->sendMessage("woah"); } else { $sender->sendMessage("Nooooo"); }}