Saving a player's location into config

Discussion in 'Plugin Development' started by bballheat, Dec 16, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    bballheat

    With my plugin, I want each individual player's coordinates to be saved into the config.yml. I'm confused on writing the players location into the config, aswell as having the player's name saved, too.
    Please help! Thank you.
     
  2. Offline

    bryce325

    Save it as four values: World, X, Y, Z.
     
  3. Offline

    Milkywayz

    Yaw and Pitch too, better to add it now then later when someone requests him too. Yaw and Pitch makes the location more precise, since it would otherwise not position them correctly if teleporting / etc.
     
  4. Offline

    bballheat

    I already have a hashmap setup to save XYZ locations and then view the location again with a command. I need help with putting those coordinates into a config.
     
  5. Offline

    fireblast709

    Messy one-string:
    Code:java
    1. public String locToStr(Location l)
    2. {
    3. StringBuilder sb = new StringBuilder();
    4. sb.append(l.getWorld().getName()).append(",");
    5. sb.append(l.getX()).append(",");
    6. sb.append(l.getY()).append(",");
    7. sb.append(l.getZ()).append(",");
    8. sb.append(l.getYaw()).append(",");
    9. sb.append(l.getPitch()).append(",");
    10. return sb.toString();
    11. }

    Using separate paths (bigger version, but more overview in the config):
    Code:java
    1. public void saveToLocation(String path, Location l)
    2. {
    3. ConfigurationSection cfgLoc = getConfig().getConfigurationSection(path);
    4. if(cfgLoc == null)
    5. {
    6. cfgLoc = getConfig().createSection(path);
    7. }
    8. cfgLoc.set("x", l.getX());
    9. cfgLoc.set("y", l.getY());
    10. cfgLoc.set("z", l.getZ());
    11. cfgLoc.set("yaw", l.getYaw());
    12. cfgLoc.set("pitch", l.getPitch());
    13. saveConfig();
    14. }
     
  6. Offline

    bballheat

    Am I going to make another class for the config?
     
  7. Offline

    fireblast709

    you could, but it is not neccesary :3
     
Thread Status:
Not open for further replies.

Share This Page