For those of you who need a simple way of creating file saved data per-player, this is for you. Requirements: -Knowledge of simple Java -Knowledge of how to make a plugin First, add this class file to your plugin: Code:java package me.miclebrick; import java.io.File;import java.io.IOException;import java.util.*; import org.bukkit.configuration.file.FileConfiguration;import org.bukkit.configuration.file.YamlConfiguration; public class PlayerHelper {private static String name;public PlayerHelper(String par1PluginName){this.name = par1PluginName;}public static String getPlayerPath(String par1Name){return "plugins/"+name+"/userdata/" +par1Name.toLowerCase()+".yml";}public static void createNewData(String par1Name){File f = new File(getPlayerPath(par1Name));if(f.exists()){try {f.createNewFile();FileConfiguration pDat = YamlConfiguration.loadConfiguration(f);//Save data for the player. Example://pDat.set("path.to.object", value);pDat.save(f);} catch (IOException e) {e.printStackTrace();}}}public static FileConfiguration getPlayerConfigAsYAML(String par1Name){File f = new File(getPlayerPath(par1Name));createNewData(par1Name);return YamlConfiguration.loadConfiguration(f);}public static void setPlayerObject(String par1Name, String par2Path, Object par3Value){try{File f = new File(getPlayerPath(par1Name));createNewData(par1Name);FileConfiguration pDat = YamlConfiguration.loadConfiguration(f);pDat.set(par2Path, par3Value);pDat.save(f);} catch (IOException e) {e.printStackTrace();}}public static Object getPlayerObject(String par1Name, String par2Path){File f = new File(getPlayerPath(par1Name));createNewData(par1Name);FileConfiguration pDat = YamlConfiguration.loadConfiguration(f);return pDat.get(par2Path);}public static boolean checkIfPlayerHasData(String par1Name){File f = new File(getPlayerPath(par1Name));if(!f.exists()) return false;else return true;}} To give players their own data, do something like this. Code:java @EventHandlerpublic void createNewData(PlayerLoginEvent event){PlayerHelper ph = new PlayerHelper("YourPluginName");ph.createNewData(event.getPlayer().getName());} That would make it so that whenever a player logs in, it checks if the directory "plugins/YourPluginName/userdata/PlayerName.yml" exists. If it doesn't, then it creates that file, and adds your specified defaults to it. To get and set a player value, use ph.setPlayerObject() and ph.getPlayerObject(). Example: Code:java PlayerHelper ph = new PlayerHelper("YourPluginName");boolean doSomething = (boolean) ph.getPlayerObject("PlayerName", "do.something");if(doSomething){ph.setPlayerObject("PlayerName", "do.something", false);}ItemStack is = new ItemStack(Material.DIAMOND, 1);ph.setPlayerObject("PlayerName", "DIAMOND.item", is); Feel free to add custom methods and mess around with the class! Also, if you find any errors, please tell me and I'll fix it.
macguy8 True, but then you wouldn't be able to change the config and make the effects go into the game without reloading or restarting ... could you?
Miclebrick What do you mean? If you are trying to create a per player stats, ive already done this. Find it in my started threads.
DevRosemberg You do the same thing as he does In the fact of not caching it. Miclebrick Correct. However, most plugins don't allow you to live-edit, and in my opinion that lack of live-editing is something worth losing for the efficiency you'd gain by doing that EDIT by Moderator: merged posts, please use the edit button instead of double posting.