Re-optimize wikiplugin, call contains on hashmultimap in menumanager
This commit is contained in:
@@ -266,6 +266,8 @@ public class MenuManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
int widgetId = event.getParam1();
|
int widgetId = event.getParam1();
|
||||||
|
if (managedMenuOptions.containsKey(widgetId))
|
||||||
|
{
|
||||||
Collection<WidgetMenuOption> options = managedMenuOptions.get(widgetId);
|
Collection<WidgetMenuOption> options = managedMenuOptions.get(widgetId);
|
||||||
|
|
||||||
for (WidgetMenuOption currentMenu : options)
|
for (WidgetMenuOption currentMenu : options)
|
||||||
@@ -284,6 +286,7 @@ public class MenuManager
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void rebuildLeftClickMenu()
|
private void rebuildLeftClickMenu()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -25,11 +25,8 @@
|
|||||||
package net.runelite.client.plugins.wiki;
|
package net.runelite.client.plugins.wiki;
|
||||||
|
|
||||||
import com.google.common.primitives.Ints;
|
import com.google.common.primitives.Ints;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.stream.Stream;
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Provider;
|
import javax.inject.Provider;
|
||||||
import javax.inject.Singleton;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import net.runelite.api.Client;
|
import net.runelite.api.Client;
|
||||||
import net.runelite.api.MenuEntry;
|
import net.runelite.api.MenuEntry;
|
||||||
@@ -53,18 +50,18 @@ import net.runelite.client.callback.ClientThread;
|
|||||||
import net.runelite.client.eventbus.Subscribe;
|
import net.runelite.client.eventbus.Subscribe;
|
||||||
import net.runelite.client.game.ItemManager;
|
import net.runelite.client.game.ItemManager;
|
||||||
import net.runelite.client.game.SpriteManager;
|
import net.runelite.client.game.SpriteManager;
|
||||||
import net.runelite.client.game.chatbox.ChatboxPanelManager;
|
|
||||||
import net.runelite.client.plugins.Plugin;
|
import net.runelite.client.plugins.Plugin;
|
||||||
import net.runelite.client.plugins.PluginDescriptor;
|
import net.runelite.client.plugins.PluginDescriptor;
|
||||||
import net.runelite.client.util.LinkBrowser;
|
import net.runelite.client.util.LinkBrowser;
|
||||||
import okhttp3.HttpUrl;
|
import okhttp3.HttpUrl;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@PluginDescriptor(
|
@PluginDescriptor(
|
||||||
name = "Wiki",
|
name = "Wiki",
|
||||||
description = "Adds a Wiki button that takes you to the OSRS Wiki"
|
description = "Adds a Wiki button that takes you to the OSRS Wiki"
|
||||||
)
|
)
|
||||||
@Singleton
|
|
||||||
public class WikiPlugin extends Plugin
|
public class WikiPlugin extends Plugin
|
||||||
{
|
{
|
||||||
private static final int[] QUESTLIST_WIDGET_IDS = new int[]
|
private static final int[] QUESTLIST_WIDGET_IDS = new int[]
|
||||||
@@ -92,9 +89,6 @@ public class WikiPlugin extends Plugin
|
|||||||
@Inject
|
@Inject
|
||||||
private Client client;
|
private Client client;
|
||||||
|
|
||||||
@Inject
|
|
||||||
private ChatboxPanelManager chatboxPanelManager;
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private ItemManager itemManager;
|
private ItemManager itemManager;
|
||||||
|
|
||||||
@@ -108,7 +102,6 @@ public class WikiPlugin extends Plugin
|
|||||||
@Override
|
@Override
|
||||||
public void startUp()
|
public void startUp()
|
||||||
{
|
{
|
||||||
|
|
||||||
spriteManager.addSpriteOverrides(WikiSprite.values());
|
spriteManager.addSpriteOverrides(WikiSprite.values());
|
||||||
clientThread.invokeLater(this::addWidgets);
|
clientThread.invokeLater(this::addWidgets);
|
||||||
}
|
}
|
||||||
@@ -199,9 +192,16 @@ public class WikiPlugin extends Plugin
|
|||||||
@Subscribe
|
@Subscribe
|
||||||
private void onMenuOptionClicked(MenuOptionClicked ev)
|
private void onMenuOptionClicked(MenuOptionClicked ev)
|
||||||
{
|
{
|
||||||
optarget:
|
if (ev.getMenuOpcode() == MenuOpcode.RUNELITE)
|
||||||
if (wikiSelected)
|
|
||||||
{
|
{
|
||||||
|
checkQuestClicked(ev);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!wikiSelected)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
onDeselect();
|
onDeselect();
|
||||||
client.setSpellSelected(false);
|
client.setSpellSelected(false);
|
||||||
ev.consume();
|
ev.consume();
|
||||||
@@ -214,8 +214,6 @@ public class WikiPlugin extends Plugin
|
|||||||
switch (ev.getMenuOpcode())
|
switch (ev.getMenuOpcode())
|
||||||
{
|
{
|
||||||
case RUNELITE:
|
case RUNELITE:
|
||||||
// This is a quest widget op
|
|
||||||
break optarget;
|
|
||||||
case CANCEL:
|
case CANCEL:
|
||||||
return;
|
return;
|
||||||
case ITEM_USE_ON_WIDGET:
|
case ITEM_USE_ON_WIDGET:
|
||||||
@@ -251,6 +249,7 @@ public class WikiPlugin extends Plugin
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SPELL_CAST_ON_WIDGET:
|
case SPELL_CAST_ON_WIDGET:
|
||||||
|
{
|
||||||
Widget w = getWidget(ev.getParam1(), ev.getParam0());
|
Widget w = getWidget(ev.getParam1(), ev.getParam0());
|
||||||
|
|
||||||
if (w.getType() == WidgetType.GRAPHIC && w.getItemId() != -1)
|
if (w.getType() == WidgetType.GRAPHIC && w.getItemId() != -1)
|
||||||
@@ -261,6 +260,7 @@ public class WikiPlugin extends Plugin
|
|||||||
location = null;
|
location = null;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// fallthrough
|
// fallthrough
|
||||||
default:
|
default:
|
||||||
log.info("Unknown menu option: {} {} {}", ev, ev.getMenuOpcode(), ev.getMenuOpcode() == MenuOpcode.CANCEL);
|
log.info("Unknown menu option: {} {} {}", ev, ev.getMenuOpcode(), ev.getMenuOpcode() == MenuOpcode.CANCEL);
|
||||||
@@ -285,10 +285,9 @@ public class WikiPlugin extends Plugin
|
|||||||
HttpUrl url = urlBuilder.build();
|
HttpUrl url = urlBuilder.build();
|
||||||
|
|
||||||
LinkBrowser.browse(url.toString());
|
LinkBrowser.browse(url.toString());
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ev.getMenuOpcode() == MenuOpcode.RUNELITE)
|
private void checkQuestClicked(MenuOptionClicked ev)
|
||||||
{
|
{
|
||||||
boolean quickguide = false;
|
boolean quickguide = false;
|
||||||
switch (ev.getOption())
|
switch (ev.getOption())
|
||||||
@@ -317,7 +316,6 @@ public class WikiPlugin extends Plugin
|
|||||||
.build().toString());
|
.build().toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private void openSearchInput()
|
private void openSearchInput()
|
||||||
{
|
{
|
||||||
@@ -325,22 +323,11 @@ public class WikiPlugin extends Plugin
|
|||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Widget getWidget(int wid, int index)
|
|
||||||
{
|
|
||||||
Widget w = client.getWidget(WidgetInfo.TO_GROUP(wid), WidgetInfo.TO_CHILD(wid));
|
|
||||||
if (index != -1)
|
|
||||||
{
|
|
||||||
w = w.getChild(index);
|
|
||||||
}
|
|
||||||
return w;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
private void onMenuEntryAdded(MenuEntryAdded event)
|
private void onMenuEntryAdded(MenuEntryAdded event)
|
||||||
{
|
{
|
||||||
int widgetIndex = event.getParam0();
|
int widgetIndex = event.getParam0();
|
||||||
int widgetID = event.getParam1();
|
int widgetID = event.getParam1();
|
||||||
MenuEntry[] menuEntries = client.getMenuEntries();
|
|
||||||
|
|
||||||
if (wikiSelected && event.getOpcode() == MenuOpcode.SPELL_CAST_ON_WIDGET.getId())
|
if (wikiSelected && event.getOpcode() == MenuOpcode.SPELL_CAST_ON_WIDGET.getId())
|
||||||
{
|
{
|
||||||
@@ -350,13 +337,16 @@ public class WikiPlugin extends Plugin
|
|||||||
// we don't support this widget
|
// we don't support this widget
|
||||||
// remove the last SPELL_CAST_ON_WIDGET; we can't blindly remove the top action because some other
|
// remove the last SPELL_CAST_ON_WIDGET; we can't blindly remove the top action because some other
|
||||||
// plugin might have added something on this same event, and we probably shouldn't remove that instead
|
// plugin might have added something on this same event, and we probably shouldn't remove that instead
|
||||||
MenuEntry[] oldEntries = menuEntries;
|
MenuEntry[] menuEntries = client.getMenuEntries();
|
||||||
menuEntries = Arrays.copyOf(menuEntries, menuEntries.length - 1);
|
for (int i = menuEntries.length - 1; i >= 0; i--)
|
||||||
for (int ourEntry = oldEntries.length - 1; ourEntry >= 2 && oldEntries[oldEntries.length - 1].getOpcode() != MenuOpcode.SPELL_CAST_ON_WIDGET.getId(); ourEntry--)
|
|
||||||
{
|
{
|
||||||
menuEntries[ourEntry - 1] = oldEntries[ourEntry];
|
if (menuEntries[i].getOpcode() == MenuOpcode.SPELL_CAST_ON_WIDGET.getId())
|
||||||
}
|
{
|
||||||
|
menuEntries[i] = null;
|
||||||
client.setMenuEntries(menuEntries);
|
client.setMenuEntries(menuEntries);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -396,9 +386,7 @@ public class WikiPlugin extends Plugin
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String action = Stream.of(w.getActions())
|
String action = firstAction(w);
|
||||||
.filter(s -> s != null && !s.isEmpty())
|
|
||||||
.findFirst().orElse(null);
|
|
||||||
if (action == null)
|
if (action == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
@@ -424,9 +412,7 @@ public class WikiPlugin extends Plugin
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String action = Stream.of(w.getActions())
|
String action = firstAction(w);
|
||||||
.filter(s -> s != null && !s.isEmpty())
|
|
||||||
.findFirst().orElse(null);
|
|
||||||
if (action == null)
|
if (action == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
@@ -443,4 +429,28 @@ public class WikiPlugin extends Plugin
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Widget getWidget(int wid, int index)
|
||||||
|
{
|
||||||
|
Widget w = client.getWidget(WidgetInfo.TO_GROUP(wid), WidgetInfo.TO_CHILD(wid));
|
||||||
|
if (index != -1)
|
||||||
|
{
|
||||||
|
w = w.getChild(index);
|
||||||
|
}
|
||||||
|
return w;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private static String firstAction(Widget widget)
|
||||||
|
{
|
||||||
|
for (String action : widget.getActions())
|
||||||
|
{
|
||||||
|
if (StringUtils.isNotEmpty(action))
|
||||||
|
{
|
||||||
|
return action;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user