Class ShopOption

java.lang.Object
privbot.hooks.shop.ShopOption

public final class ShopOption extends Object
A single purchasable option read off a live shop-slot widget, e.g. "Buy 10" -> 10.

Options are never assumed to exist at a fixed action index — they are parsed from whatever Widget.getActions() actually returns, so a server offering Buy 100 works with no code change. label() preserves the exact live string so Widgets.interact(widget, label) can match it and derive the real action index.

Buy X and Buy All are deliberately not parsed: Buy X needs chatbox amount entry, and Buy All has no fixed quantity to reason about against a top-up target.

  • Method Details

    • label

      public String label()
      The exact action string as it appears on the widget — pass this to Widgets.interact.
    • amount

      public int amount()
      How many units this option buys per click. Always >= 1.
    • of

      public static ShopOption of(String label, int amount)
      An option built from a known quantity rather than parsed from a widget.

      Needed where the buy options are not readable off a widget at all. On Impact they exist only in the live right-click menu ('Buy-10 @lre@Guam leaf'), so the caller supplies the label the client will render and the quantity it stands for.

      Throws:
      IllegalArgumentException - when amount is not positive
    • parse

      public static List<ShopOption> parse(String[] actions)
      Parses a widget's live action array into purchasable options, largest amount first. Null entries, blanks, and non-purchase actions are skipped.
    • bestFor

      public static ShopOption bestFor(List<ShopOption> options, int remaining)
      Picks the largest option that does not exceed remaining. When every option is larger than remaining, returns the smallest one — overshooting slightly beats deadlocking on a shop whose smallest increment exceeds what is still needed.
      Returns:
      null when options is empty
    • toString

      public String toString()
      Overrides:
      toString in class Object