|
| 1 | +/* |
| 2 | + * This file is part of ToolStats. |
| 3 | + * |
| 4 | + * ToolStats is free software: you can redistribute it and/or modify |
| 5 | + * it under the terms of the GNU General Public License as published by |
| 6 | + * the Free Software Foundation, either version 3 of the License, or |
| 7 | + * (at your option) any later version. |
| 8 | + * |
| 9 | + * ToolStats is distributed in the hope that it will be useful, |
| 10 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + * GNU General Public License for more details. |
| 13 | + * |
| 14 | + * You should have received a copy of the GNU General Public License |
| 15 | + * along with ToolStats. If not, see <https://www.gnu.org/licenses/>. |
| 16 | + */ |
| 17 | + |
| 18 | +package lol.hyper.toolstats.tools.config.versions; |
| 19 | + |
| 20 | +import lol.hyper.toolstats.ToolStats; |
| 21 | + |
| 22 | +import java.io.File; |
| 23 | +import java.io.IOException; |
| 24 | +import java.util.ArrayList; |
| 25 | +import java.util.Collections; |
| 26 | +import java.util.List; |
| 27 | + |
| 28 | +public class Version7 { |
| 29 | + |
| 30 | + private final ToolStats toolStats; |
| 31 | + |
| 32 | + /** |
| 33 | + * Used for updating from version 6 to 7. |
| 34 | + * |
| 35 | + * @param toolStats ToolStats instance. |
| 36 | + */ |
| 37 | + public Version7(ToolStats toolStats) { |
| 38 | + this.toolStats = toolStats; |
| 39 | + } |
| 40 | + |
| 41 | + /** |
| 42 | + * Perform the config update. |
| 43 | + */ |
| 44 | + public void update() { |
| 45 | + // save the old config first |
| 46 | + try { |
| 47 | + toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config-6.yml"); |
| 48 | + } catch (IOException exception) { |
| 49 | + toolStats.logger.severe("Unable to save config-5.yml!"); |
| 50 | + throw new RuntimeException(exception); |
| 51 | + } |
| 52 | + |
| 53 | + // we make this super verbose so that admins can see what's being added |
| 54 | + toolStats.logger.info("Updating config.yml to version 7."); |
| 55 | + toolStats.config.set("config-version", 7); |
| 56 | + |
| 57 | + toolStats.logger.info("Adding messages.flight-time to config.yml."); |
| 58 | + toolStats.config.set("messages.flight-time", "&7Flight time: &8{time}"); |
| 59 | + |
| 60 | + toolStats.logger.info("Adding enabled.flight-time to config.yml."); |
| 61 | + toolStats.config.set("enabled.flight-time", true); |
| 62 | + |
| 63 | + // save the config and reload it |
| 64 | + try { |
| 65 | + toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config.yml"); |
| 66 | + } catch (IOException exception) { |
| 67 | + toolStats.logger.severe("Unable to save config.yml!"); |
| 68 | + throw new RuntimeException(exception); |
| 69 | + } |
| 70 | + toolStats.loadConfig(); |
| 71 | + toolStats.logger.info("Config has been updated to version 7. A copy of version 5 has been saved as config-6.yml"); |
| 72 | + } |
| 73 | +} |
0 commit comments