npcunaggroarea: Merge nested if statements

This commit is contained in:
sdburns1998
2019-07-07 15:58:59 +02:00
parent ef256b40c7
commit 44e2ab21cf

View File

@@ -24,13 +24,10 @@
*/ */
package net.runelite.client.plugins.npcunaggroarea; package net.runelite.client.plugins.npcunaggroarea;
import java.awt.Color;
import javax.inject.Singleton;
import lombok.AccessLevel;
import net.runelite.api.geometry.Geometry;
import com.google.common.base.Splitter; import com.google.common.base.Splitter;
import com.google.common.base.Strings; import com.google.common.base.Strings;
import com.google.inject.Provides; import com.google.inject.Provides;
import java.awt.Color;
import java.awt.Polygon; import java.awt.Polygon;
import java.awt.Rectangle; import java.awt.Rectangle;
import java.awt.geom.Area; import java.awt.geom.Area;
@@ -41,6 +38,8 @@ import java.time.Instant;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton;
import lombok.AccessLevel;
import lombok.Getter; import lombok.Getter;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import net.runelite.api.Client; import net.runelite.api.Client;
@@ -56,6 +55,7 @@ import net.runelite.api.events.ConfigChanged;
import net.runelite.api.events.GameStateChanged; import net.runelite.api.events.GameStateChanged;
import net.runelite.api.events.GameTick; import net.runelite.api.events.GameTick;
import net.runelite.api.events.NpcSpawned; import net.runelite.api.events.NpcSpawned;
import net.runelite.api.geometry.Geometry;
import net.runelite.client.config.ConfigManager; import net.runelite.client.config.ConfigManager;
import net.runelite.client.eventbus.Subscribe; import net.runelite.client.eventbus.Subscribe;
import net.runelite.client.game.ItemManager; import net.runelite.client.game.ItemManager;
@@ -345,20 +345,17 @@ public class NpcAggroAreaPlugin extends Plugin
public void onGameTick(GameTick event) public void onGameTick(GameTick event)
{ {
WorldPoint newLocation = client.getLocalPlayer().getWorldLocation(); WorldPoint newLocation = client.getLocalPlayer().getWorldLocation();
if (lastPlayerLocation != null) if (lastPlayerLocation != null && safeCenters[1] == null && newLocation.distanceTo2D(lastPlayerLocation) > SAFE_AREA_RADIUS * 4)
{ {
if (safeCenters[1] == null && newLocation.distanceTo2D(lastPlayerLocation) > SAFE_AREA_RADIUS * 4) safeCenters[0] = null;
{ safeCenters[1] = newLocation;
safeCenters[0] = null; resetTimer();
safeCenters[1] = newLocation; calculateLinesToDisplay();
resetTimer();
calculateLinesToDisplay();
// We don't know where the previous area was, so if the player e.g. // We don't know where the previous area was, so if the player e.g.
// entered a dungeon and then goes back out, he/she may enter the previous // entered a dungeon and then goes back out, he/she may enter the previous
// area which is unknown and would make the plugin inaccurate // area which is unknown and would make the plugin inaccurate
previousUnknownCenter = lastPlayerLocation; previousUnknownCenter = lastPlayerLocation;
}
} }
if (safeCenters[0] == null && previousUnknownCenter != null && if (safeCenters[0] == null && previousUnknownCenter != null &&
@@ -371,17 +368,14 @@ public class NpcAggroAreaPlugin extends Plugin
calculateLinesToDisplay(); calculateLinesToDisplay();
} }
if (safeCenters[1] != null) if (safeCenters[1] != null && Arrays.stream(safeCenters).noneMatch(
x -> x != null && x.distanceTo2D(newLocation) <= SAFE_AREA_RADIUS))
{ {
if (Arrays.stream(safeCenters).noneMatch( safeCenters[0] = safeCenters[1];
x -> x != null && x.distanceTo2D(newLocation) <= SAFE_AREA_RADIUS)) safeCenters[1] = newLocation;
{ resetTimer();
safeCenters[0] = safeCenters[1]; calculateLinesToDisplay();
safeCenters[1] = newLocation; previousUnknownCenter = null;
resetTimer();
calculateLinesToDisplay();
previousUnknownCenter = null;
}
} }
lastPlayerLocation = newLocation; lastPlayerLocation = newLocation;