Fixed autoupdate bugs

This commit is contained in:
Auxilor 2020-10-10 13:12:09 +01:00
parent 99f3861ad3
commit d8f0a2d2e9
3 changed files with 15 additions and 2 deletions

View File

@ -18,7 +18,7 @@ public abstract class EnchantmentYamlConfig {
private final String name;
public YamlConfiguration config;
private File configFile;
protected File configFile;
private final File directory;
private final double latestVersion;
private final JavaPlugin plugin = EcoEnchantsPlugin.getInstance();

View File

@ -1,6 +1,7 @@
package com.willfp.ecoenchants.config;
import com.willfp.ecoenchants.EcoEnchantsPlugin;
import org.bukkit.Bukkit;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
@ -32,19 +33,23 @@ public abstract class UpdatingLang {
public void update() {
try {
config.load(configFile);
Bukkit.getLogger().info("BEFORE: " + config.getKeys(true).toString());
InputStream newIn = EcoEnchantsPlugin.getInstance().getResource("lang.yml");
BufferedReader reader = new BufferedReader(new InputStreamReader(newIn, StandardCharsets.UTF_8));
YamlConfiguration newConfig = new YamlConfiguration();
newConfig.load(reader);
Bukkit.getLogger().info("NEW: " + newConfig.getKeys(true).toString());
newConfig.getKeys(true).forEach((s -> {
if (!config.getKeys(true).contains(s)) {
config.set(s, newConfig.get(s));
}
}));
Bukkit.getLogger().info("AFTER: " + config.getKeys(true).toString());
config.save(configFile);
config.load(configFile);
} catch (IOException | InvalidConfigurationException e) {
e.printStackTrace();
}

View File

@ -7,10 +7,12 @@ import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.enchantments.meta.EnchantmentRarity;
import com.willfp.ecoenchants.enchantments.meta.EnchantmentTarget;
import com.willfp.ecoenchants.util.Logger;
import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;
import java.io.IOException;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@ -106,5 +108,11 @@ public class EnchantmentConfig extends EnchantmentYamlConfig {
config.set("name", ConfigManager.getLang().getString("enchantments." + this.getName() + ".name"));
config.set("description", ConfigManager.getLang().getString("enchantments." + this.getName() + ".description"));
Logger.info("LOADED " + name + ".");
try {
this.config.save(this.configFile);
} catch (IOException e) {
e.printStackTrace();
}
}
}