Add automatic bounty hunter target lookup in HiScore plugin (#5193)
Make HiScore plugin lookup bounty hunter target automatically on chat message that the person got new target assigned (disabled by default). Closes #4173
This commit is contained in:
committed by
Tomas Slusny
parent
44782c156a
commit
0a17590c2a
@@ -74,4 +74,15 @@ public interface HiscoreConfig extends Config
|
|||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ConfigItem(
|
||||||
|
position = 5,
|
||||||
|
keyName = "bountylookup",
|
||||||
|
name = "Bounty lookup",
|
||||||
|
description = "Automatically lookup the stats of your bounty hunter target"
|
||||||
|
)
|
||||||
|
default boolean bountylookup()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -31,13 +31,17 @@ import com.google.inject.Provides;
|
|||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Provider;
|
import javax.inject.Provider;
|
||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
|
import net.runelite.api.ChatMessageType;
|
||||||
import net.runelite.api.Client;
|
import net.runelite.api.Client;
|
||||||
import net.runelite.api.MenuAction;
|
import net.runelite.api.MenuAction;
|
||||||
import net.runelite.api.MenuEntry;
|
import net.runelite.api.MenuEntry;
|
||||||
|
import net.runelite.api.events.ChatMessage;
|
||||||
import net.runelite.api.events.ConfigChanged;
|
import net.runelite.api.events.ConfigChanged;
|
||||||
import net.runelite.api.events.MenuEntryAdded;
|
import net.runelite.api.events.MenuEntryAdded;
|
||||||
import net.runelite.api.events.PlayerMenuOptionClicked;
|
import net.runelite.api.events.PlayerMenuOptionClicked;
|
||||||
@@ -64,6 +68,7 @@ public class HiscorePlugin extends Plugin
|
|||||||
private static final String KICK_OPTION = "Kick";
|
private static final String KICK_OPTION = "Kick";
|
||||||
private static final ImmutableList<String> BEFORE_OPTIONS = ImmutableList.of("Add friend", "Remove friend", KICK_OPTION);
|
private static final ImmutableList<String> BEFORE_OPTIONS = ImmutableList.of("Add friend", "Remove friend", KICK_OPTION);
|
||||||
private static final ImmutableList<String> AFTER_OPTIONS = ImmutableList.of("Message");
|
private static final ImmutableList<String> AFTER_OPTIONS = ImmutableList.of("Message");
|
||||||
|
private static final Pattern BOUNTY_PATTERN = Pattern.compile("<col=ff0000>You've been assigned a target: (.*)</col>");
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@Nullable
|
@Nullable
|
||||||
@@ -201,6 +206,31 @@ public class HiscorePlugin extends Plugin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onPlayerMenuOptionClicked(PlayerMenuOptionClicked event)
|
||||||
|
{
|
||||||
|
if (event.getMenuOption().equals(LOOKUP))
|
||||||
|
{
|
||||||
|
lookupPlayer(Text.removeTags(event.getMenuTarget()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onChatMessage(ChatMessage event)
|
||||||
|
{
|
||||||
|
if (!config.bountylookup() || !event.getType().equals(ChatMessageType.SERVER))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String message = event.getMessage();
|
||||||
|
Matcher m = BOUNTY_PATTERN.matcher(message);
|
||||||
|
if (m.matches())
|
||||||
|
{
|
||||||
|
lookupPlayer(m.group(1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void insertMenuEntry(MenuEntry newEntry, MenuEntry[] entries, boolean after)
|
private void insertMenuEntry(MenuEntry newEntry, MenuEntry[] entries, boolean after)
|
||||||
{
|
{
|
||||||
MenuEntry[] newMenu = ObjectArrays.concat(entries, newEntry);
|
MenuEntry[] newMenu = ObjectArrays.concat(entries, newEntry);
|
||||||
@@ -214,30 +244,26 @@ public class HiscorePlugin extends Plugin
|
|||||||
client.setMenuEntries(newMenu);
|
client.setMenuEntries(newMenu);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
private void lookupPlayer(String playerName)
|
||||||
public void onLookupMenuClicked(PlayerMenuOptionClicked event)
|
|
||||||
{
|
{
|
||||||
if (event.getMenuOption().equals(LOOKUP))
|
executor.execute(() ->
|
||||||
{
|
{
|
||||||
executor.execute(() ->
|
try
|
||||||
{
|
{
|
||||||
try
|
SwingUtilities.invokeAndWait(() ->
|
||||||
{
|
{
|
||||||
SwingUtilities.invokeAndWait(() ->
|
if (!navButton.isSelected())
|
||||||
{
|
{
|
||||||
if (!navButton.isSelected())
|
navButton.getOnSelect().run();
|
||||||
{
|
}
|
||||||
navButton.getOnSelect().run();
|
});
|
||||||
}
|
}
|
||||||
});
|
catch (InterruptedException | InvocationTargetException e)
|
||||||
}
|
{
|
||||||
catch (InterruptedException | InvocationTargetException e)
|
throw new RuntimeException(e);
|
||||||
{
|
}
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
hiscorePanel.lookup(Text.removeTags(event.getMenuTarget()));
|
hiscorePanel.lookup(playerName);
|
||||||
});
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user