1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Unable to get world name.

Discussion in 'Plugin Help' started by gsdgamer, Apr 24, 2017.

  1. gsdgamer

    gsdgamer Spider Jockey

    Messages:
    28
    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
     
  2. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    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
     
  3. xBeastMode

    xBeastMode Shog Chips

    Messages:
    0
    Show your code here and please use code blocks.
     
  4. gsdgamer

    gsdgamer Spider Jockey

    Messages:
    28
    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
     
  5. xBeastMode

    xBeastMode Shog Chips

    Messages:
    0
    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.
     
    jasonwynn10 likes this.
  6. gsdgamer

    gsdgamer Spider Jockey

    Messages:
    28
    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.
     
  7. Lowkey

    Lowkey Slime

    Messages:
    94
    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...
     
    Last edited: May 1, 2017
  8. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    $sender returns a CommandSender object
     
  9. Lowkey

    Lowkey Slime

    Messages:
    94
    Oops, edited :p
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.