Hi all, I'm new here and new to the PHP coding. I have started off writing myself a simple plugin which spawns in a player every time they join the server. I have got the x,y,z cords to be put into the config file but I am unable to get the world name. Could anyone here help at all. I've tried different ways but can;t seem to figure it out
1. This should be in the development (more like facepalm) section for coding help 2. You have given us no code to work with or to correct
Like I said i'm new to the forum and PHP. the code im using is this. Code: public function onCommand(CommandSender $sender, Command $cmd, $label, array $args){ if(!($sender instanceof Player)){ $sender->sendMessage("You cannot use this command in console."); }elseif ($sender instanceof Player){ if($cmd->getName() == "createhub"){ if(!(isset($args[0]))){ if($sender->hasPermission("create.hub") || $sender->isOp()){ $wname = $this->getServer()->getLevelByName();; $pos = $sender->getPosition(); $x = $pos->getX(); $y = $pos->getY(); $z = $pos->getZ(); $this->getConfig()->set("xpos", $x); $this->getConfig()->set("ypos", $y); $this->getConfig()->set("zpos", $z); $this->getconfig()->set("world", $wname); $this->getConfig()->save(); I apologize if the code looks terrible. This is just for myself as I am still learning
Like they say, the player object is a position itself, so you don't need to get it's position. You can simply call $player->getX(), $player->getLevel(), etc... You need to learn about objects and methods, that's how you can use that knowledge.
Yeah thanks for this. I've still a lot to learn. For some reason not I get Could not save config, Cannot serialize Server instance. The codes not changed apart from taking the world name out just to be positive my x,y,z where being updated. I'll do some more reading up on it all.
1. Syntax error @ getLevelByName. Only one semi-colon is needed... (you probably made a typo). 2. Try getFolderName() aswell! 3. Sender returns a CommandSender object, not a player if I'm thinking right. Try to use PHP: $player = $sender->getPlayer(); 4. Server::getLevelByName()? You haven't said which level...