So I am wanting to see if the plugin version is the same as a config version so I can match them up. This is checked every time a player joins after: Code (Text): if (!file.exists()) { To see if they actually have their own config, that's not the problem, the problem is this: Code (Text): if (config.getString("ConfigVERSION") != plugin.getDescription().getVersion()) { So if the players config and the plugin version are not the same then it will check for all of the objects/'things' that should be in the config, is there a better/more efficient way of doing this: Code (Text): if (config.getString("ConfigVERSION") == null) { config.set("ConfigVERSION", plugin.getDescription().getVersion()); } if (config.getString("CurrentName") == null) { config.set("CurrentName", player.getName()); } if (config.getString("Rank") == null) { config.set("Rank", "Default"); } if (config.getString("Warnings") == null) { config.set("Warnings", 0); } So it doesn't overwrite data that is already there, but adds the default settings if they don't have it in their config, and at the end I have this: Code (Text): System.out.println(player.getName() + " data updated!"); This is always printed in the console and I don't know why so the only reason I have for it is that there is something wrong with this code: Code (Text): if (config.getString("ConfigVERSION") != plugin.getDescription().getVersion()) {
How would it look? I'm getting NullPointerException with: Code (Text): if (!config.getString("ConfigVERSION").equals(plugin.getDescription().getVersion().toString())) { config.set("ConfigVERSION", plugin.getDescription().getVersion()); //etc
2nd Question, anyway to "shorten" this?: Code (Text): if (config.getString("ConfigVERSION") == null) { config.set("ConfigVERSION", plugin.getDescription().getVersion()); } if (config.getString("CurrentName") == null) { config.set("CurrentName", player.getName()); } if (config.getString("Rank") == null) { config.set("Rank", "Default"); } if (config.getString("Warnings") == null) { config.set("Warnings", 0); }
Are you creating individual file for each player? If you make it all in one file, you can easily shorten it.
Code (Text): if (config.getString("ConfigVERSION") == null) { config.set("ConfigVERSION", plugin.getDescription().getVersion()); } Remove if. Code (Text): config.set("ConfigVERSION", plugin.getDescription().getVersion());
OHOHOOH Code (Text): @EventHandler public void onPlayerJoin(PlayerJoinEvent e) { String u = e.getPlayer().getUniqueId().toString(); if (!(plugin.getConfig().contains(u)) { plugin.getConfig().set(u + ".Example, "Test"); plugin.saveConfig(); plugin.getLogger().info("Created info for " + u); return; } plugin.getLogger().info("Info already exists for " + u); }
Code (Text): public static HashMap<Player, HashMap> players = new HashMap<Player, HashMap>(); { HashMap<String, String> info = new HashMap<String, String>(); info.put("Warnings", "0"); info.put("Name", player.getName()); //other informations players.put(player, info); } Try this.
Nono.. the players already have their seperated configs loaded into a seperate folder named their UUIDs. I just need to know how to add the data inside of the config if I decide to add another value rather than having like 10 if statements.
Why are you having separate files for each player? Not only that, but why each inside a folder with their UUID? Anyway, Try using a for loop.
So I can store data for each separate player? Like how many times they've been banned, their rank, etc..?
Well that's you? I rather not have to open a big file size, easier just to search for a player's uuid
Tru, it's up to personal preference. Anyway, back to topic, I'll give you this to put you on track: Code (Text): for (String s : config.getKeys(false) { if (config.get(s).equals(null)) { config.set(s, 0); //example value } }