Hi! So I've been trying to work out how to add to the config when a players runs a command but i unfortunately don't know how. I looked at some old posts to try and figure out what i should be adding but i don't know what it is. I have looked at the posts on setConfig but it doesn't show things that fit my needs. I'm trying to make it add this: check - world x y z so it doesn't just add world, x, y and z but it also adds check so that when check is called the world, x, y and z is broadcasted. I can currently only add world, x, y, z. I already have the broadcast ready but need to get the add to config sorted. Can anyone help? $this->getConfig>set("$addition", $tpc);
If you are trying to get the config to be formatted exactly like your specifying, then you need to have the string with the data and multiple other entries in an array assigned to the key PHP: $config = $plugin->getConfig();$config->set("check",["world x y z","entry 2"]);$config->save();
That would force the user to have inputted the word check though wouldn't it? I mean when it enters check is a custom set name and when it is called everything in it is used.
[19:27:37] [Server thread/CRITICAL]: ErrorException: "Illegal offset type" (EXCEPTION) in "src/pocketmine/utils/Config" at line 449 umm... Is this because of $check = $args[0]; I can post the full error if u need it. I tested it on my warp plugin.
Shouldn't this be different? You'd be setting "check" as the value for the key, which is also an array (citation). I think you meant the opposite, like this? PHP: $config = $plugin->getConfig();$config->set("check", ["world x y z","entry 2"]);$config->save(); I'm not quite certain what you need. Do you want to add more "world x y z" entries under "check" later on, or do you just need to store one? It would help if I knew what your goal was for this code.
Check - world x y z I want all of that added but I need it custom by players. So /check johni Will then add Johni - World x y z PHP: $config = $plugin->getConfig();$config->set($check, [$world, $x, $y, $z,"entry 2"]);$config->save(); Would this work?
Thank you both, you are gods. PHP: $config = $this->getConfig();$config->set($check,[$leveled, $x, $y, $z]);$config->save(); but this won't work to recieve it. PHP: $getcheck = $args[0];$config = $this->getConfig();$config->get($getcheck,[$leveled, $x, $y, $z]); This is the last thing i need to fix to have it fully working.
Config->get() Only needs the key, so it's not the same as set(). I guess that you want to retrieve the data stored with the other code snippet. I would do something like this: PHP: $config->get($args[0]); However, this will return an array, so you have to handle it like one.
so PHP: $config = $this->getConfig();$config->get($args[0]);$a = $args[0]; Will this return what was sent as $leveled?
As I said, it returns an array of all the information stored, so it doesn't only return $leveled, but also $x, $y, $z. Depending on what information you want, you'll need to specify which entry from the array to choose. For $leveled, you'd do: PHP: $config->get($args[0][0]); Because it's the first entry in the array. I suggest learning a bit more about arrays soon, it'll be beneficial to understanding configs like this. I'm sure it worked, just not how you intended it to. Any errors you get, or letting us know what did happen compared to what you expected would be very useful.
Thx but that worked only to get the letters of check back (I only put 3 letters for the check name so 0, 1 and 2 got the check letters) and when I tried to get $leveled back by doing this PHP: $config->get($args[0][3]); It said that 3 was undefined so I tried it like this PHP: $config->get($args[1][0]); 1 is undefined.
Assuming you use this to save PHP: $config = $this->getConfig();$config->set($args[0],[$leveled, $x, $y, $z]);$config->save(); To retrieve you may use PHP: $config = $this->getConfig();$data = $config->get($args[0]);if(is_array($data)){ $leveled = $data[0]; $x = $data[1]; $y = $data[2]; $z = $data[3];}
Thanks but for some reason when that runs with this PHP: $config = $this->getConfig(); $data = $config->get($args[0]); if(is_array($data)){ $land = $data[0]; $x = $data[1]; $y = $data[2]; $z = $data[3]; } $sender->sendMessage(TextFormat::GOLD . "teleporting at $land, $x, $y, $z!"); $sender->teleport(new Position($land, $x, $y, $z)); [14:05:42] [Server thread/CRITICAL]: TypeError: "Argument 4 passed to pocketmine\level\Position::__construct() must be an instance of pocketmine\level\Level or null, float given, called in /root/plugins/EmeraldWarp-master/src/ElementalMinecraftGaming/EmeraldWarp/Main.php on line 67" (EXCEPTION) in "src/pocketmine/level/Position" at line 41
Thats not how you construct a Position object, it should be PHP: new Position($x,$y,$z,$this->getServer()->getLevelByName($land));// You should place the teleporting and sendMessage code inside the curly bracket of "if" to ensure that $x $y etc are initialised
the p the plugin doesn't even load when i do that. PHP: if (isset($args[0])) { $warp = $args[0]; $config = $this->getConfig(); $data = $config->get($args[0]); if(is_array($data)){ $land = $data[0]; $x = $data[1]; $y = $data[2]; $z = $data[3]; } $sender->sendMessage(TextFormat::GOLD . "Warping $warp at $land, $x, $y, $z!"); $sender->teleport(new Position($x , $y , $z, $this->getServer()->getLevelByName($land));