From 1fb5365e7c7a8ff5d3f65604c25c9e8358a0fefd Mon Sep 17 00:00:00 2001 From: Adam Date: Fri, 17 Aug 2018 22:07:09 -0400 Subject: [PATCH] corp plugin: deprioritize attack option on dark energy core --- .../java/net/runelite/api/MenuAction.java | 2 + .../client/plugins/corp/CorpConfig.java | 44 +++++++++++++++++++ .../client/plugins/corp/CorpPlugin.java | 43 ++++++++++++++++++ 3 files changed, 89 insertions(+) create mode 100644 runelite-client/src/main/java/net/runelite/client/plugins/corp/CorpConfig.java diff --git a/runelite-api/src/main/java/net/runelite/api/MenuAction.java b/runelite-api/src/main/java/net/runelite/api/MenuAction.java index 0abe8c9b62..21f8aad0fc 100644 --- a/runelite-api/src/main/java/net/runelite/api/MenuAction.java +++ b/runelite-api/src/main/java/net/runelite/api/MenuAction.java @@ -269,6 +269,8 @@ public enum MenuAction */ UNKNOWN(-1); + public static final int MENU_ACTION_DEPRIORITIZE_OFFSET = 2000; + private static final Map map = new HashMap<>(); static diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/corp/CorpConfig.java b/runelite-client/src/main/java/net/runelite/client/plugins/corp/CorpConfig.java new file mode 100644 index 0000000000..81cf762b89 --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/plugins/corp/CorpConfig.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2018, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.client.plugins.corp; + +import net.runelite.client.config.Config; +import net.runelite.client.config.ConfigGroup; +import net.runelite.client.config.ConfigItem; + +@ConfigGroup("corp") +public interface CorpConfig extends Config +{ + @ConfigItem( + keyName = "leftClickCore", + name = "Left click walk on core", + description = "Prioritizes Walk here over Attack on the Dark energey core", + position = 1 + ) + default boolean leftClickCore() + { + return true; + } +} diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/corp/CorpPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/corp/CorpPlugin.java index 2dd3c069f9..5f2c43980c 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/corp/CorpPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/corp/CorpPlugin.java @@ -25,6 +25,7 @@ package net.runelite.client.plugins.corp; import com.google.common.eventbus.Subscribe; +import com.google.inject.Provides; import java.util.HashSet; import java.util.Set; import javax.inject.Inject; @@ -34,18 +35,23 @@ import net.runelite.api.Actor; import net.runelite.api.ChatMessageType; import net.runelite.api.Client; import net.runelite.api.GameState; +import net.runelite.api.MenuAction; +import static net.runelite.api.MenuAction.MENU_ACTION_DEPRIORITIZE_OFFSET; +import net.runelite.api.MenuEntry; import net.runelite.api.NPC; import net.runelite.api.NpcID; import net.runelite.api.Varbits; import net.runelite.api.events.GameStateChanged; import net.runelite.api.events.HitsplatApplied; import net.runelite.api.events.InteractingChanged; +import net.runelite.api.events.MenuEntryAdded; import net.runelite.api.events.NpcDespawned; import net.runelite.api.events.NpcSpawned; import net.runelite.client.chat.ChatColorType; import net.runelite.client.chat.ChatMessageBuilder; import net.runelite.client.chat.ChatMessageManager; import net.runelite.client.chat.QueuedMessage; +import net.runelite.client.config.ConfigManager; import net.runelite.client.plugins.Plugin; import net.runelite.client.plugins.PluginDescriptor; import net.runelite.client.ui.overlay.OverlayManager; @@ -57,6 +63,10 @@ import net.runelite.client.ui.overlay.OverlayManager; ) public class CorpPlugin extends Plugin { + private static final int NPC_SECTION_ACTION = MenuAction.NPC_SECOND_OPTION.getId(); + private static final String ATTACK = "Attack"; + private static final String DARK_ENERGY_CORE = "Dark energy core"; + @Getter(AccessLevel.PACKAGE) private NPC corp; @@ -86,6 +96,15 @@ public class CorpPlugin extends Plugin @Inject private CoreOverlay coreOverlay; + @Inject + private CorpConfig config; + + @Provides + CorpConfig getConfig(ConfigManager configManager) + { + return configManager.getConfig(CorpConfig.class); + } + @Override protected void startUp() throws Exception { @@ -202,4 +221,28 @@ public class CorpPlugin extends Plugin players.add(source); } + + @Subscribe + public void onMenuEntryAdded(MenuEntryAdded menuEntryAdded) + { + if (menuEntryAdded.getType() != NPC_SECTION_ACTION + || !config.leftClickCore() || !menuEntryAdded.getOption().equals(ATTACK)) + { + return; + } + + final int npcIndex = menuEntryAdded.getIdentifier(); + final NPC npc = client.getCachedNPCs()[npcIndex]; + if (npc == null || !npc.getName().equals(DARK_ENERGY_CORE)) + { + return; + } + + // since this is the menu entry add event, this is the last menu entry + MenuEntry[] menuEntries = client.getMenuEntries(); + MenuEntry menuEntry = menuEntries[menuEntries.length - 1]; + + menuEntry.setType(NPC_SECTION_ACTION + MENU_ACTION_DEPRIORITIZE_OFFSET); + client.setMenuEntries(menuEntries); + } }