|
5 | 5 | import org.bukkit.ChatColor; |
6 | 6 | import org.bukkit.command.Command; |
7 | 7 | import org.bukkit.command.CommandSender; |
| 8 | +import org.bukkit.configuration.file.FileConfiguration; |
8 | 9 | import org.bukkit.event.Event; |
9 | 10 | import org.bukkit.plugin.PluginDescriptionFile; |
10 | 11 | import org.bukkit.plugin.PluginManager; |
11 | 12 | import org.bukkit.plugin.java.JavaPlugin; |
| 13 | +import org.bukkit.util.FileUtil; |
12 | 14 | import org.jetbrains.annotations.NotNull; |
13 | 15 | import org.wargamer2010.signshop.blocks.SignShopBooks; |
14 | 16 | import org.wargamer2010.signshop.blocks.SignShopItemMeta; |
15 | 17 | import org.wargamer2010.signshop.commands.*; |
16 | 18 | import org.wargamer2010.signshop.configuration.ColorUtil; |
17 | 19 | import org.wargamer2010.signshop.configuration.SignShopConfig; |
18 | 20 | import org.wargamer2010.signshop.configuration.Storage; |
| 21 | +import org.wargamer2010.signshop.configuration.configUtil; |
19 | 22 | import org.wargamer2010.signshop.listeners.SignShopBlockListener; |
20 | 23 | import org.wargamer2010.signshop.listeners.SignShopLoginListener; |
21 | 24 | import org.wargamer2010.signshop.listeners.SignShopPlayerListener; |
|
25 | 28 | import org.wargamer2010.signshop.player.PlayerMetadata; |
26 | 29 | import org.wargamer2010.signshop.timing.TimeManager; |
27 | 30 | import org.wargamer2010.signshop.util.DataConverter; |
| 31 | +import org.wargamer2010.signshop.util.SSTimeUtil; |
28 | 32 | import org.wargamer2010.signshop.util.commandUtil; |
29 | 33 | import org.wargamer2010.signshop.worth.CMIWorthHandler; |
30 | 34 | import org.wargamer2010.signshop.worth.EssentialsWorthHandler; |
|
38 | 42 | import java.util.logging.*; |
39 | 43 |
|
40 | 44 | public class SignShop extends JavaPlugin { |
| 45 | + public static final int DATA_VERSION = 3; |
41 | 46 | private static final Logger logger = Logger.getLogger("Minecraft"); |
42 | 47 | private static final Logger transactionlogger = Logger.getLogger("SignShop_Transactions"); |
43 | 48 | public static WorthHandler worthHandler; |
44 | 49 | private static SignShop instance; |
45 | 50 | //Statics |
46 | 51 | private static Storage store; |
47 | 52 | private static TimeManager manager = null; |
48 | | - public static final int DATA_VERSION = 3; |
49 | 53 | //Permissions |
50 | 54 | private static boolean USE_PERMISSIONS = false; |
51 | 55 | // Commands |
@@ -117,6 +121,9 @@ public void onEnable() { |
117 | 121 |
|
118 | 122 | setupCommands(); |
119 | 123 |
|
| 124 | + // Backup config if it is an old version |
| 125 | + backupOldConfig(); |
| 126 | + |
120 | 127 | SignShopConfig.init(); |
121 | 128 | SignShopBooks.init(); |
122 | 129 | PlayerMetadata.init(); |
@@ -278,6 +285,21 @@ private void registerSSListeners() { |
278 | 285 | pm.registerEvents(new SharedMoneyTransaction(), this); |
279 | 286 | } |
280 | 287 |
|
| 288 | + private void backupOldConfig() { |
| 289 | + FileConfiguration ymlThing = configUtil.loadYMLFromPluginFolder(SignShopConfig.configFilename); |
| 290 | + File configFile = new File(SignShop.getInstance().getDataFolder(), SignShopConfig.configFilename); |
| 291 | + |
| 292 | + if ((ymlThing != null && configFile.exists()) |
| 293 | + && (!ymlThing.isSet("ConfigVersionDoNotTouch") || ymlThing.getInt("ConfigVersionDoNotTouch") != SignShopConfig.getConfigVersionDoNotTouch())) { |
| 294 | + |
| 295 | + SignShop.log("Old config detected, backing it up before modifiying it.", Level.INFO); |
| 296 | + File configBackup = new File(SignShop.getInstance().getDataFolder(), "configBackup" + SSTimeUtil.getDateTimeStamp() + ".yml"); |
| 297 | + FileUtil.copy(configFile, configBackup); |
| 298 | + ymlThing.set("ConfigVersionDoNotTouch", SignShopConfig.getConfigVersionDoNotTouch()); |
| 299 | + SignShopConfig.saveConfig(ymlThing, configFile); |
| 300 | + } |
| 301 | + } |
| 302 | + |
281 | 303 | private static class TransferFormatter extends Formatter { |
282 | 304 | private final DateFormat df = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss.SSS"); |
283 | 305 |
|
|
0 commit comments