|
@ -18,21 +18,22 @@ public class CollectCommand implements CommandAPI { |
|
|
JSONArray inventory = o.getJSONArray("inventory"); |
|
|
JSONArray inventory = o.getJSONArray("inventory"); |
|
|
|
|
|
|
|
|
ArrayList<Item> location = travelEngine.getPlayer().getLocation().getItemList(); |
|
|
ArrayList<Item> location = travelEngine.getPlayer().getLocation().getItemList(); |
|
|
|
|
|
ArrayList<Item> getInventory = travelEngine.getPlayer().getInventory(); |
|
|
|
|
|
|
|
|
System.out.println("Was willst du einsammeln?"); |
|
|
System.out.println("Was willst du einsammeln?"); |
|
|
String item = new String(); |
|
|
String item = new String(); |
|
|
item = scanner.nextLine(); |
|
|
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++) { |
|
|
for (int i = 0; i < location.size(); i++) { |
|
|
if (item.equals(location.get(i).getName())) { |
|
|
if (item.equals(location.get(i).getName())) { |
|
|
JSONObject o1 = new JSONObject(); |
|
|
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++) { |
|
|
for (int k = 0; k < inventory.length(); k++) { |
|
|
if (inventory.getJSONObject(k).getString("name").equals(item)) { |
|
|
if (inventory.getJSONObject(k).getString("name").equals(item)) { |
|
|
JSONObject o2 = new JSONObject(); |
|
|
JSONObject o2 = new JSONObject(); |
|
@ -40,7 +41,7 @@ public class CollectCommand implements CommandAPI { |
|
|
amountItemsInPlayerconfig = inventory.getJSONObject(k).getInt("amount"); |
|
|
amountItemsInPlayerconfig = inventory.getJSONObject(k).getInt("amount"); |
|
|
inventory.getJSONObject(k).put("amount", amountItemsInPlayerconfig + 1); |
|
|
inventory.getJSONObject(k).put("amount", amountItemsInPlayerconfig + 1); |
|
|
jp.writeObject("playerconfig.json", o); |
|
|
jp.writeObject("playerconfig.json", o); |
|
|
System.out.println("Du hast das Item eingsammelt."); |
|
|
|
|
|
|
|
|
System.out.println("Du hast das Item eingesammelt."); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@ -53,9 +54,8 @@ public class CollectCommand implements CommandAPI { |
|
|
o1.put("durability", 1000); |
|
|
o1.put("durability", 1000); |
|
|
o.getJSONArray("inventory").put(o1); |
|
|
o.getJSONArray("inventory").put(o1); |
|
|
jp.writeObject("playerconfig.json", o); |
|
|
jp.writeObject("playerconfig.json", o); |
|
|
travelEngine.getPlayer().getInventory().add(location.get(i)); |
|
|
|
|
|
|
|
|
getInventory.add(location.get(i)); |
|
|
location.remove(i); |
|
|
location.remove(i); |
|
|
return; |
|
|
|
|
|
} |
|
|
} |
|
|
} System.out.println("Es gibt kein Item, dass du einsammeln kannst."); |
|
|
} System.out.println("Es gibt kein Item, dass du einsammeln kannst."); |
|
|
} |
|
|
} |
|
|