yamls not updating right?

Discussion in 'Plugin Development' started by nitrousspark, Dec 15, 2012.

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

    nitrousspark

    D:

    at this point i dont care, just give me code.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 30, 2016
  2. Offline

    fireblast709

    If your code is not working, you might have a problem elsewhere (or a stacktrace, as any problems with the Yaml class have a stacktrace)
     
  3. Offline

    nitrousspark

    well appearently i was allready given the answer in a format i didnt understand, so now im asking for it in a different format D:<
     
  4. Offline

    fireblast709

    what are you using to test it? (so when do you set it, and where is it not set anymore) please post a full snippet containing all code called between the setting and the getting that fails
     
  5. Offline

    nitrousspark

    ok, full explanation

    the plugin makes a player yaml or notepad in a folder, the name of the yaml is the players name
    Yaml yaml = this.getPlyaerYaml(player); - gets the yaml for the player
    yaml.add("rank", "default"); - if its not there it adds into the yaml this, rank: default
    yaml.set("rank", "default"); - if it is there it sets it to this, rank: default
    yaml.save(); - saves the yaml

    the problem is that it will set it to default, then it will change back after like 5 seconds, but sometimes it works fine

    heres the yaml class

    Code:
    package me.nitrousspark.server;
     
    import java.io.File;
    import java.io.IOException;
     
    import org.bukkit.configuration.file.YamlConfiguration;
    import org.bukkit.configuration.file.YamlConfigurationOptions;
     
    public class Yaml {
     
        private File file = null;
        private YamlConfiguration yaml = new YamlConfiguration();
     
        public Yaml(File file) {
     
            this.file = file;
     
            if (!file.exists()) {
     
                try {
                    file.createNewFile();
                } catch (IOException e) {
                    e.printStackTrace();
                }
     
            }
     
            // logger.log(Level.INFO,
            // "[AdvancedStorage] New Yaml file loaded. Path: " +
            // this.file.getAbsolutePath());
     
            this.load();
     
        }
     
        public Yaml(String path) {
     
            this.file = new File(path);
     
            if (!file.exists()) {
     
                try {
                    file.createNewFile();
                } catch (IOException e) {
                    e.printStackTrace();
                }
     
            }
     
            // logger.log(Level.INFO,
            // "[AdvancedStorage] New Yaml file loaded. Path: " +
            // this.file.getAbsolutePath());
     
            this.load();
     
        }
     
        private void load() {
     
            try {
                this.yaml.load(this.file);
            } catch (Exception e) {
                e.printStackTrace();
            }
     
        }
     
        /**
        * Save the Yaml's data to the file passed in the constructor.
        */
        public void save() {
     
            try {
                this.yaml.save(this.file);
            } catch (Exception e) {
                e.printStackTrace();
            }
     
        }
     
        /**
        * Get an Integer from the given path.
        *
        * @param s
        *            Path to the Integer.
        * @return Integer at given path.
        */
        public int getInteger(String s) {
     
            return this.yaml.getInt(s);
     
        }
     
        /**
        * Save, then load the Yaml file. **Warning** Very Unstable.
        */
        public void reload() {
     
            this.save();
     
            this.load();
     
        }
     
        /**
        * Get a String from the path defined.
        *
        * @param s
        *            Path to the String.
        * @return String at given path.
        */
        public String getString(String s) {
     
            return this.yaml.getString(s);
     
        }
     
        /**
        * Gets an Object at the given path.
        *
        * @param s
        *            Path to given Object.
        * @return An Object at the given Path.
        */
        public Object get(String s) {
     
            return this.yaml.get(s);
     
        }
     
        /**
        * Gets a boolean at the given path.
        *
        * @param s
        *            Path to the boolean.
        * @return Boolean at the given path.
        */
        public boolean getBoolean(String s) {
     
            return this.yaml.getBoolean(s);
     
        }
     
        /**
        * If the given path has no variable, it will be given a variable.
        *
        * @param s
        *            Path to look for.
        * @param o
        *            Variable to be assigned if not existing.
        */
        public void add(String s, Object o) {
     
            if (!this.contains(s)) {
     
                this.set(s, o);
     
            }
     
        }
     
        /**
        * Adds a String to a List of Strings.
        *
        * @param s
        *            Path to given String List.
        * @param o
        *            String to add to the String List.
        */
        public void addToStringList(String s, String o) {
     
            this.yaml.getStringList(s).add(o);
     
        }
     
        /**
        * Removes a String to a List of Strings.
        *
        * @param s
        *            Path to given String List.
        * @param o
        *            String to remove from the String List.
        */
        public void removeFromStringList(String s, String o) {
     
            this.yaml.getStringList(s).remove(o);
     
        }
     
        /**
        * Looks for a String List at given Path.
        *
        * @param s
        *            Path to String List.
        * @return String List at given Path.
        */
        public java.util.List<String> getStringList(String s) {
     
            return this.yaml.getStringList(s);
     
        }
     
        /**
        * Adds an Integer to a List of Integers.
        *
        * @param s
        *            Path to given Integer List.
        * @param o
        *            Integer to add to the Integer List.
        */
        public void addToIntegerList(String s, int o) {
     
            this.yaml.getIntegerList(s).add(o);
     
        }
     
        /**
        * Removes an Integer to a List of Integers.
        *
        * @param s
        *            Path to given Integer List.
        * @param o
        *            Integer to remove to the Integer List.
        */
        public void removeFromIntegerList(String s, int o) {
     
            this.yaml.getIntegerList(s).remove(o);
     
        }
     
        /**
        * Looks for a Integer List at given Path.
        *
        * @param s
        *            Path to Integer List.
        * @return Integer List at given Path.
        */
        public java.util.List<Integer> getIntegerList(String s) {
     
            return this.yaml.getIntegerList(s);
     
        }
     
        /**
        * Creates a new String List at given Path.
        *
        * @param s
        *            Path to create String List at.
        * @param list
        *            List to add.
        */
        public void createNewStringList(String s, java.util.List<String> list) {
     
            this.yaml.set(s, list);
     
        }
     
        /**
        * Creates a new Integer List at given Path.
        *
        * @param s
        *            Path to create Integer List at.
        * @param list
        *            List to add.
        */
        public void createNewIntegerList(String s, java.util.List<Integer> list) {
     
            this.yaml.set(s, list);
     
        }
     
        /**
        * **Untested/Unstable** Attempts to remove a variable at the given Path.
        *
        * @param s
        *            Path to given variable needing removal.
        */
        public void remove(String s) {
     
            this.set(s, null);
     
        }
     
        /**
        * Returns true if the given Path has a value.
        *
        * @param s
        *            Path to value.
        * @return True if the given Path has a value.
        */
        public boolean contains(String s) {
     
            return this.yaml.contains(s);
     
        }
     
        /**
        * Gets a double at the given Path.
        *
        * @param s
        *            Path to double.
        * @return Double at given Path.
        */
        public double getDouble(String s) {
     
            return this.yaml.getDouble(s);
     
        }
     
        /**
        * Sets a Object to the given Path.
        *
        * @param s
        *            Path to variable being assigned.
        * @param o
        *            Variable being assigned.
        */
        public void set(String s, Object o) {
     
            this.yaml.set(s, o);
     
        }
     
        /**
        * Increases an Integer by 1.
        *
        * @param s
        *            Path to Integer being incremented.
        */
        public void increment(String s) {
     
            this.yaml.set(s, this.getInteger(s) + 1);
     
        }
     
        /**
        * Decreases an Integer by 1.
        *
        * @param s
        *            Path to Integer being decremented.
        */
        public void decrement(String s) {
     
            this.yaml.set(s, this.getInteger(s) - 1);
     
        }
     
        /**
        * Increases an Integer by i.
        *
        * @param s
        *            Path to Integer being incremented.
        */
        public void increment(String s, int i) {
     
            this.yaml.set(s, this.getInteger(s) + i);
     
        }
     
        /**
        * Decreases an Integer by 1.
        *
        * @param s
        *            Path to Integer being decremented.
        */
        public void decrement(String s, int i) {
     
            this.yaml.set(s, this.getInteger(s) - i);
     
        }
     
        /**
        * Returns the YamlConfiguration's Options.
        *
        * @return YamlConfiguration's Options.
        */
        public YamlConfigurationOptions options() {
     
            return this.yaml.options();
     
        }
     
    }
    
    IM TIRED OF THIS GLICH

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 30, 2016
  6. Offline

    Sagacious_Zed Bukkit Docs

    Shut down your server before manually editing the yaml file. I suspect you have the plugin saving what it has in memory frequently.
     
  7. Offline

    nitrousspark

    i just want a fix for the problem D:<
    does anybody have their own yaml file they can send to me
     
  8. Offline

    Sagacious_Zed Bukkit Docs

    Even if your Yaml class is perfectly implemented, how you use the class can still lead to undesired behavior.
     
  9. Offline

    nitrousspark

    people are saying there is stuff wrong with it so WHATS THE FIX
     
  10. Offline

    Sagacious_Zed Bukkit Docs

    nitrousspark
    We mentioned that in your YAML class the implementation for adding to list is incorrect.
    As I mentioned before, to fix it "You can either modify the underlying list. or set the list again..."
    as YamlConfiguration's getStringList method returns a copy of the list stored in yaml.

    However, you mentioned that your current problem has nothing to do with the list implementation. And lacking all of the source code, I speculated that your problem may go away if you "Shut down your server before manually editing the yaml file. I suspect you have the plugin saving what it has in memory frequently."
     
  11. Offline

    nitrousspark

    ok, heres the problem, i dont understand, i didnt make the class. somebody made it for me, and i dont know where to put that code he gave me, and, the problem is not modifing the yamls manualy, but doing it within the plugin
     
  12. Offline

    Sagacious_Zed Bukkit Docs

    Then you should work to understand it, elements of object oriented design. my guess is that you are constructing more than once instance of your YAML class.
     
  13. Offline

    nitrousspark

  14. Offline

    Sagacious_Zed Bukkit Docs

    That is an unfortunate stance to take.
     
  15. Offline

    fireblast709

    nitrousspark it is possibly a bug caused by youor other code. That is what we continue to say, and that is why we continue to ask you for the rest of the code
     
  16. Offline

    nitrousspark

    my other code has been said

    Yaml yaml = this.getPlayerYaml(player);
    yaml.add("rank", "default");
    yaml.set("rank", "default");
    yaml.save();
     
  17. Offline

    fireblast709

    I am still missing the method "getPlayerYaml(player)"
     
  18. Offline

    nitrousspark

    public Yaml getPlayerYaml(Player player) {

    return new Yaml(this.getDataFolder().getAbsolutePath() + File.separator
    + "data" + File.separator + "players" + File.separator
    + player.getName() + ".yml");

    }
     
  19. Offline

    fireblast709

    Does it creates the files?
     
  20. Offline

    nitrousspark

  21. Offline

    fireblast709

    Working perfectly fine with me (except the bugs we already have pointed out). It just saves them and the data is not lost
     
  22. Offline

    nitrousspark

    so what can i do?
     
  23. Offline

    fireblast709

    not really a clue... you aren't using the config in async tasks are you? (just to be sure)
     
  24. Offline

    nitrousspark

    you mean anywhere in the code? if so yes i am
     
  25. Offline

    Sagacious_Zed Bukkit Docs

    Using them can cause unpredictable behavior, especially if you don't know what you are doing.
     
  26. Offline

    nitrousspark

    well in the places that its not working i dont have them. its just in some places.

    can somebody just give me their yaml file if they have one im tired of going back and forth

    this is why i said fuck it

    there have been like 50 posts and i still dont have a solution

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 30, 2016
  27. Offline

    ZeusAllMighty11

    nitrousspark

     
  28. Offline

    fireblast709

  29. Offline

    nitrousspark

    so how can i make a delay without async tasks?

    and do the async tasks effect when im getting something from the yamls?

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

    fireblast709

    nitrousspark probably, that is why people keep hammering on thread-safety ;3. Btw, you can just schedule a delayed task
    Code:java
    1. new BukkitRunnable()
    2. {
    3. @Override
    4. public void run()
    5. {
    6. // Delayed stuff
    7. }
    8. }.runTaskLater(<plugin instance/this (if in main class)>, delay_in_ticks);
     
Thread Status:
Not open for further replies.

Share This Page