idle notifier: prevent double notifications for anim and interact
This commit is contained in:
@@ -561,6 +561,11 @@ public class IdleNotifierPlugin extends Plugin
|
|||||||
{
|
{
|
||||||
lastInteract = null;
|
lastInteract = null;
|
||||||
lastInteracting = null;
|
lastInteracting = null;
|
||||||
|
|
||||||
|
// prevent animation notifications from firing too
|
||||||
|
lastAnimation = IDLE;
|
||||||
|
lastAnimating = null;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -648,6 +653,11 @@ public class IdleNotifierPlugin extends Plugin
|
|||||||
{
|
{
|
||||||
lastAnimation = IDLE;
|
lastAnimation = IDLE;
|
||||||
lastAnimating = null;
|
lastAnimating = null;
|
||||||
|
|
||||||
|
// prevent interaction notifications from firing too
|
||||||
|
lastInteract = null;
|
||||||
|
lastInteracting = null;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,8 +48,10 @@ import org.junit.Before;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
import static org.mockito.ArgumentMatchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
|
import static org.mockito.Mockito.lenient;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.never;
|
import static org.mockito.Mockito.never;
|
||||||
import static org.mockito.Mockito.times;
|
import static org.mockito.Mockito.times;
|
||||||
@@ -83,6 +85,9 @@ public class IdleNotifierPluginTest
|
|||||||
@Mock
|
@Mock
|
||||||
private NPC randomEvent;
|
private NPC randomEvent;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private NPC fishingSpot;
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private Player player;
|
private Player player;
|
||||||
|
|
||||||
@@ -103,6 +108,13 @@ public class IdleNotifierPluginTest
|
|||||||
when(randomEventComp.getActions()).thenReturn(randomEventActions);
|
when(randomEventComp.getActions()).thenReturn(randomEventActions);
|
||||||
when(randomEvent.getComposition()).thenReturn(randomEventComp);
|
when(randomEvent.getComposition()).thenReturn(randomEventComp);
|
||||||
|
|
||||||
|
// Mock Fishing Spot
|
||||||
|
final String[] fishingSpotActions = new String[] { "Use-rod", "Examine" };
|
||||||
|
final NPCComposition fishingSpotComp = mock(NPCComposition.class);
|
||||||
|
when(fishingSpotComp.getActions()).thenReturn(fishingSpotActions);
|
||||||
|
when(fishingSpot.getComposition()).thenReturn(fishingSpotComp);
|
||||||
|
when(fishingSpot.getName()).thenReturn("Fishing spot");
|
||||||
|
|
||||||
// Mock player
|
// Mock player
|
||||||
when(player.getName()).thenReturn(PLAYER_NAME);
|
when(player.getName()).thenReturn(PLAYER_NAME);
|
||||||
when(player.getAnimation()).thenReturn(AnimationID.IDLE);
|
when(player.getAnimation()).thenReturn(AnimationID.IDLE);
|
||||||
@@ -258,6 +270,31 @@ public class IdleNotifierPluginTest
|
|||||||
verify(notifier, times(1)).notify(any());
|
verify(notifier, times(1)).notify(any());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSendOneNotificationForAnimationAndInteract()
|
||||||
|
{
|
||||||
|
when(player.getInteracting()).thenReturn(fishingSpot);
|
||||||
|
when(player.getAnimation()).thenReturn(AnimationID.FISHING_POLE_CAST);
|
||||||
|
|
||||||
|
AnimationChanged animationChanged = new AnimationChanged();
|
||||||
|
animationChanged.setActor(player);
|
||||||
|
|
||||||
|
plugin.onInteractingChanged(new InteractingChanged(player, fishingSpot));
|
||||||
|
plugin.onAnimationChanged(animationChanged);
|
||||||
|
plugin.onGameTick(new GameTick());
|
||||||
|
|
||||||
|
verify(notifier, never()).notify(anyString());
|
||||||
|
|
||||||
|
when(player.getAnimation()).thenReturn(AnimationID.IDLE);
|
||||||
|
lenient().when(player.getInteracting()).thenReturn(null);
|
||||||
|
|
||||||
|
plugin.onAnimationChanged(animationChanged);
|
||||||
|
plugin.onInteractingChanged(new InteractingChanged(player, null));
|
||||||
|
plugin.onGameTick(new GameTick());
|
||||||
|
|
||||||
|
verify(notifier).notify("[" + PLAYER_NAME + "] is now idle!");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSpecRegen()
|
public void testSpecRegen()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user