From 8fe445b5f8f28da5a5c45959dd17209a870b0713 Mon Sep 17 00:00:00 2001 From: Juliakn66 <117075450+Juliakn66@users.noreply.github.com> Date: Sat, 4 Feb 2023 11:01:56 +0100 Subject: [PATCH] refactoring: created method increaseAmountInPlayerConfig() in CollectCommand.java --- .../org/bitbiome/commands/CollectCommand.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) 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."); + } }