Saving and reading multiple locations

Discussion in 'Plugin Development' started by iFamasssxD, Jul 8, 2013.

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

    iFamasssxD

    How would I format saving a chest to the config then reading it if theres more than one location in there? (Location being X, Y, Z) not all the bukkit location crap.

    This may be a bit vague. When I run a command it saves a chests location that I am looking at to the config. What is a good was so when a bukkit task comes along it can read the configs location and set all spaces needed to a chest.

    I have the setting locations Im just not sure what the best format is for saving and reading from a big list if it gets to be alot of locations. If it doesnt feel free to ask questions. I really appreciate it.
     
  2. Offline

    tills13

    use this to get which block the player is looking at.

    (Chest) block to get the chest (you can read the inventory from here using getBlockInventory()) or block.getX() etc to get location.

    Look at FileConfiguration to handle saving/loading. Or just can just save them as a list of the three values.
     
  3. Offline

    iFamasssxD

    tills13 i appreciate your response but that is not at all what i was looking for. I am saying how to read a big list of locations in the config when a bukkit task is fired. And what is the proper format for saving so its easy to read. I want chests to be spawned at these locations. Do not worry about the loot i have that its just the reading the list of locations part.

    Really I need to know how I would save the locations in a specific format so I can easily iterate through them. Once i have the locations I can do the rest. Just the formatting is whats getting to me.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
  4. Offline

    artish1

    edit: heres the counter variable, you can create this counter in the config since it counts more the config
    Code:
    public int counter = getConfig().getInt("Counter");
    And then the getting the locations
    Code:
    Location loc = whatever.
    getConfig().addDefault("Locations.Chests."+ counter + ".X", loc.getBlockX );
    getConfig().addDefault("Locations.Chests."+ counter + ".Y", loc.getBlockY );
    getConfig().addDefault("Locations.Chests."+ counter + ".Z", loc.getBlockZ );
    getConfig().set("Counter", counter);
    
    And then heres a loop i created that gets ALL the chests locations.
    Code:
    for(int count = 0;plugin.getConfig().contains("Locations.Chests."  + count + ".X"); count++){
                Location loc = new Location(Bukkit.getWorld("world"),
                        plugin.getConfig().getDouble("Locations.Chests."  + count + ".X"),
                        plugin.getConfig().getDouble("Locations.Chests."  + count + ".Y"),
                        plugin.getConfig().getDouble("Locations.Chests."  + count + ".Z"));
                //And you could like add this location in a list, ex: List<Location locs = new ArrayList<Location>();               
            }
     
    iFamasssxD likes this.
  5. Offline

    iFamasssxD

Thread Status:
Not open for further replies.

Share This Page