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; private final String name;
public YamlConfiguration config; public YamlConfiguration config;
private File configFile; protected File configFile;
private final File directory; private final File directory;
private final double latestVersion; private final double latestVersion;
private final JavaPlugin plugin = EcoEnchantsPlugin.getInstance(); private final JavaPlugin plugin = EcoEnchantsPlugin.getInstance();

View File

@ -1,6 +1,7 @@
package com.willfp.ecoenchants.config; package com.willfp.ecoenchants.config;
import com.willfp.ecoenchants.EcoEnchantsPlugin; import com.willfp.ecoenchants.EcoEnchantsPlugin;
import org.bukkit.Bukkit;
import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
@ -32,19 +33,23 @@ public abstract class UpdatingLang {
public void update() { public void update() {
try { try {
config.load(configFile);
Bukkit.getLogger().info("BEFORE: " + config.getKeys(true).toString());
InputStream newIn = EcoEnchantsPlugin.getInstance().getResource("lang.yml"); InputStream newIn = EcoEnchantsPlugin.getInstance().getResource("lang.yml");
BufferedReader reader = new BufferedReader(new InputStreamReader(newIn, StandardCharsets.UTF_8)); BufferedReader reader = new BufferedReader(new InputStreamReader(newIn, StandardCharsets.UTF_8));
YamlConfiguration newConfig = new YamlConfiguration(); YamlConfiguration newConfig = new YamlConfiguration();
newConfig.load(reader); newConfig.load(reader);
Bukkit.getLogger().info("NEW: " + newConfig.getKeys(true).toString());
newConfig.getKeys(true).forEach((s -> { newConfig.getKeys(true).forEach((s -> {
if (!config.getKeys(true).contains(s)) { if (!config.getKeys(true).contains(s)) {
config.set(s, newConfig.get(s)); config.set(s, newConfig.get(s));
} }
})); }));
Bukkit.getLogger().info("AFTER: " + config.getKeys(true).toString());
config.save(configFile); config.save(configFile);
config.load(configFile);
} catch (IOException | InvalidConfigurationException e) { } catch (IOException | InvalidConfigurationException e) {
e.printStackTrace(); 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.EnchantmentRarity;
import com.willfp.ecoenchants.enchantments.meta.EnchantmentTarget; import com.willfp.ecoenchants.enchantments.meta.EnchantmentTarget;
import com.willfp.ecoenchants.util.Logger; import com.willfp.ecoenchants.util.Logger;
import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey; import org.bukkit.NamespacedKey;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import java.io.IOException;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; 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("name", ConfigManager.getLang().getString("enchantments." + this.getName() + ".name"));
config.set("description", ConfigManager.getLang().getString("enchantments." + this.getName() + ".description")); 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();
}
} }
} }