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;
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.Strings;
import com.google.inject.Provides;
import java.awt.Color;
import java.awt.Polygon;
import java.awt.Rectangle;
import java.awt.geom.Area;
@@ -41,6 +38,8 @@ import java.time.Instant;
import java.util.Arrays;
import java.util.List;
import javax.inject.Inject;
import javax.inject.Singleton;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
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.GameTick;
import net.runelite.api.events.NpcSpawned;
import net.runelite.api.geometry.Geometry;
import net.runelite.client.config.ConfigManager;
import net.runelite.client.eventbus.Subscribe;
import net.runelite.client.game.ItemManager;
@@ -345,20 +345,17 @@ public class NpcAggroAreaPlugin extends Plugin
public void onGameTick(GameTick event)
{
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;
resetTimer();
calculateLinesToDisplay();
safeCenters[0] = null;
safeCenters[1] = newLocation;
resetTimer();
calculateLinesToDisplay();
// 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
// area which is unknown and would make the plugin inaccurate
previousUnknownCenter = lastPlayerLocation;
}
// 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
// area which is unknown and would make the plugin inaccurate
previousUnknownCenter = lastPlayerLocation;
}
if (safeCenters[0] == null && previousUnknownCenter != null &&
@@ -371,17 +368,14 @@ public class NpcAggroAreaPlugin extends Plugin
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(
x -> x != null && x.distanceTo2D(newLocation) <= SAFE_AREA_RADIUS))
{
safeCenters[0] = safeCenters[1];
safeCenters[1] = newLocation;
resetTimer();
calculateLinesToDisplay();
previousUnknownCenter = null;
}
safeCenters[0] = safeCenters[1];
safeCenters[1] = newLocation;
resetTimer();
calculateLinesToDisplay();
previousUnknownCenter = null;
}
lastPlayerLocation = newLocation;