Hey! What I'm trying to do is make a path and each line of the path has it's own value, allowing me to see a players stats. How would I do that? My current code is below. Code: @Override public void onEnable() { System.out.println("[Blink] The plugin has been enabled!"); Bukkit.getServer().getPluginManager().registerEvents(this, this); Bukkit.getServer().getPluginManager().registerEvents(new Game(), this); Bukkit.getServer().getPluginManager().registerEvents(new Shop(), this); Bukkit.getServer().getPluginManager().registerEvents(new Chat(), this); Bukkit.getServer().getPluginManager().registerEvents(new Scoreboard(), this); for (Player player : Bukkit.getOnlinePlayers()) { getConfig().getList("player.uuid.tokens"); this.getConfig().set("player", player.getName()); this.getConfig().set(".uuid", player.getUniqueId().toString()); this.saveConfig(); if (!new File(getDataFolder(), "config.yml").exists()) { saveDefaultConfig(); } } } @Override public void onDisable() { System.out.println("[Blink] The plugin has been disabled!"); List<String> s = getConfig().getStringList("tokens"); for (Player p : Bukkit.getOnlinePlayers()) { s.add("" + tokens.get(p)); } getConfig().set(".tokens", s); saveConfig(); } Note! Please do not worry about the other classes, they do not really affect the config.
I would suggest creating a path first, from which you can connect to other functions related to your config. Code: World w ; // Don't forget to initialize the variable! Player p; // Don't forget to initialize the variable! String path = w.getName() + "." + p.getName() + "."; // Now, I would suggest setting your configuration as you see fit this.getConfig().set(path + "uuid." + uuidVar); this.getConfig().set(path + "tokens." + tokenVar);
@MarinD99 Now the only thing that is showing is tokens. I have initialized the variables. Code: @Override public void onEnable() { System.out.println("[Blink] The plugin has been enabled!"); for (Player player : Bukkit.getOnlinePlayers()) { Player p = player; World w = p.getWorld(); String path = w.getName() + "." + p.getName() + "."; this.getConfig().set(path + "uuid.", p.getUniqueId().toString()); this.getConfig().set(path + "tokens.", tokens.get(p)); this.saveConfig(); if (!new File(getDataFolder(), "config.yml").exists()) { saveDefaultConfig(); } } } @Override public void onDisable() { System.out.println("[Blink] The plugin has been disabled!"); List<String> s = getConfig().getStringList("tokens"); for (Player p : Bukkit.getOnlinePlayers()) { s.add("" + tokens.get(p)); } getConfig().set(".tokens", s); saveConfig(); }
@kampai Do you crete the config file? Because I see you check, if it exists, and just then save, but when do you create it? Edit: checked your code again, and found my answer Edit2.: I thin I found the problem, in the onDisable method, you did getConfig().set(".tokens") instead of the path + the "tokens." String. And by the way, you don't need a "." on the end of the path.
Now it's doing tokens: - 'null' - world.Millionare.9 When the plugin is disabled (via reloading) But when its enabled it does this world: Millionare: uuid: I know why it's not showing the tokens on enable but why is it putting everything under tokens? Is it because I set the path under the tokens string? Code: @Override public void onEnable() { System.out.println("[Blink] The plugin has been enabled!"); Bukkit.getServer().getPluginManager().registerEvents(this, this); Bukkit.getServer().getPluginManager().registerEvents(new Game(), this); Bukkit.getServer().getPluginManager().registerEvents(new Shop(), this); Bukkit.getServer().getPluginManager().registerEvents(new Chat(), this); Bukkit.getServer().getPluginManager().registerEvents(new Scoreboard(), this); for (Player player : Bukkit.getOnlinePlayers()) { Player p = player; World w = p.getWorld(); String path = w.getName() + "." + p.getName() + "."; this.getConfig().set(path + "uuid", p.getUniqueId().toString()); this.getConfig().set(path + "tokens", tokens.get(p)); this.saveConfig(); if (!new File(getDataFolder(), "config.yml").exists()) { saveDefaultConfig(); } } } @Override public void onDisable() { System.out.println("[Blink] The plugin has been disabled!"); List<String> s = getConfig().getStringList("tokens"); for (Player player : Bukkit.getOnlinePlayers()) { Player p = player; World w = p.getWorld(); String path = w.getName() + "." + p.getName() + "."; s.add(path + tokens.get(p)); } getConfig().set(".tokens", s); saveConfig(); }
What I gave you was but a mere example of how paths are used in a config. It's not showing anything more apart from tokens because I haven't assigned it to. Create your own path, depending on what you'd like to use.
Yeahh I realized that but I think that the problem is I added the path to the string tokens instead of the other way around. How would I check if a player isn't in a hashmap add the value 0 to the config?
Code: If(!certainHashMap().contains(p, p.getName())) { // Not recommended to store a player's name, rather use a UUID this.getConfig().set(path, null); } Keep in mind once again, this is but a mere example. Apply to your own code as necessary.