diff --git a/src/main/java/org/bitbiome/classes/InteractionLoop.java b/src/main/java/org/bitbiome/classes/InteractionLoop.java index 2523644..1d73075 100644 --- a/src/main/java/org/bitbiome/classes/InteractionLoop.java +++ b/src/main/java/org/bitbiome/classes/InteractionLoop.java @@ -1,6 +1,7 @@ package org.bitbiome.classes; import org.bitbiome.Boot; +import org.bitbiome.classes.*; import org.json.JSONObject; import java.util.Scanner; diff --git a/src/main/java/org/bitbiome/commands/CommandListener.java b/src/main/java/org/bitbiome/commands/CommandListener.java index 8677e64..14020fe 100644 --- a/src/main/java/org/bitbiome/commands/CommandListener.java +++ b/src/main/java/org/bitbiome/commands/CommandListener.java @@ -1,5 +1,7 @@ package org.bitbiome.commands; +import org.bitbiome.classes.TravelEngine; + import java.util.HashMap; import java.util.Scanner; @@ -24,11 +26,11 @@ public class CommandListener { } - public boolean perform(String command, Scanner scanner, boolean isRunning, String message) { + public boolean perform(String command, Scanner scanner, boolean isRunning, String message, TravelEngine travelEngine) { CommandAPI cmd; if ((cmd = commands.get(command)) != null) { - cmd.performCommand(scanner, isRunning, message); + cmd.performCommand(scanner, isRunning, message, travelEngine); return true; } return false; diff --git a/src/main/java/org/bitbiome/commands/ShopCommand.java b/src/main/java/org/bitbiome/commands/ShopCommand.java index bb51f52..25fbf4d 100644 --- a/src/main/java/org/bitbiome/commands/ShopCommand.java +++ b/src/main/java/org/bitbiome/commands/ShopCommand.java @@ -1,5 +1,6 @@ package org.bitbiome.commands; +import org.bitbiome.classes.TravelEngine; import org.bitbiome.shop.Item; import org.bitbiome.shop.Shop; @@ -14,7 +15,7 @@ public class ShopCommand implements CommandAPI{ } @Override - public void performCommand(Scanner scanner, boolean isRunning, String message) { + public void performCommand(Scanner scanner, boolean isRunning, String message, TravelEngine travelEngine) { System.out.println("Willkommen im Shop!"); ArrayList currentItems = shop.loadCurrentShopItems(); diff --git a/src/main/java/org/bitbiome/shop/Shop.java b/src/main/java/org/bitbiome/shop/Shop.java index 3ca1b22..9fa4d3d 100644 --- a/src/main/java/org/bitbiome/shop/Shop.java +++ b/src/main/java/org/bitbiome/shop/Shop.java @@ -1,5 +1,6 @@ package org.bitbiome.shop; +import org.bitbiome.classes.JsonParser; import org.json.JSONArray; import org.json.JSONObject; @@ -14,6 +15,7 @@ import java.util.Random; public class Shop { public ArrayList allItems; public ArrayList currentShopItems; + public JsonParser jsonParser = new JsonParser(); public Shop() { try { @@ -79,9 +81,7 @@ public class Shop { tempJSON.put("amount", intNewAmount); jsonArray2.put(tempJSON); gameConfig.put("shopitems", jsonArray2); - FileWriter fileWriter = new FileWriter("src/main/resources/gameconfig.json"); - fileWriter.write(gameConfig.toString()); - fileWriter.close(); + jsonParser.writeObject("gameconfig.json", gameConfig); currentShopItems = loadCurrentShopItems(); break; } @@ -98,9 +98,7 @@ public class Shop { tempJSON.put("amount", newAmount); jsonArray.put(tempJSON); playerConfig.put("inventory", jsonArray); - FileWriter fileWriter = new FileWriter("src/main/resources/playerconfig.json"); - fileWriter.write(playerConfig.toString()); - fileWriter.close(); + jsonParser.writeObject("playerconfig.json", playerConfig); return true; } } @@ -121,9 +119,7 @@ public class Shop { jsonArray.put(inventory); playerConfig.put("inventory", jsonArray); - FileWriter fileWriter = new FileWriter("src/main/resources/playerconfig.json"); - fileWriter.write(playerConfig.toString()); - fileWriter.close(); + jsonParser.writeObject("playerconfig.json", playerConfig); }catch (Exception e){ e.printStackTrace(); @@ -195,9 +191,8 @@ public class Shop { //write in gameconfig.json gameConfig.remove("shopitems"); gameConfig.put("shopitems", shopitems); - FileWriter fileWriter = new FileWriter("src/main/resources/gameconfig.json"); - fileWriter.write(gameConfig.toString()); - fileWriter.close(); + jsonParser.writeObject("gameconfig.json", gameConfig); + }catch (Exception e){ e.printStackTrace();