From 8bb9367d7baae04ed39585bb70f638b9bb9c9ea0 Mon Sep 17 00:00:00 2001 From: Juliakn66 <117075450+Juliakn66@users.noreply.github.com> Date: Fri, 3 Feb 2023 15:05:02 +0100 Subject: [PATCH] updated LookaroundCommand() get ArrayList of currentLocation of Player --- .../bitbiome/commands/LookaroundCommand.java | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/bitbiome/commands/LookaroundCommand.java b/src/main/java/org/bitbiome/commands/LookaroundCommand.java index 1407700..2f3b77f 100644 --- a/src/main/java/org/bitbiome/commands/LookaroundCommand.java +++ b/src/main/java/org/bitbiome/commands/LookaroundCommand.java @@ -1,12 +1,42 @@ package org.bitbiome.commands; +import org.bitbiome.classes.JsonParser; import org.bitbiome.classes.TravelEngine; +import org.bitbiome.entities.Item; +import org.bitbiome.entities.Location; +import org.bitbiome.entities.Mob; +import org.json.JSONArray; +import org.json.JSONObject; +import org.json.JSONTokener; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Random; import java.util.Scanner; public class LookaroundCommand implements CommandAPI{ @Override public void performCommand(Scanner scanner, boolean isRunning, String message, TravelEngine travelEngine) { - + StringBuilder s = new StringBuilder(); + Location location = travelEngine.getPlayer().getLocation(); + JsonParser jp = new JsonParser(); + JSONObject o = jp.getJSONObject("gameconfig.json"); + JSONArray locations = o.getJSONArray("locations"); + JSONObject locationObject = locations.getJSONObject(0); + + for (int i = 1; i < locations.length(); i++) { + if(locations.getJSONObject(i).getString("name").equals(location.getName())){ + locationObject = locations.getJSONObject(i); + } + } + JSONArray items = locationObject.getJSONArray("items"); + JSONArray mobs = locationObject.getJSONArray("mobs"); + + ArrayList foundItems = location.getItemList(); + ArrayList foundMobs = location.getMobList(); + s.append(foundItems).append(foundMobs); + System.out.println(s); + } + }