Skip to content

Commit

Permalink
worldhopper: fix spam in chatbox when trying to open switcher in bank
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderhenne authored and Adam- committed Aug 18, 2018
1 parent 1f82fe4 commit 1e5cf3a
Showing 1 changed file with 64 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@
import net.runelite.api.MenuAction;
import net.runelite.api.MenuEntry;
import net.runelite.api.Varbits;
import net.runelite.api.events.ChatMessage;
import net.runelite.api.events.ConfigChanged;
import net.runelite.api.events.GameStateChanged;
import net.runelite.api.events.GameTick;
import net.runelite.api.events.MenuEntryAdded;
import net.runelite.api.events.PlayerMenuOptionClicked;
import net.runelite.api.events.VarbitChanged;
Expand Down Expand Up @@ -93,6 +95,8 @@ public class WorldHopperPlugin extends Plugin
private static final int REFRESH_THROTTLE = 60_000; // ms
private static final int TICK_THROTTLE = (int) Duration.ofMinutes(10).toMillis();

private static final int DISPLAY_SWITCHER_MAX_ATTEMPTS = 3;

private static final String HOP_TO = "Hop-to";
private static final String KICK_OPTION = "Kick";
private static final ImmutableList<String> BEFORE_OPTIONS = ImmutableList.of("Add friend", "Remove friend", KICK_OPTION);
Expand Down Expand Up @@ -125,6 +129,9 @@ public class WorldHopperPlugin extends Plugin
private NavigationButton navButton;
private WorldSwitcherPanel panel;

private net.runelite.api.World quickHopTargetWorld;
private int displaySwitcherAttempts = 0;

@Getter
private int lastWorld;

Expand Down Expand Up @@ -586,17 +593,67 @@ private void hop(int worldId)
.runeLiteFormattedMessage(chatMessage)
.build());

clientThread.invokeLater(() ->
quickHopTargetWorld = rsWorld;
displaySwitcherAttempts = 0;
}

@Subscribe
public void onGameTick(GameTick event)
{
if (quickHopTargetWorld == null)
{
return;
}

if (client.getWidget(WidgetInfo.WORLD_SWITCHER_LIST) == null)
{
if (client.getWidget(WidgetInfo.WORLD_SWITCHER_LIST) == null)
client.openWorldHopper();

if (++displaySwitcherAttempts >= DISPLAY_SWITCHER_MAX_ATTEMPTS)
{
client.openWorldHopper();
return false;
String chatMessage = new ChatMessageBuilder()
.append(ChatColorType.NORMAL)
.append("Failed to quick-hop after ")
.append(ChatColorType.HIGHLIGHT)
.append(Integer.toString(displaySwitcherAttempts))
.append(ChatColorType.NORMAL)
.append(" attempts.")
.build();

chatMessageManager
.queue(QueuedMessage.builder()
.type(ChatMessageType.GAME)
.runeLiteFormattedMessage(chatMessage)
.build());

resetQuickHopper();
}
}
else
{
client.hopToWorld(quickHopTargetWorld);
resetQuickHopper();
}
}

client.hopToWorld(rsWorld);
return true;
});
@Subscribe
public void onChatMessage(ChatMessage event)
{
if (event.getType() != ChatMessageType.SERVER)
{
return;
}

if (event.getMessage().equals("Please finish what you're doing before using the World Switcher."))
{
resetQuickHopper();
}
}

private void resetQuickHopper()
{
displaySwitcherAttempts = 0;
quickHopTargetWorld = null;
}

private ChatPlayer getChatPlayerFromName(String name)
Expand Down

0 comments on commit 1e5cf3a

Please sign in to comment.