diff --git a/src/main/java/org/bitbiome/commands/CollectCommand.java b/src/main/java/org/bitbiome/commands/CollectCommand.java index 127638e..ab29c5a 100644 --- a/src/main/java/org/bitbiome/commands/CollectCommand.java +++ b/src/main/java/org/bitbiome/commands/CollectCommand.java @@ -36,12 +36,7 @@ public class CollectCommand implements CommandAPI { 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(); - 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 eingesammelt."); + increaseAmountInPlayerConfig(inventory,k,jp,o); return; } } @@ -59,5 +54,13 @@ public class CollectCommand implements CommandAPI { } } System.out.println("Es gibt kein Item, dass du einsammeln kannst."); } + public void increaseAmountInPlayerConfig(JSONArray inventory, int k, JsonParser jp, JSONObject o){ + 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 eingesammelt."); + } }