Merge pull request #884 from xaviergmail/superior-foes

Add slayer superior foe notification
This commit is contained in:
Adam
2018-03-15 12:19:44 -04:00
committed by GitHub
3 changed files with 48 additions and 2 deletions

View File

@@ -55,6 +55,16 @@ public interface SlayerConfig extends Config
return true;
}
@ConfigItem(
keyName = "superiornotification",
name = "Superior foe notification",
description = "Toggles notifications on superior foe encounters"
)
default boolean showSuperiorNotification()
{
return true;
}
// Stored data
@ConfigItem(
keyName = "taskName",

View File

@@ -46,6 +46,7 @@ import net.runelite.api.events.ExperienceChanged;
import net.runelite.api.events.GameStateChanged;
import net.runelite.api.widgets.Widget;
import net.runelite.api.widgets.WidgetInfo;
import net.runelite.client.Notifier;
import net.runelite.client.config.ConfigManager;
import net.runelite.client.game.ItemManager;
import net.runelite.client.plugins.Plugin;
@@ -66,6 +67,7 @@ public class SlayerPlugin extends Plugin
private static final String CHAT_GEM_COMPLETE_MESSAGE = "You need something new to hunt.";
private static final Pattern CHAT_COMPLETE_MESSAGE = Pattern.compile("[\\d]+(?:,[\\d]+)?");
private static final String CHAT_CANCEL_MESSAGE = "Your task has been cancelled.";
private static final String CHAT_SUPERIOR_MESSAGE = "A superior foe has appeared...";
//NPC messages
private static final Pattern NPC_ASSIGN_MESSAGE = Pattern.compile(".*Your new task is to kill (\\d*) (.*)\\.");
@@ -89,6 +91,9 @@ public class SlayerPlugin extends Plugin
@Inject
private ItemManager itemManager;
@Inject
private Notifier notifier;
private String taskName;
private int amount;
private TaskCounter counter;
@@ -230,6 +235,12 @@ public class SlayerPlugin extends Plugin
return;
}
if (config.showSuperiorNotification() && chatMsg.equals(CHAT_SUPERIOR_MESSAGE))
{
notifier.notify(CHAT_SUPERIOR_MESSAGE);
return;
}
Matcher mProgress = CHAT_GEM_PROGRESS_MESSAGE.matcher(chatMsg);
if (!mProgress.find())
{

View File

@@ -24,22 +24,27 @@
*/
package net.runelite.client.plugins.slayer;
import static net.runelite.api.ChatMessageType.SERVER;
import static org.junit.Assert.assertEquals;
import com.google.inject.Guice;
import com.google.inject.testing.fieldbinder.Bind;
import com.google.inject.testing.fieldbinder.BoundFieldModule;
import javax.inject.Inject;
import static net.runelite.api.ChatMessageType.SERVER;
import net.runelite.api.Client;
import net.runelite.api.events.ChatMessage;
import net.runelite.client.Notifier;
import net.runelite.client.game.ItemManager;
import net.runelite.client.ui.overlay.infobox.InfoBoxManager;
import static org.junit.Assert.assertEquals;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
import org.mockito.runners.MockitoJUnitRunner;
@RunWith(MockitoJUnitRunner.class)
public class SlayerPluginTest
{
@@ -50,6 +55,8 @@ public class SlayerPluginTest
private static final String TASK_COMPLETE = "You need something new to hunt.";
private static final String TASK_CANCELED = "Your task has been cancelled.";
private static final String SUPERIOR_MESSAGE = "A superior foe has appeared...";
@Mock
@Bind
Client client;
@@ -70,6 +77,10 @@ public class SlayerPluginTest
@Bind
ItemManager itemManager;
@Mock
@Bind
Notifier notifier;
@Inject
SlayerPlugin slayerPlugin;
@@ -138,4 +149,18 @@ public class SlayerPluginTest
assertEquals("", slayerPlugin.getTaskName());
assertEquals(0, slayerPlugin.getAmount());
}
@Test
public void testSuperiorNotification()
{
ChatMessage chatMessageEvent = new ChatMessage(SERVER, "Superior", SUPERIOR_MESSAGE, null);
when(slayerConfig.showSuperiorNotification()).thenReturn(true);
slayerPlugin.onChatMessage(chatMessageEvent);
verify(notifier).notify(SUPERIOR_MESSAGE);
when(slayerConfig.showSuperiorNotification()).thenReturn(false);
slayerPlugin.onChatMessage(chatMessageEvent);
verifyNoMoreInteractions(notifier);
}
}