Skip to content

More deprecation/warning related fixes and changes #191

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 25 additions & 24 deletions src/main/java/com/botdetector/BotDetectorPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ BotDetectorConfig provideConfig(ConfigManager configManager)
/** A blocked world should not log {@link PlayerSighting}s (see {@link #processCurrentWorld()} and {@link #ALLOWED_PROFILE_TYPES}). **/
private boolean isCurrentWorldBlocked;
/** A queue containing the last two {@link GameState}s from {@link #onGameStateChanged(GameStateChanged)}. **/
private EvictingQueue<GameState> previousTwoGameStates = EvictingQueue.create(2);
private final EvictingQueue<GameState> previousTwoGameStates = EvictingQueue.create(2);

/** The currently loaded token or {@link AuthToken#EMPTY_TOKEN} if no valid token is loaded. **/
@Getter
Expand Down Expand Up @@ -662,7 +662,11 @@ private void onGameStateChanged(GameStateChanged event)
&& previousTwoGameStates.contains(GameState.LOGGED_IN)
&& previousTwoGameStates.contains(GameState.LOADING))
{
client.getPlayers().forEach(this::processPlayer);
WorldView wv = client.getTopLevelWorldView();
if (wv != null)
{
wv.players().forEach(this::processPlayer);
}
}
break;
}
Expand Down Expand Up @@ -724,16 +728,18 @@ private void processPlayer(Player player)
// IDK man I can't ever seem to be able to repro this...
clientThread.invoke(() ->
{
boolean instanced = client.isInInstancedRegion();
WorldView wv = client.getTopLevelWorldView();
boolean instanced = wv != null && wv.isInstance();

WorldPoint wp = !instanced ? player.getWorldLocation()
: WorldPoint.fromLocalInstance(client, player.getLocalLocation());

if (wp.getRegionID() > MAX_ALLOWED_REGION_ID)
{
WorldView wv2 = client.getTopLevelWorldView();
log.warn(String.format("Player sighting with invalid region ID. (name:'%s' x:%d y:%d z:%d r:%d s:%d)",
playerName, wp.getX(), wp.getY(), wp.getPlane(), wp.getRegionID(),
(instanced ? 1 : 0) + (client.isInInstancedRegion() ? 2 : 0))); // Sanity check
(instanced ? 1 : 0) + (wv2 != null && wv2.isInstance() ? 2 : 0))); // Sanity check
return;
}

Expand Down Expand Up @@ -984,7 +990,7 @@ private void onMenuEntryAdded(MenuEntryAdded event)
|| groupId == InterfaceID.GROUP_IRON && (option.equals("Add friend") || option.equals("Remove friend") || option.equals("Remove ignore")))
{
// TODO: Properly use the new menu entry callbacks
client.createMenuEntry(-1)
client.getMenu().createMenuEntry(-1)
.setOption(getPredictOption(event.getTarget()))
.setTarget(event.getTarget())
.setType(MenuAction.RUNELITE)
Expand All @@ -1003,12 +1009,6 @@ private void onMenuOpened(MenuOpened event)
return;
}

final WorldView wv = client.getTopLevelWorldView();
if (wv == null)
{
return;
}

boolean changeReportOption = config.applyPredictColorsOnReportOption();
// Do this once when the menu opens
// Avoids having to loop the menu entries on every 'added' event
Expand All @@ -1024,7 +1024,7 @@ private void onMenuOpened(MenuOpened event)
if (type == MenuAction.RUNELITE_PLAYER.getId()
&& entry.getOption().equals(PREDICT_OPTION))
{
Player player = wv.players().byIndex(entry.getIdentifier());
Player player = entry.getPlayer();
if (player != null)
{
entry.setOption(getPredictOption(player.getName()));
Expand All @@ -1035,7 +1035,7 @@ private void onMenuOpened(MenuOpened event)
if (changeReportOption && entry.getOption().equals(REPORT_OPTION)
&& (PLAYER_MENU_ACTIONS.contains(entry.getType()) || entry.getType() == MenuAction.CC_OP_LOW_PRIORITY))
{
Player player = wv.players().byIndex(entry.getIdentifier());
Player player = entry.getPlayer();
if (player != null)
{
entry.setOption(getReportOption(player.getName()));
Expand All @@ -1057,18 +1057,11 @@ private void onMenuOptionClicked(MenuOptionClicked event)
if (event.getMenuAction() == MenuAction.RUNELITE_PLAYER
|| PLAYER_MENU_ACTIONS.contains(event.getMenuAction()))
{
WorldView wv = client.getTopLevelWorldView();
if (wv == null)
{
return;
}

Player player = wv.players().byIndex(event.getId());
Player player = event.getMenuEntry().getPlayer();
if (player == null)
{
return;
}

name = player.getName();
}
else
Expand Down Expand Up @@ -1274,7 +1267,7 @@ private void manualFlushCommand()
}

/**
* Manually force a full rescan of all players in {@link Client#getPlayers()} using {@link #processPlayer(Player)}.
* Manually force a full rescan of all players in {@link WorldView#players()} using {@link #processPlayer(Player)}.
*/
private void manualSightCommand()
{
Expand All @@ -1289,8 +1282,16 @@ else if (client.getGameState() != GameState.LOGGED_IN)
}
else
{
client.getPlayers().forEach(this::processPlayer);
sendChatStatusMessage("Player sightings refreshed.", true);
WorldView wv = client.getTopLevelWorldView();
if (wv != null)
{
wv.players().forEach(this::processPlayer);
sendChatStatusMessage("Player sightings refreshed.", true);
}
else
{
sendChatStatusMessage("Could not refresh player sightings for an unknown reason.", true);
}
}
}

Expand Down
Loading