Introduced updater for config.yml

Signed-off-by: DroppingAnvil <dr0pping.4nvi1@gmail.com>
This commit is contained in:
DroppingAnvil 2019-11-05 17:15:42 -06:00
parent d590d854ce
commit d3870731f4
3 changed files with 33 additions and 4 deletions

View File

@ -185,17 +185,19 @@ public class FactionsPlugin extends MPlugin {
// Load Conf from disk // Load Conf from disk
Conf.load(); Conf.load();
//Dependency checks //Dependency checks
if (Conf.dependencyCheck && (Bukkit.getPluginManager().isPluginEnabled("Vault") && Bukkit.getPluginManager().isPluginEnabled("Essentials"))) { if (Conf.dependencyCheck && (!Bukkit.getPluginManager().isPluginEnabled("Vault") && !Bukkit.getPluginManager().isPluginEnabled("Essentials"))) {
RegisteredServiceProvider<Economy> rsp = FactionsPlugin.this.getServer().getServicesManager().getRegistration(Economy.class);
FactionsPlugin.econ = rsp.getProvider();
} else if (Conf.dependencyCheck) {
divider(); divider();
System.out.println("You are missing dependencies!"); System.out.println("You are missing dependencies!");
System.out.println("Please verify EssentialsX and Vault are installed!"); System.out.println("Please verify EssentialsX and Vault are installed!");
Conf.save();
Bukkit.getPluginManager().disablePlugin(instance); Bukkit.getPluginManager().disablePlugin(instance);
divider(); divider();
return; return;
} }
//Update their config if needed
Updater.updateIfNeeded(getConfig());
RegisteredServiceProvider<Economy> rsp = FactionsPlugin.this.getServer().getServicesManager().getRegistration(Economy.class);
FactionsPlugin.econ = rsp.getProvider();
com.massivecraft.factions.integration.Essentials.setup(); com.massivecraft.factions.integration.Essentials.setup();
hookedPlayervaults = setupPlayervaults(); hookedPlayervaults = setupPlayervaults();
FPlayers.getInstance().load(); FPlayers.getInstance().load();

View File

@ -0,0 +1,26 @@
package com.massivecraft.factions.util;
import com.massivecraft.factions.FactionsPlugin;
import org.bukkit.configuration.file.FileConfiguration;
import java.io.File;
import java.io.IOException;
public class Updater {
public static double currentVersion = 1.0;
public static void updateIfNeeded(FileConfiguration conf) {
double version = conf.getDouble("Config-Version", 0);
//Previous version
if (version == 0) {
//Instructions for this configuration to be updated to current
FactionsPlugin.getInstance().log("Your config.yml is pre-versioning so we are going to assign it version 1.0 \n Please regenerate your config.yml if you run into any errors relating to config.");
conf.set("Config-Version", 1.0);
version = 1.0;
}
//End with save + reload
try {
conf.save(new File("plugins/Factions/config.yml"));
FactionsPlugin.getInstance().reloadConfig();
} catch (IOException e) {e.printStackTrace();}
}
}

View File

@ -1,3 +1,4 @@
Config-Version: 1.0
# SaberFactions by Driftay # SaberFactions by Driftay
# Report issues: https://github.com/Driftay/Saber-Factions/issues/new # Report issues: https://github.com/Driftay/Saber-Factions/issues/new
# Live support: https://discord.gg/TFxWKeX # Live support: https://discord.gg/TFxWKeX