Class PlayerPackets


  • public class PlayerPackets
    extends java.lang.Object
    A high-level utility class for sending packets related to Player interactions to the game server.

    This class handles actions like right-clicking other players (e.g., Follow, Trade) and "use-on" actions (e.g., using an item on a player). It abstracts the low-level packet construction and uses client data to determine the correct action index.

    • Constructor Summary

      Constructors 
      Constructor Description
      PlayerPackets()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void queuePlayerAction​(int actionFieldNo, int playerIndex, boolean ctrlDown)
      Queues the low-level packet to perform a generic action click on another player.
      void queuePlayerAction​(net.runelite.api.Player player, java.lang.String... actionlist)
      Queues a player action by matching a human-readable action string (e.g., "Attack", "Trade", "Follow").
      void queueWidgetOnPlayer​(int playerIndex, int sourceItemId, int sourceSlot, int sourceWidgetId, boolean ctrlDown)
      Queues the raw packet for using a widget (typically an item) on another player.
      void queueWidgetOnPlayer​(net.runelite.api.Player player, net.runelite.api.widgets.Widget widget)
      Queues the packet for using a specific Widget (or item it represents) on a target Player.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • PlayerPackets

        public PlayerPackets()
    • Method Detail

      • queuePlayerAction

        public void queuePlayerAction​(int actionFieldNo,
                                      int playerIndex,
                                      boolean ctrlDown)
        Queues the low-level packet to perform a generic action click on another player.

        This method sends one of the OPPLAYER packets (e.g., OPPLAYER1 through OPPLAYER10), where the action is determined by the actionFieldNo (which corresponds to a Player Option).

        Parameters:
        actionFieldNo - The 1-based index of the action to execute (1-10).
        playerIndex - The server index/ID of the target player.
        ctrlDown - If true, indicates the control key was held down.
      • queuePlayerAction

        public void queuePlayerAction​(net.runelite.api.Player player,
                                      java.lang.String... actionlist)
        Queues a player action by matching a human-readable action string (e.g., "Attack", "Trade", "Follow").

        This is a high-level convenience method that checks the client's current **Player Options** (the text that appears on the right-click menu) for a matching action, finds the corresponding action number (1-10), and sends the correct packet.

        Parameters:
        player - The target Player object to interact with.
        actionlist - A varargs list of action strings to search for (case-insensitive).
      • queueWidgetOnPlayer

        public void queueWidgetOnPlayer​(int playerIndex,
                                        int sourceItemId,
                                        int sourceSlot,
                                        int sourceWidgetId,
                                        boolean ctrlDown)
        Queues the raw packet for using a widget (typically an item) on another player.

        This method sends the OPPLAYERT (Use Widget on Player) packet, which contains the details of the source item/widget and the target player.

        Parameters:
        playerIndex - The server index/ID of the target player.
        sourceItemId - The ID of the item being used.
        sourceSlot - The slot index of the item being used (e.g., inventory slot).
        sourceWidgetId - The ID of the parent widget containing the item (e.g., inventory widget ID).
        ctrlDown - If true, indicates the control key was held down.
      • queueWidgetOnPlayer

        public void queueWidgetOnPlayer​(net.runelite.api.Player player,
                                        net.runelite.api.widgets.Widget widget)
        Queues the packet for using a specific Widget (or item it represents) on a target Player.

        This is a convenience method that extracts the necessary item and widget details from the provided Widget object and calls the raw queueWidgetOnPlayer method.

        Parameters:
        player - The target Player object.
        widget - The source Widget containing the item or action to be used on the player.