Browse Source

refactoring: replace code for more readability

remotes/origin/Julia
Juliakn66 2 years ago
parent
commit
11e9541a1f
  1. 16
      src/main/java/org/bitbiome/commands/CollectCommand.java

16
src/main/java/org/bitbiome/commands/CollectCommand.java

@ -18,21 +18,22 @@ public class CollectCommand implements CommandAPI {
JSONArray inventory = o.getJSONArray("inventory");
ArrayList<Item> location = travelEngine.getPlayer().getLocation().getItemList();
ArrayList<Item> 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<Item> location, String item, JsonParser jp, JSONObject o, JSONArray inventory, TravelEngine travelEngine) {
public void collectItem(ArrayList<Item> location, String item, JsonParser jp, JSONObject o, JSONArray inventory, ArrayList<Item> 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.");
}

Loading…
Cancel
Save