Add config updater

feat/data-edit-commands
William 3 years ago
parent d4dbb5fe7d
commit a5127e67a3

@ -56,7 +56,7 @@ public class BukkitRedisListener extends RedisListener {
switch (message.getMessageType()) {
case REQUEST_DATA_ON_JOIN -> {
UUID playerUUID = UUID.fromString(message.getMessageDataElements()[1]);
switch (me.william278.husksync.redis.RedisMessage.RequestOnJoinUpdateType.valueOf(message.getMessageDataElements()[0])) {
switch (RedisMessage.RequestOnJoinUpdateType.valueOf(message.getMessageDataElements()[0])) {
case ADD_REQUESTER -> HuskSyncBukkit.bukkitCache.setRequestOnJoin(playerUUID);
case REMOVE_REQUESTER -> HuskSyncBukkit.bukkitCache.removeRequestOnJoin(playerUUID);
}

@ -1,14 +1,40 @@
package me.william278.husksync.bungeecord.config;
import me.william278.husksync.util.MessageManager;
import me.william278.husksync.HuskSyncBungeeCord;
import me.william278.husksync.Settings;
import me.william278.husksync.util.MessageManager;
import net.md_5.bungee.config.Configuration;
import java.util.HashMap;
public class ConfigLoader {
public static void loadSettings(Configuration config) throws IllegalArgumentException {
private static final HuskSyncBungeeCord plugin = HuskSyncBungeeCord.getInstance();
private static Configuration copyDefaults(Configuration config) {
// Get the config version and update if needed
String configVersion = config.getString("config_file_version", "1.0");
if (configVersion.contains("-dev")) {
configVersion = configVersion.replaceAll("-dev", "");
}
if (!configVersion.equals(plugin.getDescription().getVersion())) {
if (configVersion.equalsIgnoreCase("1.0")) {
config.set("check_for_updates", true);
}
if (configVersion.equalsIgnoreCase("1.0") || configVersion.equalsIgnoreCase("1.0.1") || configVersion.equalsIgnoreCase("1.0.2") || configVersion.equalsIgnoreCase("1.0.3")) {
config.set("clusters.main.player_table", "husksync_players");
config.set("clusters.main.data_table", "husksync_data");
}
config.set("config_file_version", plugin.getDescription().getVersion());
}
// Save the config back
ConfigManager.saveConfig(config);
return config;
}
public static void loadSettings(Configuration loadedConfig) throws IllegalArgumentException {
Configuration config = copyDefaults(loadedConfig);
Settings.language = config.getString("language", "en-gb");
Settings.serverType = Settings.ServerType.BUNGEECORD;

@ -32,6 +32,14 @@ public class ConfigManager {
}
}
public static void saveConfig(Configuration config) {
try {
ConfigurationProvider.getProvider(YamlConfiguration.class).save(config, new File(plugin.getDataFolder(), "config.yml"));
} catch (IOException e) {
plugin.getLogger().log(Level.CONFIG, "An exception occurred loading the configuration file", e);
}
}
public static void loadMessages() {
try {
if (!plugin.getDataFolder().exists()) {

@ -22,6 +22,5 @@ clusters:
main:
player_table: 'husksync_players'
data_table: 'husksync_data'
check_for_updates: true
config_file_version: 1.1
Loading…
Cancel
Save