opponent info plugin: Fix possible onGameTick NPE

The plugin is initialized with `lastTime` as null, meaning that if
`onGameTick` is called before `onInteractingChanged`, you can encounter
a case where after starting the client or plugin, `lastTime` has not yet
been set while `client.getLocalPlayer().getInteracting` is null (because
`onGameTick` gets sequenced before `onInteractingChanged` per tick),
causing an NPE when trying to compare a null Duration.

Fixes runelite/runelite#5451
This commit is contained in:
Jordan Atwood
2018-09-14 14:36:10 -07:00
parent 89b8bc52ca
commit 91369c41f0

View File

@@ -154,7 +154,9 @@ public class OpponentInfoPlugin extends Plugin
@Subscribe
public void onGameTick(GameTick gameTick)
{
if (lastOpponent != null && client.getLocalPlayer().getInteracting() == null)
if (lastOpponent != null
&& lastTime != null
&& client.getLocalPlayer().getInteracting() == null)
{
if (Duration.between(lastTime, Instant.now()).compareTo(WAIT) > 0)
{