From b99ac6da82ebfd40de30c571fea050dc6043cbd0 Mon Sep 17 00:00:00 2001 From: Max Gerbeth Date: Fri, 20 Jan 2023 00:16:18 +0100 Subject: [PATCH] indend code in Shop.java --- src/main/java/org/bitbiome/shop/Shop.java | 51 ++++++++++++----------- 1 file changed, 26 insertions(+), 25 deletions(-) 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(); }