From 1d0bdf9615839882af0f83e70f47a42115e762fa Mon Sep 17 00:00:00 2001 From: lulwut Date: Fri, 17 May 2019 11:10:56 +1200 Subject: [PATCH 1/4] Updated Runecraft Plugin - Lava Rune Changes: - Added many menu swaps to make the process entirely left click - Overlay added notifying broken pouch - Issue: Easyscape has to be turned off or conflicts turned off to work with lava rune menuentry changes. --- .../client/plugins/runecraft/AbyssRifts.java | 10 +- .../plugins/runecraft/RunecraftConfig.java | 8 +- .../plugins/runecraft/RunecraftOverlay.java | 41 +++ .../plugins/runecraft/RunecraftPlugin.java | 237 ++++++++---------- 4 files changed, 151 insertions(+), 145 deletions(-) create mode 100644 runelite-client/src/main/java/net/runelite/client/plugins/runecraft/RunecraftOverlay.java diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/runecraft/AbyssRifts.java b/runelite-client/src/main/java/net/runelite/client/plugins/runecraft/AbyssRifts.java index 1ecedafe00..60f02d5080 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/runecraft/AbyssRifts.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/runecraft/AbyssRifts.java @@ -24,7 +24,7 @@ */ package net.runelite.client.plugins.runecraft; -import com.google.common.collect.ImmutableMap; +import java.util.HashMap; import java.util.Map; import lombok.Getter; import static net.runelite.api.ItemID.AIR_RUNE; @@ -64,18 +64,14 @@ public enum AbyssRifts @Getter private final int itemId; - private static final Map rifts; + private static final Map rifts = new HashMap<>(); static { - ImmutableMap.Builder builder = new ImmutableMap.Builder<>(); - for (AbyssRifts s : values()) { - builder.put(s.getObjectId(), s); + rifts.put(s.getObjectId(), s); } - - rifts = builder.build(); } AbyssRifts(int objectId, int itemId) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/runecraft/RunecraftConfig.java b/runelite-client/src/main/java/net/runelite/client/plugins/runecraft/RunecraftConfig.java index 38d6edc501..003a002139 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/runecraft/RunecraftConfig.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/runecraft/RunecraftConfig.java @@ -219,11 +219,11 @@ public interface RunecraftConfig extends Config return true; } @ConfigItem( - keyName = "opLavas", - name = "Op lavas", - description = "Op orange dorito mode - Only does something if you're wearing fire tiara" + keyName = "Lavas", + name = "Lavas", + description = "Swaps Ring of dueling menu entry depending on location, requires fire tiara or RC cape to be worn." ) - default boolean opLavas() + default boolean Lavas() { return true; } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/runecraft/RunecraftOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/runecraft/RunecraftOverlay.java new file mode 100644 index 0000000000..ae916e41e4 --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/plugins/runecraft/RunecraftOverlay.java @@ -0,0 +1,41 @@ +package net.runelite.client.plugins.runecraft; + +import net.runelite.api.Client; +import net.runelite.client.ui.overlay.Overlay; +import net.runelite.client.ui.overlay.OverlayPosition; +import net.runelite.client.ui.overlay.components.ComponentOrientation; +import net.runelite.client.ui.overlay.components.LineComponent; +import net.runelite.client.ui.overlay.components.PanelComponent; +import net.runelite.client.ui.overlay.components.TitleComponent; + +import javax.inject.Inject; +import java.awt.*; + +public class RunecraftOverlay extends Overlay { + private final RunecraftPlugin plugin; + private final Client client; + private final PanelComponent panel = new PanelComponent(); + + @Inject + RunecraftOverlay(RunecraftPlugin plugin, Client client) { + this.plugin = plugin; + this.client = client; + setPosition(OverlayPosition.CANVAS_TOP_RIGHT); + panel.setOrientation(ComponentOrientation.VERTICAL); + } + + public Dimension render(Graphics2D graphics) { + String text = "Pouch Has Degraded"; + panel.getChildren().clear(); + if(plugin.isDegradedPouchInInventory()) { + panel.getChildren().add(TitleComponent.builder() + .text("Pouch Has Degraded") + .color(Color.red) + .build()); + panel.setPreferredSize(new Dimension(graphics.getFontMetrics().stringWidth(text)+5, 5)); + return panel.render(graphics); + } else { + return null; + } + } +} diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/runecraft/RunecraftPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/runecraft/RunecraftPlugin.java index 475a6bf998..2ba6d8d593 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/runecraft/RunecraftPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/runecraft/RunecraftPlugin.java @@ -26,64 +26,58 @@ package net.runelite.client.plugins.runecraft; import com.google.common.collect.ImmutableList; import com.google.inject.Provides; + +import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.stream.Stream; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; import javax.inject.Inject; import lombok.AccessLevel; import lombok.Getter; -import net.runelite.api.ChatMessageType; -import net.runelite.api.Client; -import net.runelite.api.DecorativeObject; -import net.runelite.api.EquipmentInventorySlot; -import net.runelite.api.GameState; -import net.runelite.api.InventoryID; -import net.runelite.api.Item; -import net.runelite.api.ItemContainer; -import net.runelite.api.ItemID; -import net.runelite.api.MenuEntry; -import net.runelite.api.NPC; -import net.runelite.api.NpcID; -import net.runelite.api.events.ChatMessage; -import net.runelite.api.events.ConfigChanged; -import net.runelite.api.events.DecorativeObjectDespawned; -import net.runelite.api.events.DecorativeObjectSpawned; -import net.runelite.api.events.GameStateChanged; -import net.runelite.api.events.ItemContainerChanged; -import net.runelite.api.events.MenuEntryAdded; -import net.runelite.api.events.NpcDespawned; -import net.runelite.api.events.NpcSpawned; +import net.runelite.api.*; +import net.runelite.api.events.*; +import net.runelite.api.widgets.Widget; +import net.runelite.api.widgets.WidgetInfo; import net.runelite.client.Notifier; import net.runelite.client.config.ConfigManager; import net.runelite.client.eventbus.Subscribe; import net.runelite.client.plugins.Plugin; import net.runelite.client.plugins.PluginDescriptor; import net.runelite.client.ui.overlay.OverlayManager; -import static net.runelite.client.util.MenuUtil.swap; import net.runelite.client.util.Text; +import static net.runelite.client.util.MenuUtil.swap; + + + @PluginDescriptor( name = "Runecraft", description = "Show minimap icons and clickboxes for abyssal rifts", tags = {"abyssal", "minimap", "overlay", "rifts", "rc", "runecrafting"} ) -public class RunecraftPlugin extends Plugin -{ +public class RunecraftPlugin extends Plugin { + private static final int[] CASTLE_WARS = {9776}; + private static final int[] FIRE_ALTAR = {10315}; + + private static final String POUCH_DECAYED_NOTIFICATION_MESSAGE = "Your rune pouch has decayed."; private static final String POUCH_DECAYED_MESSAGE = "Your pouch has decayed through use."; private static final List DEGRADED_POUCHES = ImmutableList.of( - ItemID.MEDIUM_POUCH_5511, - ItemID.LARGE_POUCH_5513, - ItemID.GIANT_POUCH_5515 + ItemID.MEDIUM_POUCH_5511, + ItemID.LARGE_POUCH_5513, + ItemID.GIANT_POUCH_5515 ); private static final List POUCHES = ImmutableList.of( - ItemID.SMALL_POUCH, - ItemID.MEDIUM_POUCH, - ItemID.LARGE_POUCH, - ItemID.GIANT_POUCH + ItemID.SMALL_POUCH, + ItemID.MEDIUM_POUCH, + ItemID.LARGE_POUCH, + ItemID.GIANT_POUCH ); private boolean wearingTiara; + private boolean wearingCape; @Getter(AccessLevel.PACKAGE) private final Set abyssObjects = new HashSet<>(); @@ -103,6 +97,9 @@ public class RunecraftPlugin extends Plugin @Inject private AbyssOverlay abyssOverlay; + @Inject + private RunecraftOverlay runecraftOverlay; + @Inject private RunecraftConfig config; @@ -110,114 +107,108 @@ public class RunecraftPlugin extends Plugin private Notifier notifier; @Provides - RunecraftConfig getConfig(ConfigManager configManager) - { + RunecraftConfig getConfig(ConfigManager configManager) { return configManager.getConfig(RunecraftConfig.class); } @Override - protected void startUp() throws Exception - { + protected void startUp() throws Exception { overlayManager.add(abyssOverlay); abyssOverlay.updateConfig(); + overlayManager.add(runecraftOverlay); } @Override - protected void shutDown() throws Exception - { + protected void shutDown() throws Exception { overlayManager.remove(abyssOverlay); abyssObjects.clear(); darkMage = null; degradedPouchInInventory = false; + overlayManager.remove(runecraftOverlay); } @Subscribe - public void onConfigChanged(ConfigChanged event) - { + public void onConfigChanged(ConfigChanged event) { abyssOverlay.updateConfig(); } @Subscribe - public void onChatMessage(ChatMessage event) - { - if (event.getType() != ChatMessageType.GAMEMESSAGE) - { + public void onChatMessage(ChatMessage event) { + if (event.getType() != ChatMessageType.GAMEMESSAGE) { return; } - if (config.degradingNotification()) - { - if (event.getMessage().contains(POUCH_DECAYED_MESSAGE)) - { + if (config.degradingNotification()) { + if (event.getMessage().contains(POUCH_DECAYED_MESSAGE)) { notifier.notify(POUCH_DECAYED_NOTIFICATION_MESSAGE); } } } @Subscribe - public void onMenuEntryAdded(MenuEntryAdded entry) - { - if (!wearingTiara) - { + public void onMenuEntryAdded(MenuEntryAdded entry) { + if (client.getGameState() != GameState.LOGGED_IN) { + return; + } + + Widget loginScreenOne = client.getWidget(WidgetInfo.LOGIN_CLICK_TO_PLAY_SCREEN); + Widget loginScreenTwo = client.getWidget(WidgetInfo.LOGIN_CLICK_TO_PLAY_SCREEN_MESSAGE_OF_THE_DAY); + + if (loginScreenOne != null || loginScreenTwo != null) { return; } final String option = Text.removeTags(entry.getOption()).toLowerCase(); final String target = Text.removeTags(entry.getTarget()).toLowerCase(); - final int id = entry.getIdentifier(); - final int type = entry.getType(); - if (target.contains("pouch") && !target.startsWith("rune")) - { - if (option.equals("deposit-all") && type == 57 && id == 2) - { - swap(client, "fill", option, target); - swap(client, "cancel", option, "", target); - } - else if (option.equals("fill") && id != 9) - { - swap(client, "empty", option, target); + + Widget widgetBankTitleBar = client.getWidget(WidgetInfo.BANK_TITLE_BAR); + if (isEssencePouch(target)) { + if (widgetBankTitleBar == null || widgetBankTitleBar.isHidden()) { //swap pouches based on empty/full and in bank + swap(client, "Empty", option, target); + } else { + swap(client, "Fill", option, target); //Due to RuneLite issues the "Deposit" menutext will always show even though it is on fill } + } else if (target.contains("ring of dueling") && option.contains("withdraw")) { //withdraw-1 ring of dueling + swap(client, "withdraw-1", option, target); + } else if (target.contains("binding necklace") && option.contains("withdraw")) { //withdraw-1 binding necklace + swap(client, "withdraw-1", option, target); } - - else if (target.contains("ring of dueling") && option.contains("remove")) - { - if (target.contains("7") || target.contains("5") || target.contains("3") || target.contains("1")) - { + else if (target.contains("ring of dueling") && option.contains("remove")) { + if (client.getLocalPlayer().getWorldLocation().getRegionID() != 10315) { //changes duel ring teleport options based on location + swap(client, "duel arena", option, target); + } else if (client.getLocalPlayer().getWorldLocation().getRegionID() == 10315) { swap(client, "castle wars", option, target); } - else if (wearingBindingNeck()) - { - swap(client, "duel arena", option, target); + } + else if(target.contains("crafting cape") && option.contains("remove")) { //teleport for crafting cape + swap(client, "Teleport", option, target); + } else if(target.contains("max cape") && option.contains("remove")) { //teleport for max cape + swap(client, "Crafting Guild", option, target); } + else if (target.contains("altar") && option.contains("craft")) // Don't accidentally click the altar to craft + { + hide(option, target, true); + } else if (target.contains("pure")) // Don't accidentally use pure essence on altar + { + hide("use", target, true); + hide("drop", target, true); } - else if (target.contains("altar") && option.contains("craft")) // Don't accidentally click the altar to craft - { - hide(option, target, true); - } - else if (target.contains("pure") && option.contains("use")) // Don't accidentally use pure essence on altar - { - hide(option, target, true); - } } - private void hide(String option, String target, boolean contains) - { + private void hide(String option, String target, boolean contains) { final MenuEntry[] entries = client.getMenuEntries(); int index = searchIndex(entries, option, target, contains); - if (index < 0) - { + if (index < 0) { return; } MenuEntry[] newEntries = new MenuEntry[entries.length - 1]; int i2 = 0; - for (int i = 0; i < entries.length - 1; i++) - { - if (i == index) - { + for (int i = 0; i < entries.length - 1; i++) { + if (i == index) { continue; } @@ -228,21 +219,14 @@ public class RunecraftPlugin extends Plugin client.setMenuEntries(newEntries); } - private int searchIndex(MenuEntry[] entries, String option, String target) - { - return searchIndex(entries, option, target, false); - } - private int searchIndex(MenuEntry[] entries, String option, String target, boolean contains) - { - for (int i = entries.length - 1; i >= 0; i--) - { + private int searchIndex(MenuEntry[] entries, String option, String target, boolean contains) { + for (int i = entries.length - 1; i >= 0; i--) { MenuEntry entry = entries[i]; String entryOption = Text.removeTags(entry.getOption()).toLowerCase(); String entryTarget = Text.removeTags(entry.getTarget()).toLowerCase(); if (entryOption.contains(option.toLowerCase()) - && (entryTarget.equals(target) || (entryTarget.contains(target) && contains))) - { + && (entryTarget.equals(target) || (entryTarget.contains(target) && contains))) { return i; } } @@ -250,29 +234,29 @@ public class RunecraftPlugin extends Plugin return -1; } + + private boolean isEssencePouch(String target) { + return (target.equalsIgnoreCase("Small Pouch") || target.equalsIgnoreCase("Medium Pouch") || target.equalsIgnoreCase("Large Pouch") || target.equalsIgnoreCase("Giant Pouch")); + } + @Subscribe - public void onDecorativeObjectSpawned(DecorativeObjectSpawned event) - { + public void onDecorativeObjectSpawned(DecorativeObjectSpawned event) { DecorativeObject decorativeObject = event.getDecorativeObject(); - if (AbyssRifts.getRift(decorativeObject.getId()) != null) - { + if (AbyssRifts.getRift(decorativeObject.getId()) != null) { abyssObjects.add(decorativeObject); } } @Subscribe - public void onDecorativeObjectDespawned(DecorativeObjectDespawned event) - { + public void onDecorativeObjectDespawned(DecorativeObjectDespawned event) { DecorativeObject decorativeObject = event.getDecorativeObject(); abyssObjects.remove(decorativeObject); } @Subscribe - public void onGameStateChanged(GameStateChanged event) - { + public void onGameStateChanged(GameStateChanged event) { GameState gameState = event.getGameState(); - switch (gameState) - { + switch (gameState) { case LOADING: abyssObjects.clear(); break; @@ -285,48 +269,33 @@ public class RunecraftPlugin extends Plugin } @Subscribe - public void onItemContainerChanged(ItemContainerChanged event) - { - if (event.getItemContainer() == client.getItemContainer(InventoryID.INVENTORY)) - { + public void onItemContainerChanged(ItemContainerChanged event) { + if (event.getItemContainer() == client.getItemContainer(InventoryID.INVENTORY)) { - final Item[] items = event.getItemContainer().getItems(); - degradedPouchInInventory = Stream.of(items).anyMatch(i -> DEGRADED_POUCHES.contains(i.getId())); - } - else if (event.getItemContainer() == client.getItemContainer(InventoryID.EQUIPMENT)) - { final Item[] items = event.getItemContainer().getItems(); - wearingTiara = config.opLavas() && items[EquipmentInventorySlot.HEAD.getSlotIdx()].getId() == ItemID.FIRE_TIARA; + degradedPouchInInventory = Stream.of(items).anyMatch(i -> DEGRADED_POUCHES.contains(i.getId())); + } else if (event.getItemContainer() == client.getItemContainer(InventoryID.EQUIPMENT)) { + final Item[] items = event.getItemContainer().getItems(); + wearingTiara = config.Lavas() && items[EquipmentInventorySlot.HEAD.getSlotIdx()].getId() == ItemID.FIRE_TIARA; + wearingCape = config.Lavas() && items[EquipmentInventorySlot.CAPE.getSlotIdx()].getId() == ItemID.RUNECRAFT_CAPE || items[EquipmentInventorySlot.CAPE.getSlotIdx()].getId() == ItemID.RUNECRAFT_CAPET; + System.out.println("item changed"); } } @Subscribe - public void onNpcSpawned(NpcSpawned event) - { + public void onNpcSpawned(NpcSpawned event) { final NPC npc = event.getNpc(); - if (npc.getId() == NpcID.DARK_MAGE) - { + if (npc.getId() == NpcID.DARK_MAGE) { darkMage = npc; } } @Subscribe - public void onNpcDespawned(NpcDespawned event) - { + public void onNpcDespawned(NpcDespawned event) { final NPC npc = event.getNpc(); - if (npc == darkMage) - { + if (npc == darkMage) { darkMage = null; } } - private boolean wearingBindingNeck() - { - final ItemContainer worn = client.getItemContainer(InventoryID.EQUIPMENT); - if (worn == null) - { - return false; - } - return worn.getItems()[EquipmentInventorySlot.AMULET.getSlotIdx()].getId() == ItemID.BINDING_NECKLACE; - } } From 72f1d0ab6f8e770a3ab5e26d5e7298650a86c8bc Mon Sep 17 00:00:00 2001 From: lulwut Date: Fri, 17 May 2019 11:22:16 +1200 Subject: [PATCH 2/4] - Removed wildcard imports --- .../client/plugins/runecraft/AbyssRifts.java | 14 +- .../plugins/runecraft/RunecraftConfig.java | 1 + .../plugins/runecraft/RunecraftOverlay.java | 64 +++--- .../plugins/runecraft/RunecraftPlugin.java | 189 ++++++++++++------ 4 files changed, 162 insertions(+), 106 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/runecraft/AbyssRifts.java b/runelite-client/src/main/java/net/runelite/client/plugins/runecraft/AbyssRifts.java index 60f02d5080..e9546e3cee 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/runecraft/AbyssRifts.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/runecraft/AbyssRifts.java @@ -27,19 +27,7 @@ package net.runelite.client.plugins.runecraft; import java.util.HashMap; import java.util.Map; import lombok.Getter; -import static net.runelite.api.ItemID.AIR_RUNE; -import static net.runelite.api.ItemID.BLOOD_RUNE; -import static net.runelite.api.ItemID.BODY_RUNE; -import static net.runelite.api.ItemID.CHAOS_RUNE; -import static net.runelite.api.ItemID.COSMIC_RUNE; -import static net.runelite.api.ItemID.DEATH_RUNE; -import static net.runelite.api.ItemID.EARTH_RUNE; -import static net.runelite.api.ItemID.FIRE_RUNE; -import static net.runelite.api.ItemID.LAW_RUNE; -import static net.runelite.api.ItemID.MIND_RUNE; -import static net.runelite.api.ItemID.NATURE_RUNE; -import static net.runelite.api.ItemID.SOUL_RUNE; -import static net.runelite.api.ItemID.WATER_RUNE; +import static net.runelite.api.ItemID.*; import net.runelite.api.ObjectID; public enum AbyssRifts diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/runecraft/RunecraftConfig.java b/runelite-client/src/main/java/net/runelite/client/plugins/runecraft/RunecraftConfig.java index 003a002139..21bf0a3c42 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/runecraft/RunecraftConfig.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/runecraft/RunecraftConfig.java @@ -218,6 +218,7 @@ public interface RunecraftConfig extends Config { return true; } + @ConfigItem( keyName = "Lavas", name = "Lavas", diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/runecraft/RunecraftOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/runecraft/RunecraftOverlay.java index ae916e41e4..91a95bb885 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/runecraft/RunecraftOverlay.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/runecraft/RunecraftOverlay.java @@ -1,41 +1,47 @@ package net.runelite.client.plugins.runecraft; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Graphics2D; +import javax.inject.Inject; import net.runelite.api.Client; import net.runelite.client.ui.overlay.Overlay; import net.runelite.client.ui.overlay.OverlayPosition; import net.runelite.client.ui.overlay.components.ComponentOrientation; -import net.runelite.client.ui.overlay.components.LineComponent; import net.runelite.client.ui.overlay.components.PanelComponent; import net.runelite.client.ui.overlay.components.TitleComponent; -import javax.inject.Inject; -import java.awt.*; +public class RunecraftOverlay extends Overlay +{ + private final RunecraftPlugin plugin; + private final Client client; + private final PanelComponent panel = new PanelComponent(); -public class RunecraftOverlay extends Overlay { - private final RunecraftPlugin plugin; - private final Client client; - private final PanelComponent panel = new PanelComponent(); + @Inject + RunecraftOverlay(RunecraftPlugin plugin, Client client) + { + this.plugin = plugin; + this.client = client; + setPosition(OverlayPosition.CANVAS_TOP_RIGHT); + panel.setOrientation(ComponentOrientation.VERTICAL); + } - @Inject - RunecraftOverlay(RunecraftPlugin plugin, Client client) { - this.plugin = plugin; - this.client = client; - setPosition(OverlayPosition.CANVAS_TOP_RIGHT); - panel.setOrientation(ComponentOrientation.VERTICAL); - } - - public Dimension render(Graphics2D graphics) { - String text = "Pouch Has Degraded"; - panel.getChildren().clear(); - if(plugin.isDegradedPouchInInventory()) { - panel.getChildren().add(TitleComponent.builder() - .text("Pouch Has Degraded") - .color(Color.red) - .build()); - panel.setPreferredSize(new Dimension(graphics.getFontMetrics().stringWidth(text)+5, 5)); - return panel.render(graphics); - } else { - return null; - } - } + public Dimension render(Graphics2D graphics) + { + String text = "Pouch Has Degraded"; + panel.getChildren().clear(); + if (plugin.isDegradedPouchInInventory()) + { + panel.getChildren().add(TitleComponent.builder() + .text("Pouch Has Degraded") + .color(Color.red) + .build()); + panel.setPreferredSize(new Dimension(graphics.getFontMetrics().stringWidth(text) + 5, 5)); + return panel.render(graphics); + } + else + { + return null; + } + } } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/runecraft/RunecraftPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/runecraft/RunecraftPlugin.java index 2ba6d8d593..311945c64c 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/runecraft/RunecraftPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/runecraft/RunecraftPlugin.java @@ -26,19 +26,33 @@ package net.runelite.client.plugins.runecraft; import com.google.common.collect.ImmutableList; import com.google.inject.Provides; - -import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.stream.Stream; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; import javax.inject.Inject; import lombok.AccessLevel; import lombok.Getter; -import net.runelite.api.*; -import net.runelite.api.events.*; +import net.runelite.api.ChatMessageType; +import net.runelite.api.Client; +import net.runelite.api.DecorativeObject; +import net.runelite.api.EquipmentInventorySlot; +import net.runelite.api.GameState; +import net.runelite.api.InventoryID; +import net.runelite.api.Item; +import net.runelite.api.ItemID; +import net.runelite.api.MenuEntry; +import net.runelite.api.NPC; +import net.runelite.api.NpcID; +import net.runelite.api.events.ChatMessage; +import net.runelite.api.events.ConfigChanged; +import net.runelite.api.events.DecorativeObjectDespawned; +import net.runelite.api.events.DecorativeObjectSpawned; +import net.runelite.api.events.GameStateChanged; +import net.runelite.api.events.ItemContainerChanged; +import net.runelite.api.events.MenuEntryAdded; +import net.runelite.api.events.NpcDespawned; +import net.runelite.api.events.NpcSpawned; import net.runelite.api.widgets.Widget; import net.runelite.api.widgets.WidgetInfo; import net.runelite.client.Notifier; @@ -47,10 +61,8 @@ import net.runelite.client.eventbus.Subscribe; import net.runelite.client.plugins.Plugin; import net.runelite.client.plugins.PluginDescriptor; import net.runelite.client.ui.overlay.OverlayManager; -import net.runelite.client.util.Text; import static net.runelite.client.util.MenuUtil.swap; - - +import net.runelite.client.util.Text; @PluginDescriptor( @@ -58,7 +70,8 @@ import static net.runelite.client.util.MenuUtil.swap; description = "Show minimap icons and clickboxes for abyssal rifts", tags = {"abyssal", "minimap", "overlay", "rifts", "rc", "runecrafting"} ) -public class RunecraftPlugin extends Plugin { +public class RunecraftPlugin extends Plugin +{ private static final int[] CASTLE_WARS = {9776}; private static final int[] FIRE_ALTAR = {10315}; @@ -66,15 +79,15 @@ public class RunecraftPlugin extends Plugin { private static final String POUCH_DECAYED_NOTIFICATION_MESSAGE = "Your rune pouch has decayed."; private static final String POUCH_DECAYED_MESSAGE = "Your pouch has decayed through use."; private static final List DEGRADED_POUCHES = ImmutableList.of( - ItemID.MEDIUM_POUCH_5511, - ItemID.LARGE_POUCH_5513, - ItemID.GIANT_POUCH_5515 + ItemID.MEDIUM_POUCH_5511, + ItemID.LARGE_POUCH_5513, + ItemID.GIANT_POUCH_5515 ); private static final List POUCHES = ImmutableList.of( - ItemID.SMALL_POUCH, - ItemID.MEDIUM_POUCH, - ItemID.LARGE_POUCH, - ItemID.GIANT_POUCH + ItemID.SMALL_POUCH, + ItemID.MEDIUM_POUCH, + ItemID.LARGE_POUCH, + ItemID.GIANT_POUCH ); private boolean wearingTiara; private boolean wearingCape; @@ -107,19 +120,22 @@ public class RunecraftPlugin extends Plugin { private Notifier notifier; @Provides - RunecraftConfig getConfig(ConfigManager configManager) { + RunecraftConfig getConfig(ConfigManager configManager) + { return configManager.getConfig(RunecraftConfig.class); } @Override - protected void startUp() throws Exception { + protected void startUp() throws Exception + { overlayManager.add(abyssOverlay); abyssOverlay.updateConfig(); overlayManager.add(runecraftOverlay); } @Override - protected void shutDown() throws Exception { + protected void shutDown() throws Exception + { overlayManager.remove(abyssOverlay); abyssObjects.clear(); darkMage = null; @@ -128,33 +144,41 @@ public class RunecraftPlugin extends Plugin { } @Subscribe - public void onConfigChanged(ConfigChanged event) { + public void onConfigChanged(ConfigChanged event) + { abyssOverlay.updateConfig(); } @Subscribe - public void onChatMessage(ChatMessage event) { - if (event.getType() != ChatMessageType.GAMEMESSAGE) { + public void onChatMessage(ChatMessage event) + { + if (event.getType() != ChatMessageType.GAMEMESSAGE) + { return; } - if (config.degradingNotification()) { - if (event.getMessage().contains(POUCH_DECAYED_MESSAGE)) { + if (config.degradingNotification()) + { + if (event.getMessage().contains(POUCH_DECAYED_MESSAGE)) + { notifier.notify(POUCH_DECAYED_NOTIFICATION_MESSAGE); } } } @Subscribe - public void onMenuEntryAdded(MenuEntryAdded entry) { - if (client.getGameState() != GameState.LOGGED_IN) { + public void onMenuEntryAdded(MenuEntryAdded entry) + { + if (client.getGameState() != GameState.LOGGED_IN) + { return; } Widget loginScreenOne = client.getWidget(WidgetInfo.LOGIN_CLICK_TO_PLAY_SCREEN); Widget loginScreenTwo = client.getWidget(WidgetInfo.LOGIN_CLICK_TO_PLAY_SCREEN_MESSAGE_OF_THE_DAY); - if (loginScreenOne != null || loginScreenTwo != null) { + if (loginScreenOne != null || loginScreenTwo != null) + { return; } @@ -163,33 +187,49 @@ public class RunecraftPlugin extends Plugin { Widget widgetBankTitleBar = client.getWidget(WidgetInfo.BANK_TITLE_BAR); - if (isEssencePouch(target)) { - if (widgetBankTitleBar == null || widgetBankTitleBar.isHidden()) { //swap pouches based on empty/full and in bank + if (isEssencePouch(target)) + { + if (widgetBankTitleBar == null || widgetBankTitleBar.isHidden()) + { //swap pouches based on empty/full and in bank swap(client, "Empty", option, target); - } else { + } + else + { swap(client, "Fill", option, target); //Due to RuneLite issues the "Deposit" menutext will always show even though it is on fill } - } else if (target.contains("ring of dueling") && option.contains("withdraw")) { //withdraw-1 ring of dueling - swap(client, "withdraw-1", option, target); - } else if (target.contains("binding necklace") && option.contains("withdraw")) { //withdraw-1 binding necklace + } + else if (target.contains("ring of dueling") && option.contains("withdraw")) + { //withdraw-1 ring of dueling swap(client, "withdraw-1", option, target); } - else if (target.contains("ring of dueling") && option.contains("remove")) { - if (client.getLocalPlayer().getWorldLocation().getRegionID() != 10315) { //changes duel ring teleport options based on location + else if (target.contains("binding necklace") && option.contains("withdraw")) + { //withdraw-1 binding necklace + swap(client, "withdraw-1", option, target); + } + else if (target.contains("ring of dueling") && option.contains("remove")) + { + if (client.getLocalPlayer().getWorldLocation().getRegionID() != 10315) + { //changes duel ring teleport options based on location swap(client, "duel arena", option, target); - } else if (client.getLocalPlayer().getWorldLocation().getRegionID() == 10315) { + } + else if (client.getLocalPlayer().getWorldLocation().getRegionID() == 10315) + { swap(client, "castle wars", option, target); } } - else if(target.contains("crafting cape") && option.contains("remove")) { //teleport for crafting cape - swap(client, "Teleport", option, target); - } else if(target.contains("max cape") && option.contains("remove")) { //teleport for max cape - swap(client, "Crafting Guild", option, target); - } - else if (target.contains("altar") && option.contains("craft")) // Don't accidentally click the altar to craft + else if (target.contains("crafting cape") && option.contains("remove")) + { //teleport for crafting cape + swap(client, "Teleport", option, target); + } + else if (target.contains("max cape") && option.contains("remove")) + { //teleport for max cape + swap(client, "Crafting Guild", option, target); + } + else if (target.contains("altar") && option.contains("craft")) // Don't accidentally click the altar to craft { hide(option, target, true); - } else if (target.contains("pure")) // Don't accidentally use pure essence on altar + } + else if (target.contains("pure")) // Don't accidentally use pure essence on altar { hide("use", target, true); hide("drop", target, true); @@ -197,18 +237,22 @@ public class RunecraftPlugin extends Plugin { } - private void hide(String option, String target, boolean contains) { + private void hide(String option, String target, boolean contains) + { final MenuEntry[] entries = client.getMenuEntries(); int index = searchIndex(entries, option, target, contains); - if (index < 0) { + if (index < 0) + { return; } MenuEntry[] newEntries = new MenuEntry[entries.length - 1]; int i2 = 0; - for (int i = 0; i < entries.length - 1; i++) { - if (i == index) { + for (int i = 0; i < entries.length - 1; i++) + { + if (i == index) + { continue; } @@ -219,14 +263,17 @@ public class RunecraftPlugin extends Plugin { client.setMenuEntries(newEntries); } - private int searchIndex(MenuEntry[] entries, String option, String target, boolean contains) { - for (int i = entries.length - 1; i >= 0; i--) { + private int searchIndex(MenuEntry[] entries, String option, String target, boolean contains) + { + for (int i = entries.length - 1; i >= 0; i--) + { MenuEntry entry = entries[i]; String entryOption = Text.removeTags(entry.getOption()).toLowerCase(); String entryTarget = Text.removeTags(entry.getTarget()).toLowerCase(); if (entryOption.contains(option.toLowerCase()) - && (entryTarget.equals(target) || (entryTarget.contains(target) && contains))) { + && (entryTarget.equals(target) || (entryTarget.contains(target) && contains))) + { return i; } } @@ -235,28 +282,34 @@ public class RunecraftPlugin extends Plugin { } - private boolean isEssencePouch(String target) { + private boolean isEssencePouch(String target) + { return (target.equalsIgnoreCase("Small Pouch") || target.equalsIgnoreCase("Medium Pouch") || target.equalsIgnoreCase("Large Pouch") || target.equalsIgnoreCase("Giant Pouch")); } @Subscribe - public void onDecorativeObjectSpawned(DecorativeObjectSpawned event) { + public void onDecorativeObjectSpawned(DecorativeObjectSpawned event) + { DecorativeObject decorativeObject = event.getDecorativeObject(); - if (AbyssRifts.getRift(decorativeObject.getId()) != null) { + if (AbyssRifts.getRift(decorativeObject.getId()) != null) + { abyssObjects.add(decorativeObject); } } @Subscribe - public void onDecorativeObjectDespawned(DecorativeObjectDespawned event) { + public void onDecorativeObjectDespawned(DecorativeObjectDespawned event) + { DecorativeObject decorativeObject = event.getDecorativeObject(); abyssObjects.remove(decorativeObject); } @Subscribe - public void onGameStateChanged(GameStateChanged event) { + public void onGameStateChanged(GameStateChanged event) + { GameState gameState = event.getGameState(); - switch (gameState) { + switch (gameState) + { case LOADING: abyssObjects.clear(); break; @@ -269,12 +322,16 @@ public class RunecraftPlugin extends Plugin { } @Subscribe - public void onItemContainerChanged(ItemContainerChanged event) { - if (event.getItemContainer() == client.getItemContainer(InventoryID.INVENTORY)) { + public void onItemContainerChanged(ItemContainerChanged event) + { + if (event.getItemContainer() == client.getItemContainer(InventoryID.INVENTORY)) + { final Item[] items = event.getItemContainer().getItems(); degradedPouchInInventory = Stream.of(items).anyMatch(i -> DEGRADED_POUCHES.contains(i.getId())); - } else if (event.getItemContainer() == client.getItemContainer(InventoryID.EQUIPMENT)) { + } + else if (event.getItemContainer() == client.getItemContainer(InventoryID.EQUIPMENT)) + { final Item[] items = event.getItemContainer().getItems(); wearingTiara = config.Lavas() && items[EquipmentInventorySlot.HEAD.getSlotIdx()].getId() == ItemID.FIRE_TIARA; wearingCape = config.Lavas() && items[EquipmentInventorySlot.CAPE.getSlotIdx()].getId() == ItemID.RUNECRAFT_CAPE || items[EquipmentInventorySlot.CAPE.getSlotIdx()].getId() == ItemID.RUNECRAFT_CAPET; @@ -283,17 +340,21 @@ public class RunecraftPlugin extends Plugin { } @Subscribe - public void onNpcSpawned(NpcSpawned event) { + public void onNpcSpawned(NpcSpawned event) + { final NPC npc = event.getNpc(); - if (npc.getId() == NpcID.DARK_MAGE) { + if (npc.getId() == NpcID.DARK_MAGE) + { darkMage = npc; } } @Subscribe - public void onNpcDespawned(NpcDespawned event) { + public void onNpcDespawned(NpcDespawned event) + { final NPC npc = event.getNpc(); - if (npc == darkMage) { + if (npc == darkMage) + { darkMage = null; } } From 833e1523e867d83948a1fc79f216dff9cf7d6bbc Mon Sep 17 00:00:00 2001 From: lulwut Date: Fri, 17 May 2019 13:49:58 +1200 Subject: [PATCH 3/4] Changes made as per feedback. --- .../plugins/runecraft/RunecraftPlugin.java | 132 ++++++++---------- 1 file changed, 60 insertions(+), 72 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/runecraft/RunecraftPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/runecraft/RunecraftPlugin.java index 311945c64c..f0a154def4 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/runecraft/RunecraftPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/runecraft/RunecraftPlugin.java @@ -53,8 +53,6 @@ import net.runelite.api.events.ItemContainerChanged; import net.runelite.api.events.MenuEntryAdded; import net.runelite.api.events.NpcDespawned; import net.runelite.api.events.NpcSpawned; -import net.runelite.api.widgets.Widget; -import net.runelite.api.widgets.WidgetInfo; import net.runelite.client.Notifier; import net.runelite.client.config.ConfigManager; import net.runelite.client.eventbus.Subscribe; @@ -169,74 +167,68 @@ public class RunecraftPlugin extends Plugin @Subscribe public void onMenuEntryAdded(MenuEntryAdded entry) { - if (client.getGameState() != GameState.LOGGED_IN) + if (wearingCape || wearingTiara) { - return; - } + final String option = Text.removeTags(entry.getOption()).toLowerCase(); + final String target = Text.removeTags(entry.getTarget()).toLowerCase(); + final int id = entry.getIdentifier(); + final int type = entry.getType(); - Widget loginScreenOne = client.getWidget(WidgetInfo.LOGIN_CLICK_TO_PLAY_SCREEN); - Widget loginScreenTwo = client.getWidget(WidgetInfo.LOGIN_CLICK_TO_PLAY_SCREEN_MESSAGE_OF_THE_DAY); - - if (loginScreenOne != null || loginScreenTwo != null) - { - return; - } - - final String option = Text.removeTags(entry.getOption()).toLowerCase(); - final String target = Text.removeTags(entry.getTarget()).toLowerCase(); - - - Widget widgetBankTitleBar = client.getWidget(WidgetInfo.BANK_TITLE_BAR); - if (isEssencePouch(target)) - { - if (widgetBankTitleBar == null || widgetBankTitleBar.isHidden()) - { //swap pouches based on empty/full and in bank - swap(client, "Empty", option, target); - } - else + if (target.contains("pouch") && !target.startsWith("rune")) { - swap(client, "Fill", option, target); //Due to RuneLite issues the "Deposit" menutext will always show even though it is on fill + if (option.contains("deposit") && type == 57 && id == 2) //swap pouches based on empty/full and in ban + { + swap(client, "fill", option, target); + swap(client, "cancel", option, "", target); + } + else if (option.equals("fill") && id != 9) + { + swap(client, "empty", option, target); //Due to RuneLite issues the "Deposit" menutext will always show even though it is on fill + } } - } - else if (target.contains("ring of dueling") && option.contains("withdraw")) - { //withdraw-1 ring of dueling - swap(client, "withdraw-1", option, target); - } - else if (target.contains("binding necklace") && option.contains("withdraw")) - { //withdraw-1 binding necklace - swap(client, "withdraw-1", option, target); - } - else if (target.contains("ring of dueling") && option.contains("remove")) - { - if (client.getLocalPlayer().getWorldLocation().getRegionID() != 10315) - { //changes duel ring teleport options based on location - swap(client, "duel arena", option, target); - } - else if (client.getLocalPlayer().getWorldLocation().getRegionID() == 10315) - { - swap(client, "castle wars", option, target); - } - } - else if (target.contains("crafting cape") && option.contains("remove")) - { //teleport for crafting cape - swap(client, "Teleport", option, target); - } - else if (target.contains("max cape") && option.contains("remove")) - { //teleport for max cape - swap(client, "Crafting Guild", option, target); - } - else if (target.contains("altar") && option.contains("craft")) // Don't accidentally click the altar to craft - { - hide(option, target, true); - } - else if (target.contains("pure")) // Don't accidentally use pure essence on altar - { - hide("use", target, true); - hide("drop", target, true); - } - - } + if (target.contains("ring of dueling") && option.contains("withdraw"))//withdraw-1 ring of dueling + { + swap(client, "withdraw-1", option, target); + } + else if (target.contains("binding necklace") && option.contains("withdraw")) //withdraw-1 binding necklace + { + swap(client, "withdraw-1", option, target); + } + else if (target.contains("stamina") && option.contains("withdraw")) + { //withdraw-1 stam + swap(client, "withdraw-1", option, target); + } + else if (target.contains("ring of dueling") && option.contains("remove")) + { + if (client.getLocalPlayer().getWorldLocation().getRegionID() != 10315) + { //changes duel ring teleport options based on location + swap(client, "duel arena", option, target); + } + else if (client.getLocalPlayer().getWorldLocation().getRegionID() == 10315) + { + swap(client, "castle wars", option, target); + } + } + else if (target.contains("crafting cape") && option.contains("remove")) //teleport for crafting cape + { + swap(client, "Teleport", option, target); + } + else if (target.contains("max cape") && option.contains("remove")) //teleport for max cape + { + swap(client, "Crafting Guild", option, target); + } + else if (target.contains("altar") && option.contains("craft")) // Don't accidentally click the altar to craft + { + hide(option, target, true); + } + else if (target.contains("pure") && option.contains("use")) // Don't accidentally use pure essence on altar + { + hide("use", target, true); + hide("drop", target, true); + } + } + } private void hide(String option, String target, boolean contains) { final MenuEntry[] entries = client.getMenuEntries(); @@ -282,11 +274,6 @@ public class RunecraftPlugin extends Plugin } - private boolean isEssencePouch(String target) - { - return (target.equalsIgnoreCase("Small Pouch") || target.equalsIgnoreCase("Medium Pouch") || target.equalsIgnoreCase("Large Pouch") || target.equalsIgnoreCase("Giant Pouch")); - } - @Subscribe public void onDecorativeObjectSpawned(DecorativeObjectSpawned event) { @@ -334,8 +321,9 @@ public class RunecraftPlugin extends Plugin { final Item[] items = event.getItemContainer().getItems(); wearingTiara = config.Lavas() && items[EquipmentInventorySlot.HEAD.getSlotIdx()].getId() == ItemID.FIRE_TIARA; - wearingCape = config.Lavas() && items[EquipmentInventorySlot.CAPE.getSlotIdx()].getId() == ItemID.RUNECRAFT_CAPE || items[EquipmentInventorySlot.CAPE.getSlotIdx()].getId() == ItemID.RUNECRAFT_CAPET; - System.out.println("item changed"); + wearingCape = config.Lavas() && items[EquipmentInventorySlot.CAPE.getSlotIdx()].getId() == ItemID.RUNECRAFT_CAPE || config.Lavas() && items[EquipmentInventorySlot.CAPE.getSlotIdx()].getId() == ItemID.RUNECRAFT_CAPET || config.Lavas() && items[EquipmentInventorySlot.CAPE.getSlotIdx()].getId() == ItemID.MAX_CAPE_13342; + + System.out.println("item changed" + wearingCape); } } From e0610928a8c88d99e58dc335cf2c1dfcdb333b0d Mon Sep 17 00:00:00 2001 From: Tyler Bochard Date: Mon, 20 May 2019 14:43:06 -0400 Subject: [PATCH 4/4] Update RunecraftPlugin.java --- .../runelite/client/plugins/runecraft/RunecraftPlugin.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/runecraft/RunecraftPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/runecraft/RunecraftPlugin.java index 129a55a49d..f157e95c0a 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/runecraft/RunecraftPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/runecraft/RunecraftPlugin.java @@ -228,11 +228,11 @@ public class RunecraftPlugin extends Plugin } else if (option.equals("fill") && id != 9) { - swap(client, "empty", option, target); + swap(client, "empty", option, target); } } } - + private void hide(String option, String target, boolean contains) { final MenuEntry[] entries = client.getMenuEntries();