Added lang autoupdate
This commit is contained in:
@@ -9,7 +9,6 @@ import java.util.Set;
|
||||
public class ConfigManager {
|
||||
public static final HashMap<String, Double> configVersions = new HashMap<String, Double>() {{
|
||||
put("config", 5.0);
|
||||
put("lang", 5.0);
|
||||
put("target", 1.0);
|
||||
put("rarity", 1.0);
|
||||
}};
|
||||
@@ -25,7 +24,7 @@ public class ConfigManager {
|
||||
* Called on /ecoreload
|
||||
*/
|
||||
public static void updateConfigs() {
|
||||
LANG.reload();
|
||||
LANG.update();
|
||||
CONFIG.reload();
|
||||
TARGET.reload();
|
||||
RARITY.reload();
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.willfp.ecoenchants.config;
|
||||
|
||||
import com.willfp.ecoenchants.EcoEnchantsPlugin;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public abstract class UpdatingLang {
|
||||
public YamlConfiguration config;
|
||||
private File configFile;
|
||||
|
||||
public UpdatingLang() {
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
if (!new File(EcoEnchantsPlugin.getInstance().getDataFolder(), "lang.yml").exists()) {
|
||||
createFile();
|
||||
}
|
||||
|
||||
this.configFile = new File(EcoEnchantsPlugin.getInstance().getDataFolder(), "lang.yml");
|
||||
this.config = YamlConfiguration.loadConfiguration(configFile);
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
private void createFile() {
|
||||
EcoEnchantsPlugin.getInstance().saveResource("lang.yml", false);
|
||||
}
|
||||
|
||||
public void update() {
|
||||
try {
|
||||
InputStream newIn = EcoEnchantsPlugin.getInstance().getResource("lang.yml");
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(newIn, StandardCharsets.UTF_8));
|
||||
YamlConfiguration newConfig = new YamlConfiguration();
|
||||
newConfig.load(reader);
|
||||
|
||||
newConfig.getKeys(true).forEach((s -> {
|
||||
if (!config.getKeys(true).contains(s)) {
|
||||
config.set(s, newConfig.get(s));
|
||||
}
|
||||
}));
|
||||
|
||||
config.save(configFile);
|
||||
config.load(configFile);
|
||||
} catch (IOException | InvalidConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.willfp.ecoenchants.config.configs;
|
||||
|
||||
import com.willfp.ecoenchants.config.UpdatingLang;
|
||||
import com.willfp.ecoenchants.config.YamlConfig;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
@@ -8,9 +9,9 @@ import java.util.List;
|
||||
/**
|
||||
* Wrapper for lang.yml
|
||||
*/
|
||||
public class Lang extends YamlConfig {
|
||||
public class Lang extends UpdatingLang {
|
||||
public Lang() {
|
||||
super("lang");
|
||||
super();
|
||||
}
|
||||
|
||||
public String getString(String path) {
|
||||
|
||||
@@ -29,7 +29,6 @@ public final class Succession extends EcoEnchant {
|
||||
|
||||
boolean fire = EnchantChecks.mainhand(shooter, Enchantment.ARROW_FIRE);
|
||||
|
||||
|
||||
for (int i = 1; i <= number; i++) {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(EcoEnchantsPlugin.getInstance(), () -> {
|
||||
Arrow arrow1 = shooter.launchProjectile(Arrow.class, event.getProjectile().getVelocity());
|
||||
|
||||
Reference in New Issue
Block a user