Class ComponentQuery

java.lang.Object
com.botwithus.bot.api.component.ComponentQuery

public final class ComponentQuery extends Object
Fluent, RPC-backed query over an interface subtree. Modeled on WorldMapElements.Query: the first terminal materializes the subtree in a single get_interface_tree round-trip, then all filters run client-side over the flattened node list. The fetched tree is cached, so chaining several terminals on one query costs one RPC.
ComponentNode coins = api.components().in(Interfaces.BACKPACK)
        .withType(ComponentType.MODEL)
        .withItemId(995)
        .first();
  • Method Details

    • filter

      public ComponentQuery filter(Predicate<ComponentNode> predicate)
      Adds a predicate; multiple calls AND together.
    • withId

      public ComponentQuery withId(int componentId)
      Filter by component id within the interface.
    • withGameval

      public ComponentQuery withGameval(String... gamevals)
      Filter by gameval symbolic name, e.g. "BANK__BANK_INV_BUTTON". Pass several to match any of them.

      Matches on the whole (interfaceId, componentId) pair a gameval encodes, not just the component half — a materialized tree is cross-mount aware and can carry nodes from more than one interface, so matching the component id alone would collide across mounts.

      Names are resolved once when the filter is added. A name that does not resolve narrows the query to nothing and logs a warning — a stale name must not silently widen the result set.

      ComponentNode inv = api.components().in("BANK")
              .withGameval("BANK__BANK_INV_BUTTON")
              .visible()
              .first();
      
    • withType

      public ComponentQuery withType(ComponentType type)
      Filter to a single semantic category.
    • ofType

      public ComponentQuery ofType(ComponentType... types)
      Filter to any of the given categories.
    • withText

      public ComponentQuery withText(String text)
      Filter by exact label text (case-insensitive).
    • containingText

      public ComponentQuery containingText(String needle)
      Filter by label substring (case-insensitive).
    • textMatching

      public ComponentQuery textMatching(String regex)
      Filter by label regex (full match against the label).
    • withSpriteId

      public ComponentQuery withSpriteId(int spriteId)
      Filter by primary sprite id.
    • withItemId

      public ComponentQuery withItemId(int itemId)
      Filter by displayed item id (ModelComponent).
    • visible

      public ComponentQuery visible()
      Keep only visible components (treats unsupported-hidden as visible).
    • hidden

      public ComponentQuery hidden()
      Keep only components the producer reported hidden.
    • limit

      public ComponentQuery limit(int max)
      Cap the number of results.
    • all

      public List<ComponentNode> all()
      All matching nodes, in breadth-first tree order.
    • results

      public List<ComponentNode> results()
      Alias for all().
    • first

      public ComponentNode first()
      First matching node in tree order, or null.
    • findFirst

      public Optional<ComponentNode> findFirst()
      First matching node as an Optional.
    • count

      public int count()
    • exists

      public boolean exists()
    • stream

      public Stream<ComponentNode> stream()
      Stream over the materialized result list (filter + limit already applied).
    • tree

      public ComponentTree tree()
      The materialized subtree (one fetch, cached for this query).
    • root

      public ComponentNode root()
      Root of the materialized subtree, or null when it didn't resolve.