diff --git a/src/main/java/org/bitbiome/shop/Shop.java b/src/main/java/org/bitbiome/shop/Shop.java index 68aaef3..3ca1b22 100644 --- a/src/main/java/org/bitbiome/shop/Shop.java +++ b/src/main/java/org/bitbiome/shop/Shop.java @@ -172,32 +172,33 @@ public class Shop { private ArrayList loadPartofItems(ArrayList alleItems, int itemCount) { ArrayList arrayList = new ArrayList(); try{ - File fileGameConfig = new File("src/main/resources/gameconfig.json"); - String content2 = new String(Files.readAllBytes(Paths.get(fileGameConfig.toURI())), "UTF-8"); - JSONObject gameConfig = new JSONObject(content2); - - JSONArray jsonArray = gameConfig.getJSONArray("shopitems"); - HashSet hashSet = new HashSet<>(); - JSONArray shopitems = new JSONArray(); - Random random = new Random(); - while (hashSet.size() < itemCount){ - int rand = random.nextInt(alleItems.size()); - if(!hashSet.contains(rand)){ - hashSet.add(rand); - arrayList.add(alleItems.get(rand)); - JSONObject jsonObject = new JSONObject(); - jsonObject.put("name", alleItems.get(rand).name); - jsonObject.put("amount", alleItems.get(rand).amount); - jsonObject.put("gold", alleItems.get(rand).gold); - shopitems.put(jsonObject); + File fileGameConfig = new File("src/main/resources/gameconfig.json"); + String content2 = new String(Files.readAllBytes(Paths.get(fileGameConfig.toURI())), "UTF-8"); + JSONObject gameConfig = new JSONObject(content2); + + JSONArray jsonArray = gameConfig.getJSONArray("shopitems"); + HashSet hashSet = new HashSet<>(); + JSONArray shopitems = new JSONArray(); + Random random = new Random(); + while (hashSet.size() < itemCount){ + int rand = random.nextInt(alleItems.size()); + if(!hashSet.contains(rand)){ + hashSet.add(rand); + arrayList.add(alleItems.get(rand)); + JSONObject jsonObject = new JSONObject(); + jsonObject.put("name", alleItems.get(rand).name); + jsonObject.put("amount", alleItems.get(rand).amount); + jsonObject.put("gold", alleItems.get(rand).gold); + shopitems.put(jsonObject); + } } - } - //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(); + //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(); + }catch (Exception e){ e.printStackTrace(); }