diff --git a/resources/languages/de.yml b/resources/languages/de.yml index 00dee9c..f2ea098 100644 --- a/resources/languages/de.yml +++ b/resources/languages/de.yml @@ -37,6 +37,7 @@ Error_Recipeload: '&cEs konnten nicht alle Rezepte wiederhergesellt werden: Sieh Error_ShowHelp: 'Benutze &6/brew help &fum die Hilfe anzuzeigen' Error_UnknownCommand: Unbekannter Befehl Error_ConfigUpdate: 'Unbekannte Brewery Config Version: v&v1, Config wurde nicht geupdated!' +Error_YmlRead: 'config.yml konnte nicht gelesen werden, ist die Datei im korrekten yml-Format (korrekte Leerzeichen usw.)?' # Permission Error_NoPermissions: '&cDu hast keine Rechte dies zu tun!' diff --git a/resources/languages/en.yml b/resources/languages/en.yml index ae8d8bb..6baef83 100644 --- a/resources/languages/en.yml +++ b/resources/languages/en.yml @@ -39,6 +39,7 @@ Error_PlayerCommand: '&cThis command can only be executed as a player!' Error_Recipeload: '&cNot all recipes could be restored: More information in the server log!' Error_ShowHelp: Use &6/brew help &fto display the help Error_UnknownCommand: Unknown Command +Error_YmlRead: 'Could not read file config.yml, please make sure the file is in valid yml format (correct spaces etc.)' # Etc Etc_Barrel: Barrel diff --git a/resources/languages/fr.yml b/resources/languages/fr.yml index ac42766..4a57aca 100644 --- a/resources/languages/fr.yml +++ b/resources/languages/fr.yml @@ -38,6 +38,7 @@ Error_PlayerCommand: '&cCette commande ne peut être executée que par un joueur Error_Recipeload: '&cToutes les recettes n´ont pu être restaurées: Plus d´informations dans les logs du serveur !' Error_ShowHelp: Utilisez &6/brew help &fpour regarder l´aide Error_UnknownCommand: Commande inconnue +Error_YmlRead: 'Could not read file config.yml, please make sure the file is in valid yml format (correct spaces etc.)' # Etc Etc_Barrel: Baril diff --git a/resources/languages/it.yml b/resources/languages/it.yml index 4a2a003..136de93 100755 --- a/resources/languages/it.yml +++ b/resources/languages/it.yml @@ -38,6 +38,7 @@ Error_PlayerCommand: '&cQuesto comando può essere eseguito solo da un giocatore Error_Recipeload: '&cNon è stato possibile recuperare tutte le ricette: ulteriori informazioni nel file log!' Error_ShowHelp: Usa &6/brew help &fper visualizzare l''aiuto Error_UnknownCommand: Comando sconosciuto +Error_YmlRead: 'Could not read file config.yml, please make sure the file is in valid yml format (correct spaces etc.)' # Varie Etc_Barrel: Barile diff --git a/resources/languages/tw.yml b/resources/languages/tw.yml index d6707d4..2ba1665 100644 --- a/resources/languages/tw.yml +++ b/resources/languages/tw.yml @@ -38,6 +38,7 @@ Error_PlayerCommand: '&c這個指令只能由玩家執行!' Error_Recipeload: '&c並非所有配方都可以有用:服務器日誌中的更多信息!' Error_ShowHelp: 使用 &6/brew help &f顯示幫助 Error_UnknownCommand: 未知的指令 +Error_YmlRead: 'Could not read file config.yml, please make sure the file is in valid yml format (correct spaces etc.)' # Etc Etc_Barrel: 釀造桶 diff --git a/resources/languages/zh.yml b/resources/languages/zh.yml index ea7780f..36f7891 100644 --- a/resources/languages/zh.yml +++ b/resources/languages/zh.yml @@ -38,6 +38,7 @@ Error_PlayerCommand: '&c该命令必须由玩家执行.' Error_Recipeload: '&c加载饮品配方时出现问题, 请查看控制台以获得详细信息!' Error_ShowHelp: 使用&6/brew help&f以查看帮助 Error_UnknownCommand: 未知命令. +Error_YmlRead: 'Could not read file config.yml, please make sure the file is in valid yml format (correct spaces etc.)' # Etc Etc_Barrel: 木桶 diff --git a/src/com/dre/brewery/P.java b/src/com/dre/brewery/P.java index fd177b4..54a68f6 100644 --- a/src/com/dre/brewery/P.java +++ b/src/com/dre/brewery/P.java @@ -16,6 +16,7 @@ import org.apache.commons.lang.math.NumberUtils; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; +import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.event.HandlerList; import org.bukkit.plugin.java.JavaPlugin; @@ -313,7 +314,8 @@ public class P extends JavaPlugin { // load the Config try { - if (!BConfig.readConfig()) { + FileConfiguration cfg = BConfig.loadConfigFile(); + if (cfg == null || !BConfig.readConfig(cfg)) { p = null; getServer().getPluginManager().disablePlugin(this); return; @@ -463,6 +465,12 @@ public class P extends JavaPlugin { if (sender != null && !sender.equals(getServer().getConsoleSender())) { BConfig.reloader = sender; } + FileConfiguration cfg = BConfig.loadConfigFile(); + if (cfg == null) { + // Could not read yml file, do not proceed + return; + } + // clear all existent config Data BRecipe.getConfigRecipes().clear(); BRecipe.numConfigRecipes = 0; @@ -486,7 +494,7 @@ public class P extends JavaPlugin { // load the Config try { - if (!BConfig.readConfig()) { + if (!BConfig.readConfig(cfg)) { p = null; getServer().getPluginManager().disablePlugin(this); return; @@ -510,6 +518,8 @@ public class P extends JavaPlugin { } if (!successful && sender != null) { msg(sender, p.languageReader.get("Error_Recipeload")); + } else { + p.msg(sender, p.languageReader.get("CMD_Reload")); } BConfig.reloader = null; } diff --git a/src/com/dre/brewery/filedata/BConfig.java b/src/com/dre/brewery/filedata/BConfig.java index 7ea44d9..970a890 100644 --- a/src/com/dre/brewery/filedata/BConfig.java +++ b/src/com/dre/brewery/filedata/BConfig.java @@ -119,13 +119,31 @@ public class BConfig { } } - public static boolean readConfig() { + public static FileConfiguration loadConfigFile() { File file = new File(P.p.getDataFolder(), "config.yml"); if (!checkConfigs()) { - return false; + return null; } - FileConfiguration config = YamlConfiguration.loadConfiguration(file); + try { + YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file); + if (cfg.contains("version") && cfg.contains("language")) { + return cfg; + } + } catch (Exception e) { + e.printStackTrace(); + } + + // Failed to load + if (p.languageReader != null) { + P.p.errorLog(p.languageReader.get("Error_YmlRead")); + } else { + P.p.errorLog("Could not read file config.yml, please make sure the file is in valid yml format (correct spaces etc.)"); + } + return null; + } + + public static boolean readConfig(FileConfiguration config) { // Set the Language p.language = config.getString("language", "en"); @@ -139,6 +157,7 @@ public class BConfig { String version = config.getString("version", null); if (version != null) { if (!version.equals(configVersion) || (oldMat && P.use1_13)) { + File file = new File(P.p.getDataFolder(), "config.yml"); copyDefaultConfigs(true); new ConfigUpdater(file).update(version, oldMat, p.language); P.p.log("Config Updated to version: " + configVersion); @@ -199,7 +218,7 @@ public class BConfig { openEverywhere = config.getBoolean("openLargeBarrelEverywhere", false); MCBarrel.maxBrews = config.getInt("maxBrewsInMCBarrels", 6); - Brew.loadSeed(config, file); + Brew.loadSeed(config, new File(P.p.getDataFolder(), "config.yml")); PluginItem.registerForConfig("brewery", BreweryPluginItem::new); PluginItem.registerForConfig("mmoitems", MMOItemsPluginItem::new); diff --git a/src/com/dre/brewery/filedata/LanguageReader.java b/src/com/dre/brewery/filedata/LanguageReader.java index ba9105b..c9a8811 100644 --- a/src/com/dre/brewery/filedata/LanguageReader.java +++ b/src/com/dre/brewery/filedata/LanguageReader.java @@ -104,6 +104,7 @@ public class LanguageReader { defaults.add(new Tuple<>("Error_NoBrewName", "&cNo Recipe with Name: '&v1&c' found!")); defaults.add(new Tuple<>("Error_Recipeload", "&cNot all recipes could be restored: More information in the server log!")); defaults.add(new Tuple<>("Error_ConfigUpdate", "Unknown Brewery config version: v&v1, config was not updated!")); + defaults.add(new Tuple<>("Error_YmlRead", "Could not read File config.yml, please make sure the file is in valid yml format (correct spaces etc.)")); /* Permissions */ defaults.add(new Tuple<>("Error_NoPermissions", "&cYou don't have permissions to do this!")); diff --git a/src/com/dre/brewery/listeners/CommandListener.java b/src/com/dre/brewery/listeners/CommandListener.java index 0a88b60..e757533 100644 --- a/src/com/dre/brewery/listeners/CommandListener.java +++ b/src/com/dre/brewery/listeners/CommandListener.java @@ -36,7 +36,6 @@ public class CommandListener implements CommandExecutor { if (sender.hasPermission("brewery.cmd.reload")) { p.reload(sender); - p.msg(sender, p.languageReader.get("CMD_Reload")); } else { p.msg(sender, p.languageReader.get("Error_NoPermissions")); }