package net.t2code.opsecurity.config.config; import net.t2code.opsecurity.config.opWhitelist.OPWhitelist; import net.t2code.opsecurity.config.permissionWhitelist.PermissionWhitelist; import net.t2code.opsecurity.objects.PlayerObject; import net.t2code.opsecurity.system.Main; import org.bukkit.configuration.file.YamlConfiguration; import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; public class Converter { public static void convert() { Path pathOld = Paths.get("plugins/OPSecurity/config.yml"); Path pathNew = Paths.get(Main.getPath() + "/config.yml"); if (Files.exists(pathNew) && !Files.isDirectory(pathNew)) { return; } if (Files.exists(pathOld) && !Files.isDirectory(pathOld)) { File configOld = new File("plugins/OPSecurity/config.yml"); YamlConfiguration yamlConfigurationOld = YamlConfiguration.loadConfiguration(configOld); File opConfig = new File(Main.getPath(), "opWhitelist.yml"); YamlConfiguration opYml = YamlConfiguration.loadConfiguration(opConfig); File permConfig = new File(Main.getPath(), "permissionWhitelist.yml"); YamlConfiguration permYml = YamlConfiguration.loadConfiguration(permConfig); Config.language.valueString = yamlConfigurationOld.getString("Plugin.language"); Config.onlyOPcanUseThePlugin.valueBoolean = yamlConfigurationOld.getBoolean("Plugin.OnlyOPcanUseThePlugin"); Config.checkOnJoin.valueBoolean = yamlConfigurationOld.getBoolean("Check.OnJoin"); Config.checkOnInteract.valueBoolean = yamlConfigurationOld.getBoolean("Check.OnInteract"); Config.checkOnCommand.valueBoolean = yamlConfigurationOld.getBoolean("Check.OnCommand"); Config.checkOnChat.valueBoolean = yamlConfigurationOld.getBoolean("Check.OnChat"); Config.checkTimerEnable.valueBoolean = yamlConfigurationOld.getBoolean("Check.Timer.Enable"); Config.checkTimerRefreshInSec.valueInt = yamlConfigurationOld.getInt("Check.Timer.RefreshTime_inSec"); Config.kickCommand.valueString = yamlConfigurationOld.getString("Kick.Command"); Config.notifyJoinWarning.valueBoolean = yamlConfigurationOld.getBoolean("Notify.JoinWarn.Enable"); Config.notifySoundEnable.valueBoolean = yamlConfigurationOld.getBoolean("Notify.Sound.Enable"); Config.notifySoundValue.valueString = yamlConfigurationOld.getString("Notify.Sound.Sound"); OPWhitelist.enable.valueBoolean = yamlConfigurationOld.getBoolean("OP_Whitelist.Enable"); OPWhitelist.playerMustBeOnlineToOp.valueBoolean = yamlConfigurationOld.getBoolean("OP_Whitelist.PlayerMustBeOnlineToOp"); OPWhitelist.noOpPlayerDeopEnable.valueBoolean = yamlConfigurationOld.getBoolean("OP_Whitelist.noOpPlayerDeop.Enable"); OPWhitelist.noOpPlayerDeopPlayerSendMessage.valueBoolean = yamlConfigurationOld.getBoolean("OP_Whitelist.noOpPlayerDeop.PlayerSendMessage"); OPWhitelist.noOpPlayerKickEnable.valueBoolean = yamlConfigurationOld.getBoolean("OP_Whitelist.noOpPlayerKick.Enable"); OPWhitelist.customCommandsEnable.valueBoolean = yamlConfigurationOld.getBoolean("OP_Whitelist.customCommands.Enable"); OPWhitelist.customCommandsCommands.valueStringList = yamlConfigurationOld.getStringList("OP_Whitelist.customCommands.Commands"); ArrayList opWhitelist = new ArrayList<>(); for (String key : yamlConfigurationOld.getConfigurationSection("OP_Whitelist.Whitelist").getKeys(false)) { PlayerObject player = new PlayerObject(key, yamlConfigurationOld.getString("OP_Whitelist.Whitelist." + key + ".UUID").replace("-", "")); opWhitelist.add(player); } for (PlayerObject playerObject : opWhitelist) { opYml.set("opWhitelist.whitelist.KEY.name".replace("KEY", playerObject.playerName), playerObject.playerName); opYml.set("opWhitelist.whitelist.KEY.uuid".replace("KEY", playerObject.playerName), playerObject.uuid); } PermissionWhitelist.enable.valueBoolean = yamlConfigurationOld.getBoolean("Permission_Whitelist.Enable"); PermissionWhitelist.permissions.valueStringList = yamlConfigurationOld.getStringList("Permission_Whitelist.Permissions"); PermissionWhitelist.playerWithPermissionKick.valueBoolean = yamlConfigurationOld.getBoolean("Permission_Whitelist.PlayerWhithPermission_kick"); PermissionWhitelist.customCommandsEnable.valueBoolean = yamlConfigurationOld.getBoolean("Permission_Whitelist.customCommands.Enable"); PermissionWhitelist.customCommandsCommands.valueStringList = yamlConfigurationOld.getStringList("Permission_Whitelist.customCommands.Commands"); ArrayList permWhitelist = new ArrayList<>(); for (String key : yamlConfigurationOld.getConfigurationSection("Permission_Whitelist.Whitelist").getKeys(false)) { PlayerObject player = new PlayerObject(key, yamlConfigurationOld.getString("Permission_Whitelist.Whitelist." + key + ".UUID").replace("-", "")); permWhitelist.add(player); } for (PlayerObject playerObject : permWhitelist) { permYml.set("permissionWhitelist.whitelist.KEY.name".replace("KEY", playerObject.playerName), playerObject.playerName); permYml.set("permissionWhitelist.whitelist.KEY.uuid".replace("KEY", playerObject.playerName), playerObject.uuid); } try { opYml.save(opConfig); } catch (IOException e) { e.printStackTrace(); } try { permYml.save(permConfig); } catch (IOException e) { e.printStackTrace(); } } } }