Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Read config for coordinates

Comments in 'Plugin Development' started by MikkiMCPE, Aug 3, 2016.

  1. MikkiMCPE
    Offline

    MikkiMCPE Active Member

    Joined:
    May 16, 2015
    Posts:
    125
    Minecraft User:
    MikkiMC
    Hi!

    Anyone can tell me how to read config (yaml file) for X,Y,Z on my code?

    Code:
    x: 123
    y: 96
    z: 21
    
    that is an example for my file configuration, and my code will detect player if they are located on that coordinate then my plugin will do something, (maybe sendMessage or something secret xD)..

    thx y all btw, love pocketmine
  2. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Huh?
    Use
    PHP:
    $cfg $this->getConfig();
    $x $cfg->get("x");
    // etc, same for y, z
    Of course, you will need to have a config file for this. If you don't, create one in the resources folder and use $this->saveDefaultConfig() in onEnable().
    MikkiMCPE likes this.
  3. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    My way
    Code:
    player: x:y:z:world
    
    or
    Code:
    player:
     x: 123
     "y": 96
     z: 21
    
    MikkiMCPE and TheDeibo like this.
  4. TheDeibo
    Offline

    TheDeibo Notable Member Plugin Developer

    Joined:
    Sep 8, 2014
    Posts:
    692
    Plugins:
    1
    Minecraft User:
    TheDeibo
    That one works better. So @Primus, do you know why we need "y" With quotes?
  5. ImagicalGamer
    Offline

    ImagicalGamer Active Member

    Joined:
    Feb 25, 2016
    Posts:
    141
    Minecraft User:
    ImagicalGamer
    It adds the y in quotes when writing to a config it's weird.
  6. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    TheDeibo and ImagicalGamer like this.
  7. SOFe
    Offline

    SOFe Banned

    Joined:
    May 28, 2016
    Posts:
    386
    Minecraft User:
    Herobrine
    Further citation:
    Code:
    $ ./php -r 'var_dump(yaml_parse("player:
    >   x: 123
    >   y: 456
    >   z: 789"));'
    array(1) {
      ["player"]=>
      array(3) {
        ["x"]=>
        int(123)
        [1]=>         <------- Wow!
        int(456)
        ["z"]=>
        int(789)
      }
    }
    Last edited: Aug 6, 2016
    Survingo and Primus like this.
  8. MikkiMCPE
    Offline

    MikkiMCPE Active Member

    Joined:
    May 16, 2015
    Posts:
    125
    Minecraft User:
    MikkiMC
    ok, thanks y'all

Share This Page

Advertisement