Remove deprecated ActorQuery class
This commit is contained in:
@@ -25,13 +25,13 @@
|
||||
*/
|
||||
package net.runelite.client.plugins.fishing;
|
||||
|
||||
import com.google.common.primitives.Ints;
|
||||
import com.google.inject.Provides;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.Arrays;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
@@ -54,8 +54,8 @@ import net.runelite.api.events.GameTick;
|
||||
import net.runelite.api.events.InteractingChanged;
|
||||
import net.runelite.api.events.ItemContainerChanged;
|
||||
import net.runelite.api.events.NpcDespawned;
|
||||
import net.runelite.api.events.NpcSpawned;
|
||||
import net.runelite.api.events.VarbitChanged;
|
||||
import net.runelite.api.queries.NPCQuery;
|
||||
import net.runelite.client.Notifier;
|
||||
import net.runelite.client.config.ConfigManager;
|
||||
import net.runelite.client.eventbus.Subscribe;
|
||||
@@ -64,7 +64,6 @@ import net.runelite.client.plugins.PluginDependency;
|
||||
import net.runelite.client.plugins.PluginDescriptor;
|
||||
import net.runelite.client.plugins.xptracker.XpTrackerPlugin;
|
||||
import net.runelite.client.ui.overlay.OverlayManager;
|
||||
import net.runelite.client.util.QueryRunner;
|
||||
|
||||
@PluginDescriptor(
|
||||
name = "Fishing",
|
||||
@@ -85,10 +84,10 @@ public class FishingPlugin extends Plugin
|
||||
private final FishingSession session = new FishingSession();
|
||||
|
||||
@Getter(AccessLevel.PACKAGE)
|
||||
private Map<Integer, MinnowSpot> minnowSpots = new HashMap<>();
|
||||
private final Map<Integer, MinnowSpot> minnowSpots = new HashMap<>();
|
||||
|
||||
@Getter(AccessLevel.PACKAGE)
|
||||
private NPC[] fishingSpots;
|
||||
private final List<NPC> fishingSpots = new ArrayList<>();
|
||||
|
||||
@Getter(AccessLevel.PACKAGE)
|
||||
private FishingSpot currentSpot;
|
||||
@@ -96,9 +95,6 @@ public class FishingPlugin extends Plugin
|
||||
@Inject
|
||||
private Client client;
|
||||
|
||||
@Inject
|
||||
private QueryRunner queryRunner;
|
||||
|
||||
@Inject
|
||||
private Notifier notifier;
|
||||
|
||||
@@ -141,6 +137,7 @@ public class FishingPlugin extends Plugin
|
||||
overlayManager.remove(overlay);
|
||||
overlayManager.remove(spotOverlay);
|
||||
overlayManager.remove(fishingSpotMinimapOverlay);
|
||||
fishingSpots.clear();
|
||||
minnowSpots.clear();
|
||||
trawlerNotificationSent = false;
|
||||
currentSpot = null;
|
||||
@@ -266,36 +263,19 @@ public class FishingPlugin extends Plugin
|
||||
}
|
||||
}
|
||||
|
||||
final LocalPoint cameraPoint = new LocalPoint(client.getCameraX(), client.getCameraY());
|
||||
inverseSortSpotDistanceFromPlayer();
|
||||
|
||||
final NPCQuery query = new NPCQuery()
|
||||
.idEquals(Ints.toArray(FishingSpot.getSPOTS().keySet()));
|
||||
NPC[] spots = queryRunner.runQuery(query);
|
||||
// -1 to make closer things draw last (on top of farther things)
|
||||
Arrays.sort(spots, Comparator.comparing(npc -> -1 * npc.getLocalLocation().distanceTo(cameraPoint)));
|
||||
fishingSpots = spots;
|
||||
|
||||
// process minnows
|
||||
for (NPC npc : spots)
|
||||
for (NPC npc : fishingSpots)
|
||||
{
|
||||
FishingSpot spot = FishingSpot.getSPOTS().get(npc.getId());
|
||||
|
||||
if (spot == null)
|
||||
if (FishingSpot.getSPOTS().get(npc.getId()) == FishingSpot.MINNOW && config.showMinnowOverlay())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
final int id = npc.getIndex();
|
||||
final MinnowSpot minnowSpot = minnowSpots.get(id);
|
||||
|
||||
if (spot == FishingSpot.MINNOW && config.showMinnowOverlay())
|
||||
{
|
||||
int id = npc.getIndex();
|
||||
MinnowSpot minnowSpot = minnowSpots.get(id);
|
||||
// create the minnow spot if it doesn't already exist
|
||||
if (minnowSpot == null)
|
||||
{
|
||||
minnowSpots.put(id, new MinnowSpot(npc.getWorldLocation(), Instant.now()));
|
||||
}
|
||||
// if moved, reset
|
||||
else if (!minnowSpot.getLoc().equals(npc.getWorldLocation()))
|
||||
// or if it was moved, reset it
|
||||
if (minnowSpot == null
|
||||
|| !minnowSpot.getLoc().equals(npc.getWorldLocation()))
|
||||
{
|
||||
minnowSpots.put(id, new MinnowSpot(npc.getWorldLocation(), Instant.now()));
|
||||
}
|
||||
@@ -303,10 +283,27 @@ public class FishingPlugin extends Plugin
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onNpcSpawned(NpcSpawned event)
|
||||
{
|
||||
final NPC npc = event.getNpc();
|
||||
|
||||
if (!FishingSpot.getSPOTS().containsKey(npc.getId()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
fishingSpots.add(npc);
|
||||
inverseSortSpotDistanceFromPlayer();
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onNpcDespawned(NpcDespawned npcDespawned)
|
||||
{
|
||||
NPC npc = npcDespawned.getNpc();
|
||||
final NPC npc = npcDespawned.getNpc();
|
||||
|
||||
fishingSpots.remove(npc);
|
||||
|
||||
MinnowSpot minnowSpot = minnowSpots.remove(npc.getIndex());
|
||||
if (minnowSpot != null)
|
||||
{
|
||||
@@ -338,4 +335,10 @@ public class FishingPlugin extends Plugin
|
||||
trawlerNotificationSent = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void inverseSortSpotDistanceFromPlayer()
|
||||
{
|
||||
final LocalPoint cameraPoint = new LocalPoint(client.getCameraX(), client.getCameraY());
|
||||
fishingSpots.sort(Comparator.comparing(npc -> -1 * npc.getLocalLocation().distanceTo(cameraPoint)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,13 +62,7 @@ class FishingSpotMinimapOverlay extends Overlay
|
||||
return null;
|
||||
}
|
||||
|
||||
NPC[] fishingSpots = plugin.getFishingSpots();
|
||||
if (fishingSpots == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
for (NPC npc : fishingSpots)
|
||||
for (NPC npc : plugin.getFishingSpots())
|
||||
{
|
||||
FishingSpot spot = FishingSpot.getSPOTS().get(npc.getId());
|
||||
|
||||
|
||||
@@ -79,13 +79,7 @@ class FishingSpotOverlay extends Overlay
|
||||
return null;
|
||||
}
|
||||
|
||||
NPC[] fishingSpots = plugin.getFishingSpots();
|
||||
if (fishingSpots == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
for (NPC npc : fishingSpots)
|
||||
for (NPC npc : plugin.getFishingSpots())
|
||||
{
|
||||
FishingSpot spot = FishingSpot.getSPOTS().get(npc.getId());
|
||||
|
||||
|
||||
@@ -30,15 +30,12 @@ import java.awt.Dimension;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.util.Arrays;
|
||||
import javax.inject.Inject;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.NPC;
|
||||
import net.runelite.api.Query;
|
||||
import net.runelite.api.queries.NPCQuery;
|
||||
import net.runelite.api.widgets.Widget;
|
||||
import net.runelite.api.widgets.WidgetInfo;
|
||||
import static net.runelite.client.plugins.pestcontrol.Portal.BLUE;
|
||||
@@ -48,12 +45,11 @@ import static net.runelite.client.plugins.pestcontrol.Portal.YELLOW;
|
||||
import net.runelite.client.ui.overlay.Overlay;
|
||||
import net.runelite.client.ui.overlay.OverlayPosition;
|
||||
import net.runelite.client.ui.overlay.OverlayUtil;
|
||||
import net.runelite.client.util.QueryRunner;
|
||||
|
||||
@Slf4j
|
||||
public class PestControlOverlay extends Overlay
|
||||
{
|
||||
private final QueryRunner queryRunner;
|
||||
private final PestControlPlugin plugin;
|
||||
private final Client client;
|
||||
|
||||
// Pest control game
|
||||
@@ -61,10 +57,10 @@ public class PestControlOverlay extends Overlay
|
||||
private Game game;
|
||||
|
||||
@Inject
|
||||
public PestControlOverlay(QueryRunner queryRunner, Client client)
|
||||
public PestControlOverlay(PestControlPlugin plugin, Client client)
|
||||
{
|
||||
setPosition(OverlayPosition.DYNAMIC);
|
||||
this.queryRunner = queryRunner;
|
||||
this.plugin = plugin;
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
@@ -97,9 +93,10 @@ public class PestControlOverlay extends Overlay
|
||||
|
||||
private void renderSpinners(Graphics2D graphics)
|
||||
{
|
||||
Query query = new NPCQuery().nameEquals("Spinner");
|
||||
NPC[] result = queryRunner.runQuery(query);
|
||||
Arrays.stream(result).forEach(npc -> OverlayUtil.renderActorOverlay(graphics, npc, npc.getName(), Color.CYAN));
|
||||
for (NPC npc : plugin.getSpinners())
|
||||
{
|
||||
OverlayUtil.renderActorOverlay(graphics, npc, npc.getName(), Color.CYAN);
|
||||
}
|
||||
}
|
||||
|
||||
private void renderPortalWidgets(Graphics2D graphics)
|
||||
|
||||
@@ -24,13 +24,23 @@
|
||||
*/
|
||||
package net.runelite.client.plugins.pestcontrol;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import javax.inject.Inject;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import net.runelite.api.ChatMessageType;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.NPC;
|
||||
import net.runelite.api.NpcID;
|
||||
import net.runelite.api.events.ChatMessage;
|
||||
import net.runelite.client.eventbus.Subscribe;
|
||||
import net.runelite.api.events.NpcDespawned;
|
||||
import net.runelite.api.events.NpcSpawned;
|
||||
import net.runelite.client.plugins.Plugin;
|
||||
import net.runelite.client.plugins.PluginDescriptor;
|
||||
import net.runelite.client.ui.overlay.OverlayManager;
|
||||
@@ -42,8 +52,19 @@ import net.runelite.client.ui.overlay.OverlayManager;
|
||||
)
|
||||
public class PestControlPlugin extends Plugin
|
||||
{
|
||||
private static final Set<Integer> SPINNER_IDS = ImmutableSet.of(
|
||||
NpcID.SPINNER,
|
||||
NpcID.SPINNER_1710,
|
||||
NpcID.SPINNER_1711,
|
||||
NpcID.SPINNER_1712,
|
||||
NpcID.SPINNER_1713
|
||||
);
|
||||
|
||||
private final Pattern SHIELD_DROP = Pattern.compile("The ([a-z]+), [^ ]+ portal shield has dropped!", Pattern.CASE_INSENSITIVE);
|
||||
|
||||
@Getter(AccessLevel.PACKAGE)
|
||||
private List<NPC> spinners = new ArrayList<>();
|
||||
|
||||
@Inject
|
||||
private OverlayManager overlayManager;
|
||||
|
||||
@@ -63,6 +84,7 @@ public class PestControlPlugin extends Plugin
|
||||
protected void shutDown() throws Exception
|
||||
{
|
||||
overlayManager.remove(overlay);
|
||||
spinners.clear();
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
@@ -77,4 +99,20 @@ public class PestControlPlugin extends Plugin
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onNpcSpawned(NpcSpawned event)
|
||||
{
|
||||
final NPC npc = event.getNpc();
|
||||
if (SPINNER_IDS.contains(npc.getId()))
|
||||
{
|
||||
spinners.add(npc);
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onNpcDespawned(NpcDespawned event)
|
||||
{
|
||||
spinners.remove(event.getNpc());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,16 +44,15 @@ import net.runelite.api.Item;
|
||||
import net.runelite.api.ItemID;
|
||||
import net.runelite.api.NPC;
|
||||
import net.runelite.api.NpcID;
|
||||
import net.runelite.api.Query;
|
||||
import net.runelite.api.events.ChatMessage;
|
||||
import net.runelite.api.events.ConfigChanged;
|
||||
import net.runelite.api.events.DecorativeObjectDespawned;
|
||||
import net.runelite.api.events.DecorativeObjectSpawned;
|
||||
import net.runelite.api.events.GameStateChanged;
|
||||
import net.runelite.api.events.GameTick;
|
||||
import net.runelite.api.events.ItemContainerChanged;
|
||||
import net.runelite.api.events.MenuOptionClicked;
|
||||
import net.runelite.api.queries.NPCQuery;
|
||||
import net.runelite.api.events.NpcDespawned;
|
||||
import net.runelite.api.events.NpcSpawned;
|
||||
import net.runelite.api.widgets.Widget;
|
||||
import net.runelite.api.widgets.WidgetInfo;
|
||||
import net.runelite.client.Notifier;
|
||||
@@ -62,7 +61,6 @@ import net.runelite.client.eventbus.Subscribe;
|
||||
import net.runelite.client.plugins.Plugin;
|
||||
import net.runelite.client.plugins.PluginDescriptor;
|
||||
import net.runelite.client.ui.overlay.OverlayManager;
|
||||
import net.runelite.client.util.QueryRunner;
|
||||
|
||||
@PluginDescriptor(
|
||||
name = "Runecraft",
|
||||
@@ -102,9 +100,6 @@ public class RunecraftPlugin extends Plugin
|
||||
@Inject
|
||||
private AbyssOverlay abyssOverlay;
|
||||
|
||||
@Inject
|
||||
private QueryRunner queryRunner;
|
||||
|
||||
@Inject
|
||||
private RunecraftConfig config;
|
||||
|
||||
@@ -253,18 +248,22 @@ public class RunecraftPlugin extends Plugin
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onGameTick(GameTick event)
|
||||
public void onNpcSpawned(NpcSpawned event)
|
||||
{
|
||||
darkMage = null;
|
||||
|
||||
if (!config.hightlightDarkMage()
|
||||
|| !degradedPouchInInventory)
|
||||
final NPC npc = event.getNpc();
|
||||
if (npc.getId() == NpcID.DARK_MAGE)
|
||||
{
|
||||
return;
|
||||
darkMage = npc;
|
||||
}
|
||||
}
|
||||
|
||||
Query darkMageQuery = new NPCQuery().idEquals(NpcID.DARK_MAGE);
|
||||
NPC[] result = queryRunner.runQuery(darkMageQuery);
|
||||
darkMage = result.length >= 1 ? result[0] : null;
|
||||
@Subscribe
|
||||
public void onNpcDespawned(NpcDespawned event)
|
||||
{
|
||||
final NPC npc = event.getNpc();
|
||||
if (npc == darkMage)
|
||||
{
|
||||
darkMage = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user