docs.dev

SDK Client Reference

Static accessors, NClient and the N* native interfaces, thread-affinity invariants, wrappers, config proxies, CLI options, events, and the Logger contract.

Covers the access contract every SDK consumer uses: dev.n3u.Static, the dev.n3u.api.N* native interfaces in base-api, the wrapper types in api (dev.n3u.data.wrappers), proxy-based configuration (dev.n3u.util.config), CLI parsing (dev.n3u.util.optionsparser), and the client console logger. Source of truth: docs/sdk-client-reference.md in the n3Client repository. For plugin authoring see External plugins; for per-package references see the sibling SDK pages.

Purpose and module boundary

  • base-api is the low-level contract module: renamed native client interfaces (dev.n3u.api.N*), static accessors and threading helpers (dev.n3u.Static, dev.n3u.Logger), packet reading/writing (dev.n3u.packets), client services (dev.n3u.services), config proxies, and shared data/events (dev.n3u.data, dev.n3u.events).
  • api is the high-level SDK module: fluent queries (dev.n3u.queries), per-interface APIs (dev.n3u.api.widgets, dev.n3u.api.game, dev.n3u.api.entities), handler builders and the Script DSL (dev.n3u.util.handler), pathfinding (dev.n3u.services.pathfinder), and wrappers around live game objects (dev.n3u.data.wrappers).

External code compiles against both as compileOnly artifacts (see External plugins); the launcher injects the implementation. You never implement NClient yourself — Static.getClient() returns the injected instance.

Thread affinity invariants

This is the single most important contract in the SDK. All game-state access belongs on the client thread.

ContextBehaviorSource
Static.invoke(Supplier)Runs inline if already on the client thread; otherwise dispatches to the RuneLite client thread and blocks on a CompletableFuture.join(), rethrowing supplier exceptionsbase-api/src/main/java/dev/n3u/Static.java:101-116
Static.invoke(Runnable)Same dispatch, no return valuebase-api/src/main/java/dev/n3u/Static.java:123-130
Static.invokeLater(...)Queue without blocking; the Supplier overload still blocks for its own valuebase-api/src/main/java/dev/n3u/Static.java:132-157
NClient.isClientThread()The predicate the helpers dispatch onbase-api/src/main/java/dev/n3u/api/NClient.java
NPlugin.loop()Submitted to a worker thread pool on every GameTick while the previous run is done; safe to sleep, not thread-safe — use Static.invoke for game-state operationsapi/src/main/java/dev/n3u/util/NPlugin.java:31-65
Delays.wait(ms)Throws RuntimeException if called on the client threadapi/src/main/java/dev/n3u/api/threaded/Delays.java (wait)
IScript.execute(Class)Throws IllegalStateException on the client thread, then runs its tick loop synchronously on the calling thread — call it from a worker thread you already own (e.g. NPlugin.loop())api/src/main/java/dev/n3u/util/handler/script/IScript.java

Rule of thumb: loop()/worker threads may sleep and call the high-level api module (its mutating entry points wrap their packets in Static.invoke themselves — e.g. NpcAPI.interact at api/src/main/java/dev/n3u/api/entities/NpcAPI.java:66-73); event listeners and anything touching raw Client state should wrap reads in Static.invoke. Blocking Static.invoke(Supplier) from the client thread deadlocks nothing only because it short-circuits inline — never call the blocking form from code that is already queued on the client thread behind other work.

dev.n3u.Static — access surface

From base-api/src/main/java/dev/n3u/Static.java:

MemberPurpose
RUNELITE_DIR, N_DIRClient storage roots (ClientPaths.RUNELITE, ClientPaths.CLIENT)
getClient()Generic-typed client instance (NClient/native Client depending on call site)
getClientClassLoader()Class loader of the injected client
getRuneLite()RuneLite wrapper instance
getInjector()Guice injector
getNConfig()Proxy instance of dev.n3u.util.ClientConfig (see below)
getCliArgs()N3ClientOptions populated by OptionsParser
isHeadless() / setHeadless(boolean)Headless mode toggle
invoke / invokeLaterThread-affinity helpers (table above)
post(Object)Post an event to the RuneLite event bus
resetForRecovery()INTERNAL: clears client/RuneLite/classloader references for restart recovery
set(Object, String)INTERNAL USE ONLY — bootstrap wiring for RL_CLIENT, RL, CLASSLOADER; throws IllegalArgumentException for unknown names
isRunningFromShadedJar()Manifest-based shaded-jar detection

Note Static.getClient() performs an unchecked cast to <N>; with compileOnly dependencies the type you request must exist at runtime in the client class loader.

dev.n3u.api.NClient — native interface surface

NClient (161 lines, base-api/src/main/java/dev/n3u/api/NClient.java) is the renamed native client contract. Public surface:

  • Packet pipeline: getPacketWriter(), newClientPacket(int id, int length), getPacketBufferNode(NClientPacket, NIsaacCipher) — see SDK Packets Reference.
  • Tick and state: getTickCount(), getServerRevision(), isClientThread().
  • Varps/varbits: setVarbit(int, int), getVarbitValue(int[], int), setVarbitValue(int[], int, int), getVarpValue(int).
  • Input: getMouseHandler(), getClientMouseLastPressedMillis(), setClientMouseLastPressedMillis(long).
  • Menu: invokeMenuAction(...) with 9- and 10-parameter overloads (in the 10-parameter form, worldView is the 8th parameter, followed by x and y).
  • Session/account fields: get/setDisplayName, get/setCharacterId, get/setSessionId, get/setRefreshToken, get/setAccessToken, setLoginIndex, setAccountTypeLegacy(), setAccountTypeJagex().
  • Sailing: getShipHeading(), setShipHeading(int).

Companion N* interfaces (base-api/src/main/java/dev/n3u/api/)

InterfaceNotable membersConsumed by
NPacketWriterOne typed send method per packet family: clickPacket(3), widgetActionPacket(4), widgetActionSubOpPacket(5), widgetDragPacket(6), resume*DialoguePacket, walkPacket(3), objectActionPacket(5), groundItemActionPacket(5), playerActionPacket(3), npcActionPacket(3), widgetOnWidgetPacket(6), widgetOnGroundItemPacket(7), chatPacket(2), itemActionPacket(3), itemOnItemPacket(4), itemOn*Packet, addNode(NPacketBufferNode); accessors getIsaacCipher, getServerPacket, getServerPacketBufferapi interaction APIs (NpcAPI, WidgetAPI, …), ClickManager
NPacketBuffer (extends NBuffer)Byte-array cursor (getArray/getOffset) plus the transformed write family (writeByte{,Add,Neg,Sub}, writeShort{,LE,Add,AddLE}, writeInt*, writeStringCp1252*)NPacketWriter.addNode pipeline
NPacketBufferNodegetPacketBuffer(), getClientPacket()packet construction
NClientPacket / NServerPacketgetId(), getLength()packet identification
NBuffergetArray(), getOffset(), writeByte*(4 variants), writeShort*(4), writeInt*(4), writeLengthByte, writeStringCp1252*buffer authors
NIsaacCipherMarker for the login cipher pairpacket encryption
NMouseHandlergetMouseX/Y(), get/setMouseLastPressedMillis()input spoofing
NItemCompositiongetGroundActions()item metadata
NObjectCompositiongetBlockAccessFlags()collision metadata
NGameEngine, NAccountType, NLanguagemarker interfaces (no members)type identity

Wrappers (api/src/main/java/dev/n3u/data/wrappers/)

Live game objects are surfaced as *Ex wrappers with differing contracts (declarations verified 2026-11-06):

  • abstractions/Entity (public interface Entity extends Locatable, Interactable, Identifiable, abstractions/Entity.java:5) is implemented by ActorEx (and its subclasses PlayerEx, NpcEx), TileItemEx, and TileObjectEx — these all expose interact(String...)/interact(int) (e.g. NpcEx.java:100-105).
  • ItemEx implements Interactable, Identifiable (ItemEx.java:21) — interactable, but not Locatable/Entity; use its parent container for location.
  • ItemContainerEx implements no interface and has no interact method (ItemContainerEx.java:15) — it is a container view, not an interactable.

Verified essentials: PlayerEx.getLocal() (PlayerEx.java:20), ActorEx.isIdle() (ActorEx.java:73). Wrappers are snapshots: obtain them on the client thread and re-query rather than caching across ticks.

Configuration — dev.n3u.util.config

  • NConfig is a marker interface with getInstance() (NConfig.java).
  • ConfigFactory.create(Class) builds a JDK dynamic proxy backed by ConfigProxyHandler, which maps getters (get/is/should prefixes) and single-argument setters onto a ConfigManager using the @ConfigKey annotation (base-api/src/main/java/dev/n3u/util/config/ConfigProxyHandler.java). Methods outside those shapes throw UnsupportedOperationException (ConfigProxyHandler.java:36).
  • @ConfigGroup("N3ClientOptions") on dev.n3u.util.ClientConfig names the storage group; keys include clickStrategy (default STATIC), clickPointX/Y (default -1), pathfinderImpl (default HYBRID_BFS), drawWalkerPath, mouseMovements, caching toggles (cachedRandomDat, cachedDeviceID, cachedBank) — see base-api/src/main/java/dev/n3u/util/ClientConfig.java.
  • ConfigManager (in dev.n3u.services) owns load/save: loadConfigFromFile, saveConfig, typed getters with defaults, setProperty/addProperty, reset() — detailed in docs/sdk-services-reference.md in the repository.

Declaring your own settings for a bundled/external plugin follows the same proxy pattern: extend NConfig, annotate accessors with @ConfigKey(value = "...", defaultValue = "..."), obtain instances via ConfigFactory.create(...).

CLI options — dev.n3u.util.optionsparser

OptionsParser.parse(String[]) binds boolean fields as -name flags and value fields as --name value, matched against fields annotated @CLIArgument(name, description) on the concrete options class (OptionsParser.java:18-74); a single-dash -name value is never bound — the flag passes through to the underlying RuneLite launch and the value is discarded (OptionsParser.java:44-54). Other unrecognized -flags pass through as well, and -help prints usage and exits. Static.getCliArgs() exposes the parsed N3ClientOptions.

Events (base-api/src/main/java/dev/n3u/events/)

PacketReceived, PacketSent, BankCacheChanged are posted through Static.post/the RuneLite bus, along with the login types dev.n3u.data.LoginResponse and dev.n3u.data.LoginMessage (posted by the login mixins, src/main/java/dev/n3u/mixins/NGameEngineMixin.java:53,59). Subscribe with RuneLite's @Subscribe from a Plugin as usual. The three dev.n3u.events types are the only n3-owned event classes in that package (verified by directory listing).

Logger — dev.n3u.Logger

Static logging into the embedded console window (base-api/src/main/java/dev/n3u/Logger.java): norm/info/warn/error with varargs overloads using SLF4J-style {} placeholders (the varargs path calls Logger.format at Logger.java:311, which delegates to LoggerFormatting.arrayFormat — base-api/src/main/java/dev/n3u/util/LoggerFormatting.java:8 defines DELIM_START = '{'; there is no % handling). The one % form is %e in error(Throwable, String), substituted via message.replace("%e", throwable.getMessage()) (Logger.java:297) — that is the form NPlugin uses. Also: error(Throwable), console(String), consoleOutput/consoleErrorOutput(head, body), per-level enable flags (setNormal/setInfo/setWarning/setError), setMaxMessages(int), and UI wiring (initLoggerUI, setLoggerVisible).

Worked example — thread-safe external plugin

import dev.n3u.Logger;
import dev.n3u.Static;
import dev.n3u.api.NClient;
import dev.n3u.api.threaded.Delays;
import dev.n3u.util.NPlugin;
import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.api.events.GameTick;
import net.runelite.client.eventbus.Subscribe;

@PluginDescriptor(name = "Tick counter", description = "Reads client state safely")
public class TickCounterPlugin extends NPlugin
{
    private int ticks;

    @Override
    public void loop() throws Exception   // worker thread; may sleep
    {
        NClient client = Static.getClient();
        int tick = Static.invoke(client::getTickCount); // blocks until client thread answers
        Logger.info("tick={}", tick);
        Delays.tick(); // sleep one game tick (forbidden on client thread)
    }

    @Subscribe
    public void onGameTick(GameTick tick)  // already on client thread
    {
        this.ticks = Static.getClient().getTickCount();
    }
}

Expected result: the console logs one line per completed loop; exceptions in loop() are logged by NPlugin._onGameTick and do not crash the client (NPlugin.java:43-59). Failure handling: Static.invoke surfaces supplier exceptions to the caller thread via the future; haltLoop(Runnable) cancels a running loop and runs the callback when it stops (NPlugin.java:71-89); cleanup is RuneLite plugin shutDown() plus dropping the loop future.

Tests and known limits

  • base-api has no automated tests (git ls-files "base-api/src/test/java" returns nothing — run 2026-11-06). The N* interfaces and Static are exercised only indirectly through the client runtime and the api module's tests.
  • The N* methods are injected mixins — their runtime behavior is bound by the gamepack mixin implementation, not by these interfaces. Source inspection documents the call surface only; live packet/login behavior is out of scope for this page.
  • Static.getClient() typing is caller-controlled and unchecked; a wrong type parameter fails at runtime, not compile time.

On this page