Need help with Config.yml defaults

Discussion in 'Spigot Plugin Help' started by TJPlaysNow, May 16, 2017.

  1. So I've had this config thing for a long long time and have used it before but never actually tried using defaults until now. When doing so everything inside breaks. That is besides the top line, I don't know what to change and have looked into it a bit on the web if someone could please help me that'd be great!

    Code (Text):
    /** Creates a new config at the path, with the fileName, the default file name found in the jar, with a configCreate method caller, and uses the Plugin */
        public Config(String path, String fileName, String deffault, ConfigCreate configCreate, Plugin plugin) {
            if (!fileName.contains(".yml")) {
                fileName = fileName + ".yml";
            file = new File(path, fileName);
            fileConfig = YamlConfiguration.loadConfiguration(file);
            if (!file.exists()) {
                InputStream deffaultConfigStream = plugin.getResource(deffault);
                if (deffaultConfigStream == null) return;
                YamlConfiguration defConfig;
                if ((plugin.getDescription().getAwareness().contains(
                        PluginAwareness.Flags.UTF8))) {
                    defConfig = YamlConfiguration.loadConfiguration(new InputStreamReader(deffaultConfigStream, Charsets.UTF_8));
                } else {
                    defConfig = new YamlConfiguration();
                    byte[] contents;
                    try {
                        contents = ByteStreams.toByteArray(deffaultConfigStream);
                    } catch (IOException e) {
                        plugin.getLogger().log(Level.SEVERE, "Unexpected failure reading " + deffault, e);
                    String text = new String(contents, Charset.defaultCharset());
                    if (!(text.equals(new String(contents, Charsets.UTF_8)))) {
                        plugin.getLogger().warning("Default system encoding may have misread " + deffault + " from plugin jar");
                    try {
                    } catch (InvalidConfigurationException e) {
                        plugin.getLogger().log(Level.SEVERE, "Cannot load configuration from jar", e);
                try {
                } catch (IOException exception) {