diff --git a/src/main/java/pers/xanadu/enderdragon/config/FileUpdater.java b/src/main/java/pers/xanadu/enderdragon/config/FileUpdater.java index c76d38b..b01c985 100644 --- a/src/main/java/pers/xanadu/enderdragon/config/FileUpdater.java +++ b/src/main/java/pers/xanadu/enderdragon/config/FileUpdater.java @@ -1,10 +1,49 @@ package pers.xanadu.enderdragon.config; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; + import java.io.*; +import static pers.xanadu.enderdragon.EnderDragon.plugin; + public class FileUpdater { public static void update() throws IOException { - Lang.warn("Nothing to update."); + boolean updated = false; + File folder = new File(plugin.getDataFolder(),"setting"); + if(folder.exists()){ + File[] files = folder.listFiles(); + if(files != null){ + for(File file : files){ + FileConfiguration config = YamlConfiguration.loadConfiguration(file); + String ver = config.getString("version"); + if(!"2.4.0".equals(ver)) { + Lang.error("The version of setting/"+file.getName()+" is not supported!"); + continue; + } + updated = true; + String name = file.getName(); + Config.copyFile("setting/"+name,"new/setting/"+name,true); + } + File new_folder = new File(plugin.getDataFolder(),"new/setting/"); + files = new_folder.listFiles(); + if(files != null){ + for(File file : files){ + FileConfiguration fc = YamlConfiguration.loadConfiguration(file); + fc.set("version","2.5.4"); + fc.set("bossbar.create_fog",fc.getBoolean("bossbar.create_frog")); + fc.set("bossbar.create_frog",null); + fc.save(file); + } + } + } + } + if (updated){ + Lang.info("New config files are generated in plugins/EnderDragon/new."); + Lang.warn("Attention: Please confirm the accuracy before using new config!"); + } + else { + Lang.warn("Nothing to update!"); + } } - } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 7c8293e..787b463 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ name: EnderDragon -version: 2.5.3 +version: 2.5.4 main: pers.xanadu.enderdragon.EnderDragon author: Xanadu13 api-version: 1.13