From 70261df520a26e34010d398814e16c6e1154113c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=AD=B1=E5=82=91?= Date: Sat, 18 Feb 2023 15:47:51 +0800 Subject: [PATCH] Fix deprecated method `JsonUtils.loadToClass` --- .../github/jie65535/opencommand/OpenCommandPlugin.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/github/jie65535/opencommand/OpenCommandPlugin.java b/src/main/java/com/github/jie65535/opencommand/OpenCommandPlugin.java index c012c2c..1e2aadd 100644 --- a/src/main/java/com/github/jie65535/opencommand/OpenCommandPlugin.java +++ b/src/main/java/com/github/jie65535/opencommand/OpenCommandPlugin.java @@ -105,8 +105,8 @@ private void loadConfig() { getLogger().error("[OpenCommand] Unable to save config file."); } } else { - try { - config = JsonUtils.loadToClass(configFile.getAbsolutePath(), OpenCommandConfig.class); + try (var fileReader = new InputStreamReader(new FileInputStream(configFile))) { + config = JsonUtils.loadToClass(fileReader, OpenCommandConfig.class); } catch (Exception exception) { config = new OpenCommandConfig(); getLogger().error("[OpenCommand] There was an error while trying to load the configuration from config.json. Please make sure that there are no syntax errors. If you want to start with a default configuration, delete your existing config.json."); @@ -125,8 +125,8 @@ private void loadData() { data = new OpenCommandData(); saveData(); } else { - try { - data = JsonUtils.loadToClass(dataFile.getAbsolutePath(), OpenCommandData.class); + try (var fileReader = new InputStreamReader(new FileInputStream(dataFile))) { + data = JsonUtils.loadToClass(fileReader, OpenCommandData.class); } catch (Exception exception) { data = new OpenCommandData(); getLogger().error("[OpenCommand] There was an error while trying to load the data from data.json. Please make sure that there are no syntax errors. If you want to start with a default data, delete your existing data.json.");