Added lang autoupdate

This commit is contained in:
BuildTools 2020-10-07 10:59:21 +01:00
parent d14e60a14f
commit 238ad2b949
7 changed files with 63 additions and 7 deletions

View File

@ -1,6 +1,7 @@
package com.willfp.ecoenchants.v1_16_R1;
import com.willfp.ecoenchants.API.CooldownWrapper;
import org.bukkit.craftbukkit.libs.org.apache.commons.io.FileUtils;
import org.bukkit.entity.Player;
public class Cooldown implements CooldownWrapper {

View File

@ -157,6 +157,12 @@
<version>3.0.3</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.8.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sk89q.worldguard</groupId>
<artifactId>worldguard-bukkit</artifactId>

View File

@ -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();

View File

@ -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();
}
}
}

View File

@ -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) {

View File

@ -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());

View File

@ -3,8 +3,6 @@
# by Auxilor
#
config-version: 5.0 # Don't edit this.
messages:
prefix: "&f[&aEcoEnchants&f] "
no-permission: "&cYou don't have permission to do this!"