Skip to content

Commit 8225add

Browse files
committed
Use defaults when fails to load global config
1 parent b0d036f commit 8225add

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

src/main/java/me/rothes/protocolstringreplacer/ProtocolStringReplacer.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.apache.commons.lang.Validate;
1919
import org.bukkit.Bukkit;
2020
import org.bukkit.configuration.ConfigurationSection;
21+
import org.bukkit.configuration.InvalidConfigurationException;
2122
import org.bukkit.entity.Player;
2223
import org.bukkit.plugin.PluginLogger;
2324
import org.bukkit.plugin.PluginManager;
@@ -275,8 +276,14 @@ private void enableModify(ConfigManager.LifeCycle lifeCycle) {
275276
}
276277

277278
private void loadConfig() {
278-
configFile = new File(instance.getDataFolder() + "/Config.yml");
279-
config = CommentYamlConfiguration.loadConfiguration(configFile);
279+
try {
280+
configFile = new File(instance.getDataFolder() + "/Config.yml");
281+
config = new CommentYamlConfiguration();
282+
config.load(configFile);
283+
} catch (IOException | InvalidConfigurationException e) {
284+
error(PsrLocalization.getLocaledMessage("Console-Sender.Messages.Initialize.Config-Failed-To-Load"), e);
285+
config = PsrLocalization.getDefaultLocaledConfig();
286+
}
280287
}
281288

282289
private void checkConfig() {

src/main/resources/Languages/en-US/Locales/Locale.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ Console-Sender:
22
Messages:
33
Command-Not-Available: '&cOnly players can execute this command.'
44
Initialize:
5+
Config-Failed-To-Load: '&cFailed to load global config. Please fix the problem with the trace stack. Using defaults.'
56
Require-Spigot: '&cThis plugin must run on Spigot server or its fork.'
67
Recommend-Paper: 'You are not running Paper server or its fork. It''s recommended to switch to Paper for full supports.'
78
Out-Dated-Server: 'Your server version is too outdated, and may not enjoy some features normally...'

src/main/resources/Languages/zh-CN/Locales/Locale.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ Console-Sender:
22
Messages:
33
Command-Not-Available: '&c仅玩家可使用该指令.'
44
Initialize:
5+
Config-Failed-To-Load: '&c无法载入全局配置文件. 请通过下面的报错堆栈检查错误. 正在使用默认值.'
56
Require-Spigot: '&c本插件需要使用 Spigot 或其衍生服务端.'
67
Recommend-Paper: '您未使用 Paper 或其衍生服务端核心. 建议使用 Paper 以获得完整功能.'
78
Out-Dated-Server: '您使用的服务端过旧, 可能无法正常享受一些功能..'

0 commit comments

Comments
 (0)