From 11e9541a1f8c13d376f42e5c291777edfc9bec68 Mon Sep 17 00:00:00 2001 From: Juliakn66 <117075450+Juliakn66@users.noreply.github.com> Date: Sat, 4 Feb 2023 10:58:11 +0100 Subject: [PATCH] refactoring: replace code for more readability --- .../org/bitbiome/commands/CollectCommand.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/bitbiome/commands/CollectCommand.java b/src/main/java/org/bitbiome/commands/CollectCommand.java index 19e76bc..127638e 100644 --- a/src/main/java/org/bitbiome/commands/CollectCommand.java +++ b/src/main/java/org/bitbiome/commands/CollectCommand.java @@ -18,21 +18,22 @@ public class CollectCommand implements CommandAPI { JSONArray inventory = o.getJSONArray("inventory"); ArrayList location = travelEngine.getPlayer().getLocation().getItemList(); + ArrayList getInventory = travelEngine.getPlayer().getInventory(); System.out.println("Was willst du einsammeln?"); String item = new String(); item = scanner.nextLine(); - collectItem(location, item, jp, o, inventory,travelEngine); + collectItem(location, item, jp, o, inventory,getInventory); } - public void collectItem(ArrayList location, String item, JsonParser jp, JSONObject o, JSONArray inventory, TravelEngine travelEngine) { + public void collectItem(ArrayList location, String item, JsonParser jp, JSONObject o, JSONArray inventory, ArrayList getInventory) { for (int i = 0; i < location.size(); i++) { if (item.equals(location.get(i).getName())) { JSONObject o1 = new JSONObject(); - for (int j = 0; j < travelEngine.getPlayer().getInventory().size(); j++) { - if (travelEngine.getPlayer().getInventory().get(j).getName().equals(item)) { - travelEngine.getPlayer().getInventory().get(j).setAmount(travelEngine.getPlayer().getInventory().get(j).getAmount() + 1); + for (int j = 0; j < getInventory.size(); j++) { + if (getInventory.get(j).getName().equals(item)) { + getInventory.get(j).setAmount(getInventory.get(j).getAmount() + 1); for (int k = 0; k < inventory.length(); k++) { if (inventory.getJSONObject(k).getString("name").equals(item)) { JSONObject o2 = new JSONObject(); @@ -40,7 +41,7 @@ public class CollectCommand implements CommandAPI { amountItemsInPlayerconfig = inventory.getJSONObject(k).getInt("amount"); inventory.getJSONObject(k).put("amount", amountItemsInPlayerconfig + 1); jp.writeObject("playerconfig.json", o); - System.out.println("Du hast das Item eingsammelt."); + System.out.println("Du hast das Item eingesammelt."); return; } } @@ -53,9 +54,8 @@ public class CollectCommand implements CommandAPI { o1.put("durability", 1000); o.getJSONArray("inventory").put(o1); jp.writeObject("playerconfig.json", o); - travelEngine.getPlayer().getInventory().add(location.get(i)); + getInventory.add(location.get(i)); location.remove(i); - return; } } System.out.println("Es gibt kein Item, dass du einsammeln kannst."); }