package net.t2code.t2callayduplicate.config; import net.t2code.t2callayduplicate.system.Main; import net.t2code.t2codelib.SPIGOT.api.messages.T2Creplace; import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend; import net.t2code.t2codelib.SPIGOT.api.yaml.T2Cconfig; import org.bukkit.Material; import org.bukkit.Particle; import org.bukkit.Sound; import org.bukkit.configuration.file.YamlConfiguration; import java.io.File; import java.io.IOException; public class ConfigFile { public static void create() { File config = new File(Main.getPath(), "config.yml"); YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(config); T2Cconfig.set("Plugin.Language", "ENGLISH", yamlConfiguration); T2Cconfig.set("Plugin.updateCheck.onJoin",true,yamlConfiguration); T2Cconfig.set("Plugin.updateCheck.seePreReleaseUpdates",true,yamlConfiguration); T2Cconfig.set("Plugin.updateCheck.timeInterval",60,yamlConfiguration); T2Cconfig.set("Duplicate.SneakRequired", true, yamlConfiguration); T2Cconfig.set("Duplicate.Item.Enable", true, yamlConfiguration); T2Cconfig.set("Duplicate.Item.Material", Material.AMETHYST_SHARD.toString(), yamlConfiguration); T2Cconfig.set("Duplicate.Item.Amount", 1, yamlConfiguration); T2Cconfig.set("Duplicate.Particle.Enable", true, yamlConfiguration); T2Cconfig.set("Duplicate.Particle.Particle", "HEART", yamlConfiguration); T2Cconfig.set("Duplicate.Sound.Enable", true, yamlConfiguration); T2Cconfig.set("Duplicate.Sound.Sound", "ENTITY_ALLAY_AMBIENT_WITHOUT_ITEM", yamlConfiguration); T2Cconfig.set("Duplicate.Sound.Volume", 3, yamlConfiguration); T2Cconfig.set("Duplicate.Delay.Enable", true, yamlConfiguration); T2Cconfig.set("Duplicate.Delay.ProAllay", false, yamlConfiguration); T2Cconfig.set("Duplicate.Delay.ResetOnReload", true, yamlConfiguration); T2Cconfig.set("Duplicate.Delay.Seconds", 300, yamlConfiguration); T2Cconfig.set("Duplicate.Cost.Enable", true, yamlConfiguration); T2Cconfig.set("Duplicate.Cost.Price", 10.00, yamlConfiguration); T2Cconfig.set("Messages.MiniMessagesEditorLink", "https://webui.adventure.kyori.net", yamlConfiguration); T2Cconfig.set("Messages.Prefix", "[T2CAllayDuplicate]", yamlConfiguration); T2Cconfig.set("Messages.ENGLISH.Plugin.NoPerm", "[prefix] You are not authorized to do that!", yamlConfiguration); T2Cconfig.set("Messages.ENGLISH.Duplicate", "[prefix] Du You have duplicated an allay.", yamlConfiguration); T2Cconfig.set("Messages.ENGLISH.Error.Delay", "[prefix] You have to wait [min] minutes, [sec] seconds before you can duplicate the next allay.", yamlConfiguration); T2Cconfig.set("Messages.ENGLISH.Error.IncorrectItem", "[prefix] You need [amount] [item] to be able to duplicate an allay.", yamlConfiguration); T2Cconfig.set("Messages.ENGLISH.Error.NoMoney", "[prefix] You need [price] $ to be able to duplicate an allay.", yamlConfiguration); T2Cconfig.set("Messages.ENGLISH.Error.Reset", "[prefix] Player [player] not online!", yamlConfiguration); T2Cconfig.set("Messages.ENGLISH.Error.CanNotBuild", "[prefix] You are not authorized to do so at this area.", yamlConfiguration); T2Cconfig.set("Messages.ENGLISH.Reset", "[prefix] The delay of [player] has been reset.", yamlConfiguration); T2Cconfig.set("Messages.ENGLISH.ResetAll", "[prefix] The delay of all players has been reset.", yamlConfiguration); T2Cconfig.set("Messages.GERMAN.Plugin.NoPerm", "[prefix] Dazu bist du nicht berechtigt!", yamlConfiguration); T2Cconfig.set("Messages.GERMAN.Duplicate", "[prefix] Du hast ein Allay verdoppelt.", yamlConfiguration); T2Cconfig.set("Messages.GERMAN.Error.Delay", "[prefix] Du musst noch [min] Minuten, [sec] Sekunden warten, befor du das nächste Allay duplizieren kannst.", yamlConfiguration); T2Cconfig.set("Messages.GERMAN.Error.IncorrectItem", "[prefix] Du benötigst [amount] [item] um einen Allay duplizieren kannst.", yamlConfiguration); T2Cconfig.set("Messages.GERMAN.Error.NoMoney", "[prefix] Du benötigst [price] $ um einen Allay duplizieren kannst.", yamlConfiguration); T2Cconfig.set("Messages.GERMAN.Error.Reset", "[prefix] Spieler [player] nicht Online!", yamlConfiguration); T2Cconfig.set("Messages.GERMAN.Error.CanNotBuild", "[prefix] Du bist an diesem Bereich nicht dazu berechtigt.", yamlConfiguration); T2Cconfig.set("Messages.GERMAN.Reset", "[prefix] Das Delay von [player] wurde zurückgesetzt.", yamlConfiguration); T2Cconfig.set("Messages.GERMAN.ResetAll", "[prefix] Das Delay von allen Spielern wurde zurückgesetzt.", yamlConfiguration); try { yamlConfiguration.save(config); } catch (IOException e) { e.printStackTrace(); } } public static void select() { File config = new File(Main.getPath(), "config.yml"); YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(config); language = yamlConfiguration.getString("Plugin.Language"); updateCheckOnJoin = yamlConfiguration.getBoolean("Plugin.updateCheck.onJoin"); updateCheckSeePreReleaseUpdates = yamlConfiguration.getBoolean("Plugin.updateCheck.seePreReleaseUpdates"); updateCheckTimeInterval = yamlConfiguration.getInt("Plugin.updateCheck.timeInterval"); sneakRequired = yamlConfiguration.getBoolean("Duplicate.SneakRequired"); itemEnable = yamlConfiguration.getBoolean("Duplicate.Item.Enable"); itemMaterial = yamlConfiguration.getString("Duplicate.Item.Material"); itemAmount = yamlConfiguration.getInt("Duplicate.Item.Amount"); particleEnable = yamlConfiguration.getBoolean("Duplicate.Particle.Enable"); try { particleParticle = Particle.valueOf(yamlConfiguration.getString("Duplicate.Particle.Particle")); } catch (Exception ex) { T2Csend.error(Main.getPlugin(), ""); T2Csend.console(String.format("§4The particle %s does not exist, please check your config. The %s is used as particle.", yamlConfiguration.getString("Duplicate.Particle.Particle"), "HEART")); T2Csend.error(Main.getPlugin(), ""); particleParticle = Particle.HEART; } soundEnable = yamlConfiguration.getBoolean("Duplicate.Sound.Enable"); try { soundSound = Sound.valueOf(yamlConfiguration.getString("Duplicate.Sound.Sound")); } catch (Exception ex) { T2Csend.error(Main.getPlugin(), ""); T2Csend.console(String.format("§4The sound %s does not exist, please check your config. The %s is used as sound.", yamlConfiguration.getString("Duplicate.Sound.Sound"), "ENTITY_ALLAY_AMBIENT_WITHOUT_ITEM")); T2Csend.error(Main.getPlugin(), ""); soundSound = Sound.ENTITY_ALLAY_AMBIENT_WITHOUT_ITEM; } soundVolume = yamlConfiguration.getInt("Duplicate.Sound.Volume"); delayEnable = yamlConfiguration.getBoolean("Duplicate.Delay.Enable"); delayProAllay = yamlConfiguration.getBoolean("Duplicate.Delay.ProAllay"); delayResetOnReload = yamlConfiguration.getBoolean("Duplicate.Delay.ResetOnReload"); delaySeconds = yamlConfiguration.getInt("Duplicate.Delay.Seconds"); costEnable = yamlConfiguration.getBoolean("Duplicate.Cost.Enable"); costPrice = yamlConfiguration.getDouble("Duplicate.Cost.Price"); prefix = yamlConfiguration.getString("Messages.Prefix"); noPerm = getMSG("Messages." + language + ".Plugin.NoPerm", yamlConfiguration); duplicate = getMSG("Messages." + language + ".Duplicate", yamlConfiguration); errorDelay = getMSG("Messages." + language + ".Error.Delay", yamlConfiguration); errorIncorrectItem = getMSG("Messages." + language + ".Error.IncorrectItem", yamlConfiguration); errorNoMoney = getMSG("Messages." + language + ".Error.NoMoney", yamlConfiguration); errorReset = getMSG("Messages." + language + ".Error.Reset", yamlConfiguration); errorCanNotBuild = getMSG("Messages." + language + ".Error.CanNotBuild", yamlConfiguration); reset = getMSG("Messages." + language + ".Reset", yamlConfiguration); ResetAll = getMSG("Messages." + language + ".ResetAll", yamlConfiguration); } private static String language; private static Boolean updateCheckOnJoin; private static Boolean updateCheckSeePreReleaseUpdates; private static Integer updateCheckTimeInterval; private static Boolean sneakRequired; private static Boolean itemEnable; private static String itemMaterial; private static Integer itemAmount; private static Boolean particleEnable; private static Particle particleParticle; private static Boolean soundEnable; private static Sound soundSound; private static Integer soundVolume; private static Boolean delayEnable; private static Boolean delayProAllay; private static Boolean delayResetOnReload; private static Integer delaySeconds; private static Boolean costEnable; private static Double costPrice; private static String prefix; private static String noPerm; private static String duplicate; private static String errorDelay; private static String errorIncorrectItem; private static String errorNoMoney; private static String errorReset; private static String errorCanNotBuild; private static String reset; private static String ResetAll; public static String getLanguage() { return language; } public static Boolean getUpdateCheckOnJoin() { return updateCheckOnJoin; } public static Boolean getUpdateCheckSeePreReleaseUpdates() { return updateCheckSeePreReleaseUpdates; } public static Integer getUpdateCheckTimeInterval() { return updateCheckTimeInterval; } public static Boolean getSneakRequired() { return sneakRequired; } public static Boolean getItemEnable() { return itemEnable; } public static String getItemMaterial() { return itemMaterial; } public static Integer getItemAmount() { return itemAmount; } public static Boolean getParticleEnable() { return particleEnable; } public static Particle getParticleParticle() { return particleParticle; } public static Boolean getSoundEnable() { return soundEnable; } public static Sound getSoundSound() { return soundSound; } public static Integer getSoundVolume() { return soundVolume; } public static Boolean getDelayEnable() { return delayEnable; } public static Boolean getDelayProAllay() { return delayProAllay; } public static Boolean getDelayResetOnReload() { return delayResetOnReload; } public static Integer getDelaySeconds() { return delaySeconds; } public static Boolean getCostEnable() { return costEnable; } public static Double getCostPrice() { return costPrice; } public static String getPrefix() { return prefix; } public static String getNoPerm() { return noPerm; } public static String getDuplicate() { return duplicate; } public static String getErrorDelay() { return errorDelay; } public static String getErrorIncorrectItem() { return errorIncorrectItem; } public static String getErrorNoMoney() { return errorNoMoney; } public static String getErrorReset() { return errorReset; } public static String getErrorCanNotBuild() { return errorCanNotBuild; } public static String getReset() { return reset; } public static String getResetAll() { return ResetAll; } private static String getMSG(String path, YamlConfiguration yamlConfiguration) { String out; if (yamlConfiguration.get(path) != null) { out = T2Creplace.replace(prefix, yamlConfiguration.getString(path)); } else { T2Csend.error(Main.getPlugin(), String.format("The message on the path [%s] was not found. Please check if the language [%s] exists.", path, language)); out = path; } return out; } }