From ec1ee44981a9d0b6205506ae0eafc7974c460796 Mon Sep 17 00:00:00 2001 From: Juliakn66 <117075450+Juliakn66@users.noreply.github.com> Date: Sat, 4 Feb 2023 10:42:20 +0100 Subject: [PATCH] edited method collectItem() of CollectCommand --- .../org/bitbiome/commands/CollectCommand.java | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/bitbiome/commands/CollectCommand.java b/src/main/java/org/bitbiome/commands/CollectCommand.java index e459c49..ea5e07a 100644 --- a/src/main/java/org/bitbiome/commands/CollectCommand.java +++ b/src/main/java/org/bitbiome/commands/CollectCommand.java @@ -16,7 +16,37 @@ public class CollectCommand implements CommandAPI { } public void collectItem(ArrayList location, String item, JsonParser jp, JSONObject o, JSONArray inventory, TravelEngine travelEngine) { - + 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 k = 0; k < inventory.length(); k++) { + if (inventory.getJSONObject(k).getString("name").equals(item)) { + JSONObject o2 = new JSONObject(); + int amountItemsInPlayerconfig = 0; + 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."); + return; + } + } + } + } + o1.put("name", location.get(i).getName()); + o1.put("doesDamage", location.get(i).doesDamage()); + o1.put("damage", location.get(i).getDamage()); + o1.put("amount", 1); + o1.put("durability", 1000); + o.getJSONArray("inventory").put(o1); + jp.writeObject("playerconfig.json", o); + travelEngine.getPlayer().getInventory().add(location.get(i)); + location.remove(i); + return; + } + } System.out.println("Es gibt kein Item, dass du einsammeln kannst."); } }