From 346155ab001ae52a3b68d6d0e6d0bb384e7dc8a9 Mon Sep 17 00:00:00 2001 From: Juliakn66 <117075450+Juliakn66@users.noreply.github.com> Date: Sat, 4 Feb 2023 11:14:13 +0100 Subject: [PATCH] refactoring: added new method writeNewItem() to collectCommand.java --- .../org/bitbiome/commands/CollectCommand.java | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/bitbiome/commands/CollectCommand.java b/src/main/java/org/bitbiome/commands/CollectCommand.java index ab29c5a..e235110 100644 --- a/src/main/java/org/bitbiome/commands/CollectCommand.java +++ b/src/main/java/org/bitbiome/commands/CollectCommand.java @@ -42,18 +42,21 @@ public class CollectCommand implements CommandAPI { } } } - 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); - getInventory.add(location.get(i)); - location.remove(i); + writeNewItem(location, getInventory, o1, inventory, i, jp, o); } } System.out.println("Es gibt kein Item, dass du einsammeln kannst."); } + public void writeNewItem(ArrayList location, ArrayList getInventory, JSONObject o1, JSONArray inventory, int i, JsonParser jp, JSONObject o){ + 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); + getInventory.add(location.get(i)); + location.remove(i); + } public void increaseAmountInPlayerConfig(JSONArray inventory, int k, JsonParser jp, JSONObject o){ JSONObject o2 = new JSONObject(); int amountItemsInPlayerconfig = 0;