Try to get a not existing Section.

Discussion in 'Plugin Development' started by MrFrozen, Mar 5, 2015.

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

    MrFrozen

    Code:
    public static void addLocation(Player p, int blockID, Location loc)
            {
                YamlConfiguration c = YamlConfiguration.loadConfiguration(PB.PocketB);
                String u = p.getUniqueId().toString();
                int blockint = 0;
                c.createSection(u);
                    /*if(!c.isSet(u + ".BLOCK" + blockint))
                    {
                        c.set(u + ".X", loc.getBlockX());
                        c.set(u + ".Y", loc.getBlockY());
                        c.set(u + ".Z", loc.getBlockZ());
                    }*/
                try {
                    c.save(PB.PocketB);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
    I like that it is checked whether there under the UUID the block identifier already exists. So when he looks Block1 exists or block2 beschikbar and if that is not available then block3 etc .. So he tries untill a blockID find that does not exist and then converts the data there.
     
    Last edited: Mar 5, 2015
  2. Offline

    pie_flavor

    @MrFrozen Your post is indecipherable. Please post with correct grammar. If you speak a different language please use Google Translate.
     
  3. Offline

    MrFrozen

    Changed!
     
  4. Offline

    Skionz

    @MrFrozen We still have no idea what you are talking about.
     
  5. Offline

    teej107

    Skionz likes this.
  6. Offline

    MrFrozen

    But does I try to find a not set config section until he found one..

    I did the thread edit with Google translate. But I want something that keep trying to find a section that isn't exsits so he can create one so under the section
    Code:
    Hey:
    he will try to find a not existing block. in this case he can add block1 that looks like this
    Code:
    Hey:
        Block1:
            X:
            Y:
            Z:
    and if he wanna add a block again and if block1 exists he will check if block2 isn't set. Now he isnt set so he add block2.

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

    Fuzzybear04

    Still no idea
     
  8. Offline

    teej107

    @MrFrozen
    pseudo code
    Code:
    while (getConfigurationSection(#n)) does not exist
    #n++;
     
  9. Offline

    MrFrozen

    Thanks for the pseudo code I can use this. Funny you know what I meant and they not. Thanks anyways

    This is what I have now:
    Code:
    public static void addLocation(Player p, int blockID, Location loc)
            {
                YamlConfiguration c = YamlConfiguration.loadConfiguration(PB.PocketB);
                String u = p.getUniqueId().toString();
                int blockint = 0;
                if(c.getConfigurationSection(u) == null)
                {
                    c.createSection(u);
                } else
                {
                    while(!c.isSet(u + ".BLOCK" + blockint))
                    {
                        c.set(u + ".X", loc.getBlockX());
                        c.set(u + ".Y", loc.getBlockY());
                        c.set(u + ".Z", loc.getBlockZ());
                    }
                   
                }
                try {
                    c.save(PB.PocketB);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
    But if the .BLOCK exists I need to increase the blockint, how to?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 13, 2016
Thread Status:
Not open for further replies.

Share This Page