diff --git a/src/main/java/org/bitbiome/classes/TravelEngine.java b/src/main/java/org/bitbiome/classes/TravelEngine.java index a8d3213..2bc81cb 100644 --- a/src/main/java/org/bitbiome/classes/TravelEngine.java +++ b/src/main/java/org/bitbiome/classes/TravelEngine.java @@ -44,6 +44,15 @@ public class TravelEngine { return found; } + public boolean locationExistsWald(String name) { + boolean found = false; + for (int i = 0; i < locations.length(); i++) + if (locations.getJSONObject(1).getString("name").equals(name) | locations.getJSONObject(4).getString("name").equals(name) | locations.getJSONObject(3).getString("name").equals(name)) { + found = true; + } + return found; + } + public Location getLocationByName(String name) { JsonParser jp = new JsonParser(); JSONObject gameconfig = jp.getJSONObject("gameconfig.json"); diff --git a/src/main/java/org/bitbiome/commands/TravelCommand.java b/src/main/java/org/bitbiome/commands/TravelCommand.java index da5cbe7..eeb452a 100644 --- a/src/main/java/org/bitbiome/commands/TravelCommand.java +++ b/src/main/java/org/bitbiome/commands/TravelCommand.java @@ -18,16 +18,28 @@ public class TravelCommand implements CommandAPI { public void performCommand(Scanner scanner, boolean isRunning, String message, TravelEngine travelEngine) { System.out.println(Colors.ANSI_BLUE + "Du hast dein Travel-Pad gezückt. Wohin möchtest du reisen?" + Colors.ANSI_RESET); JSONArray locations = travelEngine.getLocationList(); - for (int i = 0; i < locations.length(); i++) { - System.out.println("- " + locations.getJSONObject(i).getString("name")); - } + if (travelEngine.getPlayer().getLocation().getName().equalsIgnoreCase("Wald")) { + System.out.println("- " + locations.getJSONObject(1).getString("name") + "\n" + "- " + locations.getJSONObject(4).getString("name") + "\n" + "- " + locations.getJSONObject(3).getString("name")); + + String locationName = scanner.nextLine(); + if (travelEngine.locationExistsWald(locationName)) { + travelEngine.travelTo(new Location(locationName, new ArrayList(), new ArrayList())); + System.out.println(Colors.ANSI_BLUE + "Du bist nun hierhin gereist: " + locationName + "\n" + Colors.ANSI_RESET); + } else { + System.out.println(Colors.ANSI_BLUE + "Du hast dein Travel-Pad weggesteckt." + Colors.ANSI_RESET); + } - String locationName = scanner.nextLine(); - if (travelEngine.locationExists(locationName)) { - travelEngine.travelTo(new Location(locationName, new ArrayList(), new ArrayList())); - System.out.println(Colors.ANSI_BLUE + "Du bist nun hierhin gereist: " + locationName + "\n" + Colors.ANSI_RESET); } else { - System.out.println(Colors.ANSI_BLUE + "Du hast dein Travel-Pad weggesteckt." + Colors.ANSI_RESET); + for (int i = 0; i < locations.length(); i++) { + System.out.println("- " + locations.getJSONObject(i).getString("name")); + } + String locationName = scanner.nextLine(); + if (travelEngine.locationExists(locationName)) { + travelEngine.travelTo(new Location(locationName, new ArrayList(), new ArrayList())); + System.out.println(Colors.ANSI_BLUE + "Du bist nun hierhin gereist: " + locationName + "\n" + Colors.ANSI_RESET); + } else { + System.out.println(Colors.ANSI_BLUE + "Du hast dein Travel-Pad weggesteckt." + Colors.ANSI_RESET); + } } } }