Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Example extends JavaPlugin {
- // Copy from here...
- public static FileConfiguration userdata = null;
- private static File userdataConfigFile = null;
- // You can rename the methods to anything you like. Userdata is just what I call it.
- // Also, in onEnable(), use loadUserdata() and to save it, use saveUserdata(). Simple enough.
- public void reloadUserdata() {
- if (userdataConfigFile == null) {
- userdataConfigFile = new File(getDataFolder(), "userdata.yml");
- }
- userdata = YamlConfiguration.loadConfiguration(userdataConfigFile);
- InputStream defConfigStream = getResource("userdata.yml");
- if (defConfigStream != null) {
- YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
- userdata.setDefaults(defConfig);
- }
- }
- public void loadUserdata(){
- userdata = getUserdata();
- userdata.options().copyDefaults(true);
- saveUserdata();
- }
- public FileConfiguration getUserdata() {
- if (userdata == null) {reloadUserdata();}
- return userdata;
- }
- public static void saveUserdata() {
- if (userdata == null || userdataConfigFile == null) {
- return;
- }
- try {
- userdata.save(userdataConfigFile);
- } catch (IOException ex) {
- Util.sendPluginInfo("Could not save config to " + userdataConfigFile.getName() + ex);
- }
- }
- // ...To here!
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement