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

How to save, get info from config.yml?

Comments in 'Plugin Development' started by minebuilder0110, Sep 20, 2015.

  1. minebuilder0110
    Offline

    minebuilder0110 Notable Member

    Joined:
    Dec 8, 2014
    Posts:
    485
    Minecraft User:
    Apparitional
    Hello. I'm trying to create a home plugin, and as a very inexperienced coder, this is a serious challenge for me. I already know how to get strings from config.yml (was it $this->getConfig()->get("stuff")?), but I don't know how to get
    Code:
    - 0110
     - survival
     - 54 <-- This
     - 12
     - -11
    (in other words, an info which is 54 in this case which is inside of 0110's info).
    If by any chance you have time to explain how to teleport players, please do so. Thank you in advance :D
  2. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    To teleport players is simple:
    PHP:
    $pos = new Position($x$y$z$level);
    $player->teleport($pos);
  3. Kvetinac97
    Offline

    Kvetinac97 Active Member Plugin Developer

    Joined:
    Nov 17, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    Kvetinac97
    Put this into onCommand function, of course you'll need check if isset($args[1]) and if $args[0] == "home"...
    PHP:
    $name $args[1];
    $array $this->getConfig()->getAll();
    $sender->teleport(new Position($array[$name][1],$array[$name][2],$array[$name][3],$array[$name][0]));
  4. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    You should save and get using strtolower() otherwise there would be problems with saving/getting correctly:
    PHP:
    $name strtolower($args[1]);
  5. minebuilder0110
    Offline

    minebuilder0110 Notable Member

    Joined:
    Dec 8, 2014
    Posts:
    485
    Minecraft User:
    Apparitional
    But how do I make it so that the format of the config come up as:
    homes:
    <PlayerName>:
    - <World>
    - <X>
    - <Y>
    - <Z>
    ?
  6. MCPEGamerJP
    Offline

    MCPEGamerJP New Member

    Joined:
    Mar 31, 2015
    Posts:
    17
    Minecraft User:
    MCPEGamerJP
    Ok, you can already set the XYZ coordinates as $config right?
    You can make the command as eg ExamplePlugin.homes and select $world.
    I don't think you can select players though...
  7. minebuilder0110
    Offline

    minebuilder0110 Notable Member

    Joined:
    Dec 8, 2014
    Posts:
    485
    Minecraft User:
    Apparitional
    Also, as the title says, I really need a way to save. I only know how to get it, but not save it with format, or even create .yml file for each player like simpleauth or aliases.
    PHP:
    if($command->getName() === "sethome") {
                if(
    count($args) !== 1){
                    
    $sender->sendMessage(TextFormat::RED "Usage: /sethome <Home Name>");
                return 
    false;
                }
                if(!
    $sender instanceof Player){
                
    $sender->sendMessage(TextFormat::RED "This command is valid in-game only.");
                return 
    false;
                }
                else {
                   [
    SPOILER="Save to config code"]What goes in here?[/SPOILER]
                }
  8. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Use the default config. Remember to save default config!
    Minecrafter9203 and MCPEGamerJP like this.
  9. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    A config file is for configuration, not for saving data, actually.
  10. MCPEGamerJP
    Offline

    MCPEGamerJP New Member

    Joined:
    Mar 31, 2015
    Posts:
    17
    Minecraft User:
    MCPEGamerJP
    It doesn't really make a difference though, because config saves your configuration into the file that you inserted it in.
  11. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    *clap clap* You finally figured it out!
  12. MCPEGamerJP
    Offline

    MCPEGamerJP New Member

    Joined:
    Mar 31, 2015
    Posts:
    17
    Minecraft User:
    MCPEGamerJP
    I'm not stupid -_-
  13. FlamingGenius
    Offline

    FlamingGenius Active Member

    Joined:
    Sep 23, 2015
    Posts:
    173
    Minecraft User:
    FlamingGenius
    For me the simplest way of doing thigs was to create a config file in resources
    Code:
    ---
    key1: value1
    key2: value2
    ...
    
    Key is what you need to get the value

    Then to save the resource file you need to add this into your onEnable function which will save the config files in your resources folder

    PHP:
    public function onEnable(){
     
    $this->saveDefaultConfig();
    }
    Then your all set as far as setting up and then to get data from your config you can use this
    PHP:
    $variable $this->getConfig()->get("key1");

    return 
    $variable;
    This will return value1

    Like and follow if i helped you :D
    minebuilder0110 likes this.
  14. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Personally, I prefer creating a new Config class ;)
  15. FlamingGenius
    Offline

    FlamingGenius Active Member

    Joined:
    Sep 23, 2015
    Posts:
    173
    Minecraft User:
    FlamingGenius
    Thats the wonderful thing about coding nothing is set in stone you can code the same thing a million different ways(some maybe more effiecient then others):p;)
    Legoboy0215 likes this.
  16. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    You can always create the database that suits you the most. For example, https://github.com/LegendOfMCPE/Poc...rc/pocketfactions/tasks/WriteDatabaseTask.php
    Note: don't store objects into AsyncTask fields like me. I was doing wrongly. It will crash the server if it was done carelessly.
    FlamingGenius likes this.
  17. Taki21
    Offline

    Taki21 New Member

    Joined:
    Sep 24, 2015
    Posts:
    11
    Minecraft User:
    Taki21
    I don't know exactly if this works:

    PHP:
    $this->config->get("PlayerTaki",get("x"));
  18. Vaivez66
    Offline

    Vaivez66 Notable Member Plugin Developer

    Joined:
    Jun 10, 2015
    Posts:
    402
    Plugins:
    2
    Bumping thread 2 months ago?
  19. Taki21
    Offline

    Taki21 New Member

    Joined:
    Sep 24, 2015
    Posts:
    11
    Minecraft User:
    Taki21
    Oh my, you are right
  20. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    This is PHP, not Java. You have to call the get () function upon an object, i.e. $this->config.
    It
    applqpak likes this.

Share This Page

Advertisement