Browse Source

using JsonPaser for writing in the file

remotes/origin/shop
Max Gerbeth 2 years ago
parent
commit
99fd247d40
  1. 1
      src/main/java/org/bitbiome/classes/InteractionLoop.java
  2. 6
      src/main/java/org/bitbiome/commands/CommandListener.java
  3. 3
      src/main/java/org/bitbiome/commands/ShopCommand.java
  4. 19
      src/main/java/org/bitbiome/shop/Shop.java

1
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;

6
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;

3
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<Item> currentItems = shop.loadCurrentShopItems();

19
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<Item> allItems;
public ArrayList<Item> 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();

Loading…
Cancel
Save