Save Waypoints/Coordinates in .yml

Discussion in 'Plugin Development' started by Alias_Me, Jan 14, 2019.

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

    Alias_Me

    Im making a Waypoint plugin where players can build a specific structure (Guideposts) which can then be accessed as fast travel points, but only from other Guideposts.
    Ive got the events for when a Guidepost is created/destroyed all set, all I need to do now is write them to a file on creation and deletes them when a Guidepost is destroyed, but I`ve got no Idea how to do that in an efficient manner.

    EDIT: All Guardposts have to have a Name (which is written on a sign) to be valid
     
    Last edited: Jan 14, 2019
  2. Offline

    KarimAKL

    @Alias_Me Do you want 1 file with all the information or do you want a file for every guardpost?
     
  3. Offline

    Alias_Me

    @KarimAKL Preferrably a single File, but if its easier one for every post wouldnt be a problem
     
  4. Online

    timtower Administrator Administrator Moderator

    @Alias_Me Set the location based on the name as key, and the x,y,z,world as value. (might want to split it in 4 values)
    Then set the section to null when it gets destroyed.
     
  5. Offline

    KarimAKL

    In that case i would create the file onEnable and then write to it later.
    To write to the file you can do something like this:
    Code:Java
    1. File file = new File("path/to/file");
    2. FileConfiguration config = YamlConfiguration.load(file);
    3.  
    4. Player player = Bukkit.getPlayer("name");
    5. Location location = player.getLocation();
    6. config.set("path.in.file.world", location.getWorld().getName());
    7. config.set("path.in.file.x", location.getX());
    8. //etc
    9. config.save(file); //This line will need a try catch.

    Delete by doing 'config.set("path.in.file.world", null);' etc.
     
    torpkev likes this.
  6. Offline

    Alias_Me

    KarimAKL likes this.
Thread Status:
Not open for further replies.

Share This Page