From 66df32ba781f84630b70b4d9004c408d1d3417bf Mon Sep 17 00:00:00 2001 From: hackthetime Date: Thu, 26 Oct 2023 09:39:51 +0200 Subject: numpad no config fix. --- .../hype/bbsentials/fabric/numpad/NumPadCodes.java | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/fabric/src/main/java/de/hype/bbsentials/fabric/numpad/NumPadCodes.java b/fabric/src/main/java/de/hype/bbsentials/fabric/numpad/NumPadCodes.java index d3b3c1e..441c563 100644 --- a/fabric/src/main/java/de/hype/bbsentials/fabric/numpad/NumPadCodes.java +++ b/fabric/src/main/java/de/hype/bbsentials/fabric/numpad/NumPadCodes.java @@ -187,8 +187,7 @@ public class NumPadCodes { toSaveCodes.add(numCode); } } - try (Writer writer = new FileWriter(new File(EnvironmentCore.mcUtils.getConfigPath(), "BBsentials_Numpad_codes.json") - )) { + try (Writer writer = new FileWriter(new File(EnvironmentCore.mcUtils.getConfigPath(), "BBsentials_Numpad_codes.json"))) { gson.toJson(toSaveCodes, writer); } catch (IOException e) { e.printStackTrace(); @@ -197,14 +196,24 @@ public class NumPadCodes { public void loadNumCodesFromFile() { - try (Reader reader = new FileReader(new File(EnvironmentCore.mcUtils.getConfigPath(), "BBsentials_Numpad_codes.json"))) { + File file = new File(EnvironmentCore.mcUtils.getConfigPath(), "BBsentials_Numpad_codes.json"); + try (Reader reader = new FileReader(file)) { Type listType = new TypeToken>() { }.getType(); numCodes = gson.fromJson(reader, listType); } catch (IOException e) { - e.printStackTrace(); + if (!file.exists()) { + try { + file.createNewFile(); + loadNumCodesFromFile(); + } catch (IOException ex) { + System.out.println("Couldnt create new file"); + e.printStackTrace(); + } + } + else { + e.printStackTrace(); + } } } - - } -- cgit