diff --git a/src/main/java/us/myles/ViaVersion/ViaVersionPlugin.java b/src/main/java/us/myles/ViaVersion/ViaVersionPlugin.java index 52933b5c4..34f53fae0 100644 --- a/src/main/java/us/myles/ViaVersion/ViaVersionPlugin.java +++ b/src/main/java/us/myles/ViaVersion/ViaVersionPlugin.java @@ -28,9 +28,7 @@ import us.myles.ViaVersion.util.ReflectionUtil; import java.io.File; import java.io.IOException; import java.lang.reflect.Field; -import java.util.List; -import java.util.Map; -import java.util.UUID; +import java.util.*; import java.util.concurrent.Callable; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeUnit; @@ -39,12 +37,11 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaVersionAPI { private final Map portedPlayers = new ConcurrentHashMap(); private boolean debug = false; - private FileConfiguration config; - private File configFile; @Override public void onEnable() { ViaVersion.setInstance(this); + saveDefaultConfig(); if (System.getProperty("ViaVersion") != null) { getLogger().severe("ViaVersion is already loaded, we don't support reloads. Please reboot if you wish to update."); getLogger().severe("Some features may not work."); @@ -59,18 +56,7 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaVersionAPI { getLogger().severe("Unable to inject handlers, are you on 1.8? "); e.printStackTrace(); } - - this.config = getFileConfiguration(); - if (!config.contains("checkforupdates")) { - config.set("checkforupdates", true); - try { - config.save(configFile); - } catch (IOException e1) { - this.getLogger().info("Unabled to write config.yml!"); - e1.printStackTrace(); - } - } - if (config.getBoolean("checkforupdates")) { + if (getConfig().getBoolean("checkforupdates")) { Bukkit.getPluginManager().registerEvents(new UpdateListener(this), this); UpdateUtil.sendUpdateMessage(this); } @@ -151,20 +137,6 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaVersionAPI { portedPlayers.remove(clientID); } - private FileConfiguration getFileConfiguration() { - if (!this.getDataFolder().exists()) - this.getDataFolder().mkdirs(); - this.configFile = new File(this.getDataFolder(), "config.yml"); - if (!this.configFile.exists()) - try { - this.configFile.createNewFile(); - } catch (IOException e) { - this.getLogger().info("Unable to create config.yml!"); - e.printStackTrace(); - } - return YamlConfiguration.loadConfiguration(this.configFile); - } - public static ItemStack getHandItem(final ConnectionInfo info) { try { return Bukkit.getScheduler().callSyncMethod(Bukkit.getPluginManager().getPlugin("ViaVersion"), new Callable() { @@ -182,4 +154,4 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaVersionAPI { return null; } } -} \ No newline at end of file +} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml new file mode 100644 index 000000000..5f02e58e1 --- /dev/null +++ b/src/main/resources/config.yml @@ -0,0 +1,2 @@ +#Should ViaVersion check for updates? +checkforupdates: true \ No newline at end of file