From 99b513a8c5b9a4e947789e7161174cbf2f4d7f18 Mon Sep 17 00:00:00 2001 From: Adam Date: Wed, 10 Apr 2019 19:17:11 -0400 Subject: [PATCH] api: remove Query api --- .../runelite/api/queries/BankItemQuery.java | 78 -------------- .../api/queries/EquipmentItemQuery.java | 102 ------------------ .../api/queries/InventoryWidgetItemQuery.java | 95 ---------------- .../runelite/api/queries/ShopItemQuery.java | 71 ------------ .../runelite/api/queries/WidgetItemQuery.java | 74 ------------- .../net/runelite/client/RuneLiteModule.java | 2 - .../net/runelite/client/util/QueryRunner.java | 43 -------- 7 files changed, 465 deletions(-) delete mode 100644 runelite-api/src/main/java/net/runelite/api/queries/BankItemQuery.java delete mode 100644 runelite-api/src/main/java/net/runelite/api/queries/EquipmentItemQuery.java delete mode 100644 runelite-api/src/main/java/net/runelite/api/queries/InventoryWidgetItemQuery.java delete mode 100644 runelite-api/src/main/java/net/runelite/api/queries/ShopItemQuery.java delete mode 100644 runelite-api/src/main/java/net/runelite/api/queries/WidgetItemQuery.java delete mode 100644 runelite-client/src/main/java/net/runelite/client/util/QueryRunner.java diff --git a/runelite-api/src/main/java/net/runelite/api/queries/BankItemQuery.java b/runelite-api/src/main/java/net/runelite/api/queries/BankItemQuery.java deleted file mode 100644 index b0131dce32..0000000000 --- a/runelite-api/src/main/java/net/runelite/api/queries/BankItemQuery.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (c) 2017, Devin French - * 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.api.queries; - -import net.runelite.api.Client; -import net.runelite.api.widgets.Widget; -import net.runelite.api.widgets.WidgetInfo; -import net.runelite.api.widgets.WidgetItem; - -import java.awt.Rectangle; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Objects; - -public class BankItemQuery extends WidgetItemQuery -{ - private static final int ITEM_EMPTY = 6512; - - @Override - public WidgetItem[] result(Client client) - { - Collection widgetItems = getBankItems(client); - if (widgetItems != null) - { - return widgetItems.stream() - .filter(Objects::nonNull) - .filter(predicate) - .toArray(WidgetItem[]::new); - } - return new WidgetItem[0]; - } - - private Collection getBankItems(Client client) - { - Collection widgetItems = new ArrayList<>(); - Widget bank = client.getWidget(WidgetInfo.BANK_ITEM_CONTAINER); - if (bank != null && !bank.isHidden()) - { - Widget[] children = bank.getDynamicChildren(); - for (int i = 0; i < children.length; i++) - { - Widget child = children[i]; - if (child.getItemId() == ITEM_EMPTY || child.isSelfHidden()) - { - continue; - } - // set bounds to same size as default inventory - Rectangle bounds = child.getBounds(); - bounds.setBounds(bounds.x - 1, bounds.y - 1, 32, 32); - // Index is set to 0 because the widget's index does not correlate to the order in the bank - widgetItems.add(new WidgetItem(child.getItemId(), child.getItemQuantity(), 0, bounds)); - } - } - return widgetItems; - } -} diff --git a/runelite-api/src/main/java/net/runelite/api/queries/EquipmentItemQuery.java b/runelite-api/src/main/java/net/runelite/api/queries/EquipmentItemQuery.java deleted file mode 100644 index 210fc1e8d0..0000000000 --- a/runelite-api/src/main/java/net/runelite/api/queries/EquipmentItemQuery.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright (c) 2017, Devin French - * 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.api.queries; - -import net.runelite.api.Client; -import net.runelite.api.widgets.Widget; -import net.runelite.api.widgets.WidgetInfo; -import net.runelite.api.widgets.WidgetItem; - -import java.awt.Rectangle; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Objects; - -public class EquipmentItemQuery extends WidgetItemQuery -{ - private static final WidgetInfo[] ALL_EQUIPMENT_WIDGET_INFOS = - { - WidgetInfo.EQUIPMENT_HELMET, - WidgetInfo.EQUIPMENT_CAPE, - WidgetInfo.EQUIPMENT_AMULET, - WidgetInfo.EQUIPMENT_WEAPON, - WidgetInfo.EQUIPMENT_BODY, - WidgetInfo.EQUIPMENT_SHIELD, - WidgetInfo.EQUIPMENT_LEGS, - WidgetInfo.EQUIPMENT_GLOVES, - WidgetInfo.EQUIPMENT_BOOTS, - WidgetInfo.EQUIPMENT_RING, - WidgetInfo.EQUIPMENT_AMMO, - }; - - private final Collection slots = new ArrayList<>(); - - public EquipmentItemQuery slotEquals(WidgetInfo... slotWidgetInfo) - { - slots.addAll(Arrays.asList(slotWidgetInfo)); - return this; - } - - @Override - public WidgetItem[] result(Client client) - { - Collection widgetItems = getEquippedItems(client); - if (widgetItems != null) - { - return widgetItems.stream() - .filter(Objects::nonNull) - .filter(predicate) - .toArray(WidgetItem[]::new); - } - return new WidgetItem[0]; - } - - private Collection getEquippedItems(Client client) - { - Collection widgetItems = new ArrayList<>(); - Widget equipment = client.getWidget(WidgetInfo.EQUIPMENT); - if (equipment != null && !equipment.isHidden()) - { - if (slots.isEmpty()) - { - slots.addAll(Arrays.asList(ALL_EQUIPMENT_WIDGET_INFOS)); - } - for (WidgetInfo slot : slots) - { - Widget parentWidget = client.getWidget(slot); - Widget itemWidget = parentWidget.getChild(1); - // Check if background icon is hidden. if hidden, item is equipped. - boolean equipped = parentWidget.getChild(2).isSelfHidden(); - // set bounds to same size as default inventory - Rectangle bounds = itemWidget.getBounds(); - bounds.setBounds(bounds.x - 1, bounds.y - 1, 32, 32); - // Index is set to 0 because there is no set in stone order of equipment slots - widgetItems.add(new WidgetItem(equipped ? itemWidget.getItemId() : -1, itemWidget.getItemQuantity(), 0, bounds)); - } - } - return widgetItems; - } -} diff --git a/runelite-api/src/main/java/net/runelite/api/queries/InventoryWidgetItemQuery.java b/runelite-api/src/main/java/net/runelite/api/queries/InventoryWidgetItemQuery.java deleted file mode 100644 index 1872eeed65..0000000000 --- a/runelite-api/src/main/java/net/runelite/api/queries/InventoryWidgetItemQuery.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (c) 2017, Devin French - * 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.api.queries; - -import net.runelite.api.Client; -import net.runelite.api.widgets.Widget; -import net.runelite.api.widgets.WidgetInfo; -import net.runelite.api.widgets.WidgetItem; - -import java.awt.Rectangle; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Objects; - -public class InventoryWidgetItemQuery extends WidgetItemQuery -{ - private static final WidgetInfo[] INVENTORY_WIDGET_INFOS = - { - WidgetInfo.DEPOSIT_BOX_INVENTORY_ITEMS_CONTAINER, - WidgetInfo.BANK_INVENTORY_ITEMS_CONTAINER, - WidgetInfo.SHOP_INVENTORY_ITEMS_CONTAINER, - WidgetInfo.GRAND_EXCHANGE_INVENTORY_ITEMS_CONTAINER, - WidgetInfo.GUIDE_PRICES_INVENTORY_ITEMS_CONTAINER, - WidgetInfo.EQUIPMENT_INVENTORY_ITEMS_CONTAINER, - WidgetInfo.INVENTORY - }; - - @Override - public WidgetItem[] result(Client client) - { - Collection widgetItems = getInventoryItems(client); - if (widgetItems != null) - { - return widgetItems.stream() - .filter(Objects::nonNull) - .filter(predicate) - .toArray(WidgetItem[]::new); - } - return new WidgetItem[0]; - } - - private Collection getInventoryItems(Client client) - { - Collection widgetItems = new ArrayList<>(); - for (WidgetInfo widgetInfo : INVENTORY_WIDGET_INFOS) - { - Widget inventory = client.getWidget(widgetInfo); - if (inventory == null || inventory.isHidden()) - { - continue; - } - if (widgetInfo == WidgetInfo.INVENTORY) - { - widgetItems.addAll(inventory.getWidgetItems()); - break; - } - else - { - Widget[] children = inventory.getDynamicChildren(); - for (int i = 0; i < children.length; i++) - { - Widget child = children[i]; - // set bounds to same size as default inventory - Rectangle bounds = child.getBounds(); - bounds.setBounds(bounds.x - 1, bounds.y - 1, 32, 32); - widgetItems.add(new WidgetItem(child.getItemId(), child.getItemQuantity(), i, bounds)); - } - break; - } - } - return widgetItems; - } -} diff --git a/runelite-api/src/main/java/net/runelite/api/queries/ShopItemQuery.java b/runelite-api/src/main/java/net/runelite/api/queries/ShopItemQuery.java deleted file mode 100644 index cd037f0a28..0000000000 --- a/runelite-api/src/main/java/net/runelite/api/queries/ShopItemQuery.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (c) 2017, Devin French - * 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.api.queries; - -import net.runelite.api.Client; -import net.runelite.api.widgets.Widget; -import net.runelite.api.widgets.WidgetInfo; -import net.runelite.api.widgets.WidgetItem; - -import java.awt.Rectangle; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Objects; - -public class ShopItemQuery extends WidgetItemQuery -{ - @Override - public WidgetItem[] result(Client client) - { - Collection widgetItems = getShopItems(client); - if (widgetItems != null) - { - return widgetItems.stream() - .filter(Objects::nonNull) - .filter(predicate) - .toArray(WidgetItem[]::new); - } - return new WidgetItem[0]; - } - - private Collection getShopItems(Client client) - { - Collection widgetItems = new ArrayList<>(); - Widget shop = client.getWidget(WidgetInfo.SHOP_ITEMS_CONTAINER); - if (shop != null && !shop.isHidden()) - { - Widget[] children = shop.getDynamicChildren(); - for (int i = 1; i < children.length; i++) - { - Widget child = children[i]; - // set bounds to same size as default inventory - Rectangle bounds = child.getBounds(); - bounds.setBounds(bounds.x - 1, bounds.y - 1, 32, 32); - widgetItems.add(new WidgetItem(child.getItemId(), child.getItemQuantity(), i - 1, bounds)); - } - } - return widgetItems; - } -} diff --git a/runelite-api/src/main/java/net/runelite/api/queries/WidgetItemQuery.java b/runelite-api/src/main/java/net/runelite/api/queries/WidgetItemQuery.java deleted file mode 100644 index 9a71a9bf3c..0000000000 --- a/runelite-api/src/main/java/net/runelite/api/queries/WidgetItemQuery.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (c) 2017, Devin French - * 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.api.queries; - -import net.runelite.api.Client; -import net.runelite.api.Query; -import net.runelite.api.widgets.WidgetItem; - -public abstract class WidgetItemQuery extends Query -{ - - public WidgetItemQuery idEquals(int... ids) - { - predicate = and(item -> - { - for (int id : ids) - { - if (item.getId() == id) - { - return true; - } - } - return false; - }); - return this; - } - - public WidgetItemQuery indexEquals(int... indexes) - { - predicate = and(item -> - { - for (int index : indexes) - { - if (item.getIndex() == index) - { - return true; - } - } - return false; - }); - return this; - } - - public WidgetItemQuery quantityEquals(int quantity) - { - predicate = and(item -> item.getQuantity() == quantity); - return this; - } - - @Override - public abstract WidgetItem[] result(Client client); -} diff --git a/runelite-client/src/main/java/net/runelite/client/RuneLiteModule.java b/runelite-client/src/main/java/net/runelite/client/RuneLiteModule.java index 20384bffe8..af5e7e2631 100644 --- a/runelite-client/src/main/java/net/runelite/client/RuneLiteModule.java +++ b/runelite-client/src/main/java/net/runelite/client/RuneLiteModule.java @@ -50,7 +50,6 @@ import net.runelite.client.rs.ClientUpdateCheckMode; import net.runelite.client.task.Scheduler; import net.runelite.client.util.DeferredEventBus; import net.runelite.client.util.ExecutorServiceExceptionLogger; -import net.runelite.client.util.QueryRunner; import net.runelite.http.api.RuneLiteAPI; import okhttp3.OkHttpClient; import org.slf4j.Logger; @@ -75,7 +74,6 @@ public class RuneLiteModule extends AbstractModule bindConstant().annotatedWith(Names.named("developerMode")).to(developerMode); bind(ScheduledExecutorService.class).toInstance(new ExecutorServiceExceptionLogger(Executors.newSingleThreadScheduledExecutor())); bind(OkHttpClient.class).toInstance(RuneLiteAPI.CLIENT); - bind(QueryRunner.class); bind(MenuManager.class); bind(ChatMessageManager.class); bind(ItemManager.class); diff --git a/runelite-client/src/main/java/net/runelite/client/util/QueryRunner.java b/runelite-client/src/main/java/net/runelite/client/util/QueryRunner.java deleted file mode 100644 index 0f34fc5448..0000000000 --- a/runelite-client/src/main/java/net/runelite/client/util/QueryRunner.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2017, Tomas Slusny - * 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.util; - -import javax.inject.Inject; -import javax.inject.Singleton; -import net.runelite.api.Client; -import net.runelite.api.Query; - -@Singleton -public class QueryRunner -{ - @Inject - private Client client; - - @SuppressWarnings("unchecked") - public T[] runQuery(Query query) - { - return (T[]) query.result(client); - } -} \ No newline at end of file