From c204733e70040700ee29fae63ff9a3f0e4bef08e Mon Sep 17 00:00:00 2001 From: Juliakn66 <117075450+Juliakn66@users.noreply.github.com> Date: Fri, 27 Jan 2023 13:18:51 +0100 Subject: [PATCH] edited player constructor added to arrayList inventory the items of file playerconfig --- src/main/java/org/bitbiome/entities/Player.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main/java/org/bitbiome/entities/Player.java b/src/main/java/org/bitbiome/entities/Player.java index 6fe3152..7fc9623 100644 --- a/src/main/java/org/bitbiome/entities/Player.java +++ b/src/main/java/org/bitbiome/entities/Player.java @@ -2,6 +2,9 @@ package org.bitbiome.entities; import org.bitbiome.classes.CreateLocations; import org.bitbiome.classes.JsonParser; +import org.json.JSONArray; +import org.json.JSONObject; + import java.util.ArrayList; @@ -20,6 +23,14 @@ public class Player { hp = 100.0F; location = new Location(jp.getJSONObject("playerconfig.json").getString("currentLocation"), new ArrayList<>(), new ArrayList<>()); inventory = new ArrayList<>(); + JSONArray items = jp.getJSONObject("playerconfig.json").getJSONArray("inventory"); + for (int i = 0; i < items.length(); i++) { + JSONObject o = items.getJSONObject(i); + inventory.add(new Item(o.getString("name"), o.getBoolean("doesDamage"), o.getFloat("damage"), o.getInt("amount"))); + } + + + } public String getName() {