From 65dd3129eee8dfcd7719112da9a3ff54d6375e9b Mon Sep 17 00:00:00 2001
From: Chris Kearney <chris@kearneymail.com>
Date: Mon, 8 Aug 2016 18:08:00 -0700
Subject: [PATCH] fixes

---
 .../creeper/CreeperConfiguration.java         |  2 +-
 .../creeper/command/CastCommand.java          |  2 +-
 .../creeper/managers/GameManager.java         |  2 +-
 .../com/comandante/creeper/player/Player.java |  9 +----
 .../creeper/server/GossipCache.java           | 12 +++---
 .../creeper/server/GossipCacheTest.java       | 38 +++++++++++++++++++
 world/npcs/treeberserker.json                 |  1 +
 7 files changed, 49 insertions(+), 17 deletions(-)
 create mode 100644 src/test/com/comandante/creeper/server/GossipCacheTest.java

diff --git a/src/main/java/com/comandante/creeper/CreeperConfiguration.java b/src/main/java/com/comandante/creeper/CreeperConfiguration.java
index 79729b0c..ca65d90f 100644
--- a/src/main/java/com/comandante/creeper/CreeperConfiguration.java
+++ b/src/main/java/com/comandante/creeper/CreeperConfiguration.java
@@ -66,7 +66,7 @@ public class CreeperConfiguration {
     public final String weatherUndergroundApiKey;
 
     public static final String MAX_GOSSIP_CACHE_SIZE = "max.gossip.cache.size";
-    public static final int MAX_GOSSIP_CACHE_SIZE_DEFAULT = 100;
+    public static final int MAX_GOSSIP_CACHE_SIZE_DEFAULT = 1000;
     public final int maxGossipCacheSize;
 
     public CreeperConfiguration(Configuration configuration) {
diff --git a/src/main/java/com/comandante/creeper/command/CastCommand.java b/src/main/java/com/comandante/creeper/command/CastCommand.java
index 4509b6ee..ae7e281d 100644
--- a/src/main/java/com/comandante/creeper/command/CastCommand.java
+++ b/src/main/java/com/comandante/creeper/command/CastCommand.java
@@ -27,7 +27,7 @@ public class CastCommand extends Command {
 
     @Override
     public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
-        this.execCommand(ctx, e, () -> {
+        execCommand(ctx, e, () -> {
             if (player.getCurrentHealth() <= 0) {
                 write("You have no health and as such you can not attack.");
                 return;
diff --git a/src/main/java/com/comandante/creeper/managers/GameManager.java b/src/main/java/com/comandante/creeper/managers/GameManager.java
index 258865bc..743f940f 100755
--- a/src/main/java/com/comandante/creeper/managers/GameManager.java
+++ b/src/main/java/com/comandante/creeper/managers/GameManager.java
@@ -391,7 +391,7 @@ public class GameManager {
                 channelUtils.write(player.getPlayerId(), "Your inventory is full, drop some items to free up room.\r\n");
                 if (isFromLoot) {
                     player.getCurrentRoom().addPresentItem(itemId);
-                    roomSay(player.getCurrentRoom().getRoomId(), player.getPlayerName() + " dropped " + itemEntity.getItemName(), player.getPlayerId());
+                    roomSay(player.getCurrentRoom().getRoomId(), player.getPlayerName() + " dropped " + itemEntity.getItemName(), player.getPlayerId() + "\r\n");
                 }
                 return false;
             }
diff --git a/src/main/java/com/comandante/creeper/player/Player.java b/src/main/java/com/comandante/creeper/player/Player.java
index 2f736a9b..5a017253 100755
--- a/src/main/java/com/comandante/creeper/player/Player.java
+++ b/src/main/java/com/comandante/creeper/player/Player.java
@@ -95,19 +95,14 @@ public class Player extends CreeperEntity {
     }
 
     private void processFightRounds() {
-        for (ActiveFight activeFight : activeFights.values()) {
-            doFightRound(activeFight);
-        }
+        activeFights.forEach((aLong, activeFight) -> doFightRound(activeFight));
     }
 
     private void processRegens() {
         synchronized (interner.intern(playerId)) {
             PlayerMetadata playerMetadata = gameManager.getPlayerManager().getPlayerMetadata(playerId);
             Stats stats = getPlayerStatsWithEquipmentAndLevel();
-            if (isActive(CoolDownType.NPC_FIGHT)) {
-                return;
-            }
-            if (isActive(CoolDownType.DEATH)) {
+            if (isActive(CoolDownType.NPC_FIGHT) || isActive(CoolDownType.DEATH)) {
                 return;
             }
             if (playerMetadata.getStats().getCurrentHealth() < stats.getMaxHealth()) {
diff --git a/src/main/java/com/comandante/creeper/server/GossipCache.java b/src/main/java/com/comandante/creeper/server/GossipCache.java
index 402c7c87..3a22c1bc 100644
--- a/src/main/java/com/comandante/creeper/server/GossipCache.java
+++ b/src/main/java/com/comandante/creeper/server/GossipCache.java
@@ -4,7 +4,9 @@ import com.comandante.creeper.managers.GameManager;
 import com.google.api.client.util.Lists;
 import com.google.common.collect.EvictingQueue;
 
-import java.util.*;
+import java.util.Collections;
+import java.util.List;
+import java.util.stream.Collectors;
 
 public class GossipCache {
 
@@ -22,12 +24,8 @@ public class GossipCache {
 
     public List<String> getRecent(int size) {
         List<String> recent = Lists.newArrayList();
-        List<String> currentEntries = Lists.newArrayList();
-        Iterator<String> iterator = evictingQueue.iterator();
-        while (iterator.hasNext()) {
-            String next = iterator.next();
-            currentEntries.add(next);
-        }
+        List<String> currentEntries = evictingQueue.stream().collect(Collectors.toList());
+
         Collections.reverse(currentEntries);
         int i = 0;
         for (String s : currentEntries) {
diff --git a/src/test/com/comandante/creeper/server/GossipCacheTest.java b/src/test/com/comandante/creeper/server/GossipCacheTest.java
new file mode 100644
index 00000000..56710ea8
--- /dev/null
+++ b/src/test/com/comandante/creeper/server/GossipCacheTest.java
@@ -0,0 +1,38 @@
+package com.comandante.creeper.server;
+
+import com.comandante.creeper.CreeperConfiguration;
+import com.comandante.creeper.managers.GameManager;
+import com.google.api.client.util.Maps;
+import org.apache.commons.configuration.MapConfiguration;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.HashMap;
+import java.util.List;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class GossipCacheTest {
+
+    GossipCache gossipCache;
+
+    @Before
+    public void setUp() throws Exception {
+        GameManager mock = mock(GameManager.class);
+        HashMap<String, Object> configuration = Maps.newHashMap();
+        configuration.put("max.gossip.cache.size", 100);
+        CreeperConfiguration creeperConfiguration = new CreeperConfiguration(new MapConfiguration(configuration));
+        when(mock.getCreeperConfiguration()).thenReturn(creeperConfiguration);
+        this.gossipCache = new GossipCache(mock);
+    }
+
+    @Test
+    public void testRecentGossip() throws Exception {
+        for (int i = 0; i < 20; i++) {
+            gossipCache.addGossipLine(String.valueOf(i));
+        }
+        List<String> recent = gossipCache.getRecent(20);
+    }
+
+}
\ No newline at end of file
diff --git a/world/npcs/treeberserker.json b/world/npcs/treeberserker.json
index 9f792659..0e8d951b 100755
--- a/world/npcs/treeberserker.json
+++ b/world/npcs/treeberserker.json
@@ -37,6 +37,7 @@
   },
   "validTriggers": [
     "t",
+    "tree",
     "tree berserker",
     "berserker",
     "b"
-- 
GitLab