From 4c5a5e73086a28f3fbb4119cef4271ae702838f3 Mon Sep 17 00:00:00 2001
From: Chris Kearney <chris@kearneymail.com>
Date: Sun, 14 Aug 2016 12:08:57 -0700
Subject: [PATCH] leave command

---
 .../comandante/creeper/ConfigureCommands.java |  1 +
 .../creeper/command/LeaveCommand.java         | 42 +++++++++++++++++++
 .../creeper/command/MovementCommand.java      |  2 +-
 3 files changed, 44 insertions(+), 1 deletion(-)
 create mode 100644 src/main/java/com/comandante/creeper/command/LeaveCommand.java

diff --git a/src/main/java/com/comandante/creeper/ConfigureCommands.java b/src/main/java/com/comandante/creeper/ConfigureCommands.java
index f51e2801..d7d886d7 100755
--- a/src/main/java/com/comandante/creeper/ConfigureCommands.java
+++ b/src/main/java/com/comandante/creeper/ConfigureCommands.java
@@ -94,5 +94,6 @@ public class ConfigureCommands {
         creeperCommandRegistry.addCommand(new CompareCommand(gameManager));
         creeperCommandRegistry.addCommand(new CardsCommand(gameManager));
         creeperCommandRegistry.addCommand(new SpellsCommand(gameManager));
+        creeperCommandRegistry.addCommand(new LeaveCommand(gameManager));
     }
 }
diff --git a/src/main/java/com/comandante/creeper/command/LeaveCommand.java b/src/main/java/com/comandante/creeper/command/LeaveCommand.java
new file mode 100644
index 00000000..1325e3a4
--- /dev/null
+++ b/src/main/java/com/comandante/creeper/command/LeaveCommand.java
@@ -0,0 +1,42 @@
+package com.comandante.creeper.command;
+
+import com.comandante.creeper.managers.GameManager;
+import com.comandante.creeper.player.PlayerMovement;
+import com.comandante.creeper.world.RemoteExit;
+import com.comandante.creeper.world.Room;
+import org.jboss.netty.channel.ChannelHandlerContext;
+import org.jboss.netty.channel.MessageEvent;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+
+
+public class LeaveCommand extends Command {
+    final static List<String> validTriggers = Arrays.asList("leave");
+    final static String description = "Enters a Leave exit";
+    final static String correctUsage = "leave";
+
+    public LeaveCommand(GameManager gameManager) {
+        super(gameManager, validTriggers, description, correctUsage);
+    }
+
+    @Override
+    public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
+        execCommand(ctx, e, () -> {
+            PlayerMovement playerMovement;
+            List<RemoteExit> leave = currentRoom.getEnterExits().stream().filter(remoteExit -> remoteExit.getExitDetail().equalsIgnoreCase("leave")).collect(Collectors.toList());
+            if (leave.size() > 0) {
+                Room destinationRoom = roomManager.getRoom(leave.get(0).getRoomId());
+                playerMovement = new PlayerMovement(player, currentRoom.getRoomId(), destinationRoom.getRoomId(), "entered " + leave.get(0).getExitDetail() + ".", "N/A");
+                player.movePlayer(playerMovement);
+                if (playerMovement != null) {
+                    player.setReturnDirection(java.util.Optional.of(playerMovement.getReturnDirection()));
+                    printCurrentRoomInformation(roomManager.getRoom(playerMovement.getDestinationRoomId()));
+                }
+                return;
+            }
+            write("There is no Leave exit." + "\r\n");
+        });
+    }
+}
\ No newline at end of file
diff --git a/src/main/java/com/comandante/creeper/command/MovementCommand.java b/src/main/java/com/comandante/creeper/command/MovementCommand.java
index 82b6cd62..734ae3b4 100644
--- a/src/main/java/com/comandante/creeper/command/MovementCommand.java
+++ b/src/main/java/com/comandante/creeper/command/MovementCommand.java
@@ -98,7 +98,7 @@ public class MovementCommand extends Command {
         if (originalMessageParts.size() > 1) {
             String enterExitName = originalMessageParts.get(1);
             for (RemoteExit remoteExit : currentRoom.getEnterExits()) {
-                if (remoteExit.getExitDetail().equals(enterExitName)) {
+                if (remoteExit.getExitDetail().equalsIgnoreCase(enterExitName)) {
                     return Optional.of(remoteExit);
                 }
             }
-- 
GitLab