diff --git a/src/main/java/org/bitbiome/commands/CommandListener.java b/src/main/java/org/bitbiome/commands/CommandListener.java index b1a5378..d59813c 100644 --- a/src/main/java/org/bitbiome/commands/CommandListener.java +++ b/src/main/java/org/bitbiome/commands/CommandListener.java @@ -17,6 +17,7 @@ public class CommandListener { commands.put("exit", new QuitCommand()); commands.put("quit", new QuitCommand()); commands.put("location", new LocationCommand()); + commands.put("travel", new TravelCommand()); } public HashMap returnCommands() { diff --git a/src/main/java/org/bitbiome/commands/TravelCommand.java b/src/main/java/org/bitbiome/commands/TravelCommand.java new file mode 100644 index 0000000..ca68bf5 --- /dev/null +++ b/src/main/java/org/bitbiome/commands/TravelCommand.java @@ -0,0 +1,33 @@ +package org.bitbiome.commands; + +import org.bitbiome.classes.Colors; +import org.bitbiome.classes.CreateLocations; +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 java.util.ArrayList; +import java.util.Scanner; + + +public class TravelCommand implements CommandAPI { + + @Override + 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")); + } + + 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); + } + } +}