<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Client0s</title>
    <description>The latest articles on DEV Community by Client0s (@client0s).</description>
    <link>https://dev.to/client0s</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4122415%2F4d8f5e85-1ab2-4c49-a35b-606a6609d79d.png</url>
      <title>DEV Community: Client0s</title>
      <link>https://dev.to/client0s</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/client0s"/>
    <language>en</language>
    <item>
      <title>Build a small OpenOSRS plugin in Java</title>
      <dc:creator>Client0s</dc:creator>
      <pubDate>Sat, 12 Sep 2026 22:56:37 +0000</pubDate>
      <link>https://dev.to/client0s/build-a-small-openosrs-plugin-in-java-4p2n</link>
      <guid>https://dev.to/client0s/build-a-small-openosrs-plugin-in-java-4p2n</guid>
      <description>&lt;p&gt;A small plugin is a good way to learn a desktop client's extension system. This example displays a chat message after login. It covers discovery, dependency injection, game events and packaging without automating gameplay.&lt;/p&gt;

&lt;p&gt;I maintain the OpenOSRS project at &lt;a href="https://github.com/OOSRS/OOSRS" rel="noopener noreferrer"&gt;OOSRS/OOSRS&lt;/a&gt;. It builds on the RuneLite/OpenOSRS ecosystem; the example below comes from our public &lt;a href="https://github.com/OOSRS/OOSRS-Plugins" rel="noopener noreferrer"&gt;example-plugin repository&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Build the example
&lt;/h2&gt;

&lt;p&gt;You need Git and JDK 11. The repository includes its Gradle wrapper, so you do not need a separate Gradle installation.&lt;/p&gt;

&lt;p&gt;On Linux or macOS:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/OOSRS/OOSRS-Plugins.git
&lt;span class="nb"&gt;cd &lt;/span&gt;OOSRS-Plugins
./gradlew :welcome-message:jar
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On Windows, use &lt;code&gt;gradlew.bat :welcome-message:jar&lt;/code&gt; from the repository folder.&lt;/p&gt;

&lt;p&gt;The output is &lt;code&gt;welcome-message/build/libs/welcome-message-1.0.0.jar&lt;/code&gt; for the current example version. The build reads &lt;code&gt;sdk.properties&lt;/code&gt;, downloads the pinned client SDK and checks its SHA-256. It uses that SDK at compile time; it does not bundle a second client into the plugin.&lt;/p&gt;

&lt;h2&gt;
  
  
  The plugin class
&lt;/h2&gt;

&lt;p&gt;Here is the Welcome example, with the formatting expanded for readability:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kn"&gt;package&lt;/span&gt; &lt;span class="nn"&gt;net.openosrs.examples.welcome&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;javax.inject.Inject&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;net.runelite.api.ChatMessageType&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;net.runelite.api.Client&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;net.runelite.api.GameState&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;net.runelite.api.events.GameStateChanged&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;net.runelite.client.eventbus.Subscribe&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;net.runelite.client.plugins.Plugin&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;net.runelite.client.plugins.PluginDescriptor&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;org.pf4j.Extension&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="nd"&gt;@Extension&lt;/span&gt;
&lt;span class="nd"&gt;@PluginDescriptor&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"OpenOSRS: Welcome"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;description&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Shows a welcome message when you log in"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;enabledByDefault&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;WelcomePlugin&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Plugin&lt;/span&gt;
&lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nd"&gt;@Inject&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;Client&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;boolean&lt;/span&gt; &lt;span class="n"&gt;greeted&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="nd"&gt;@Subscribe&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;onGameStateChanged&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;GameStateChanged&lt;/span&gt; &lt;span class="n"&gt;event&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;event&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getGameState&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="nc"&gt;GameState&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;LOGIN_SCREEN&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
        &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;greeted&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;

        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;event&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getGameState&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="nc"&gt;GameState&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;LOGGED_IN&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;greeted&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
        &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;addChatMessage&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
                &lt;span class="nc"&gt;ChatMessageType&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;GAMEMESSAGE&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
                &lt;span class="s"&gt;""&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
                &lt;span class="s"&gt;"Welcome to OpenOSRS. Your example plugin is running!"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
                &lt;span class="kc"&gt;null&lt;/span&gt;
            &lt;span class="o"&gt;);&lt;/span&gt;
            &lt;span class="n"&gt;greeted&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="nd"&gt;@Override&lt;/span&gt;
    &lt;span class="kd"&gt;protected&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;shutDown&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
    &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;greeted&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;@Extension&lt;/code&gt; lets PF4J discover the extension. &lt;code&gt;@PluginDescriptor&lt;/code&gt; provides the name and initial enabled state. Dependency injection supplies the client instance, while &lt;code&gt;@Subscribe&lt;/code&gt; registers the game-state handler.&lt;/p&gt;

&lt;p&gt;The boolean prevents repeated greetings until the login screen is reached. It also resets when the plugin stops. Because this example listens for a state change, enable it before logging in; enabling it while already logged in does not immediately generate a greeting.&lt;/p&gt;

&lt;h2&gt;
  
  
  The packaging details that matter
&lt;/h2&gt;

&lt;p&gt;Keep the build configuration from the example repository when starting out. It includes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A compile-only client SDK dependency.&lt;/li&gt;
&lt;li&gt;Compile-only PF4J plus its annotation processor.&lt;/li&gt;
&lt;li&gt;The generated &lt;code&gt;META-INF/extensions.idx&lt;/code&gt; discovery file.&lt;/li&gt;
&lt;li&gt;Manifest entries including &lt;code&gt;Plugin-Id&lt;/code&gt;, &lt;code&gt;Plugin-Version&lt;/code&gt;, &lt;code&gt;Plugin-Provider&lt;/code&gt; and &lt;code&gt;Plugin-Requires&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Bundling client classes into a plugin can produce classloader conflicts. Missing discovery metadata can leave a valid-looking JAR that the loader cannot discover. A normal Java compile alone does not establish that a plugin is packaged correctly.&lt;/p&gt;

&lt;p&gt;The manifest's plugin ID must match the ID in the repository catalog. Use your own unique ID for a new plugin, and keep the manifest and catalog release versions aligned.&lt;/p&gt;

&lt;h2&gt;
  
  
  Install through the GitHub repository feature
&lt;/h2&gt;

&lt;p&gt;To try the published example, open &lt;strong&gt;External Plugin Manager&lt;/strong&gt; in OpenOSRS. The examples repository is included by default. Install &lt;strong&gt;OpenOSRS: Welcome&lt;/strong&gt;, then enable it in the plugin list before logging in.&lt;/p&gt;

&lt;p&gt;If you removed the repository, choose &lt;strong&gt;Add new GitHub repository&lt;/strong&gt; and enter:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Owner: OOSRS
Repository: OOSRS-Plugins
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This installs the published release, not the JAR you just built locally. To distribute your own version, use your own public repository, upload the JAR as a release asset and add a root &lt;code&gt;plugins.json&lt;/code&gt; catalog. The &lt;a href="https://github.com/OOSRS/OOSRS-Plugins/blob/main/plugins.json" rel="noopener noreferrer"&gt;example catalog&lt;/a&gt; shows the complete structure, including the asset URL, version and SHA-512 checksum. Add that repository in the manager to install your release.&lt;/p&gt;

&lt;h2&gt;
  
  
  Keep game access on the right thread
&lt;/h2&gt;

&lt;p&gt;Read game state from game-thread events. If a Swing callback or worker needs to access it, schedule that work through &lt;code&gt;ClientThread.invoke(...)&lt;/code&gt;. Do not sleep in event handlers or block the Swing event thread. Check login state and handle missing players or unloaded interfaces.&lt;/p&gt;

&lt;p&gt;For overlays, collect a snapshot in the game event and render that snapshot. Register resources when the plugin starts and remove them in &lt;code&gt;shutDown()&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where to go next
&lt;/h2&gt;

&lt;p&gt;The same repository has two other small examples: &lt;strong&gt;Nearby NPCs&lt;/strong&gt;, which shows snapshot reads and overlay cleanup, and &lt;strong&gt;Inventory Monitor&lt;/strong&gt;, which detects a transition to a full inventory.&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://github.com/OOSRS/OOSRS/blob/main/docs/PLUGINS.md" rel="noopener noreferrer"&gt;plugin guide&lt;/a&gt; and &lt;a href="https://oosrs.github.io/OOSRS/" rel="noopener noreferrer"&gt;API documentation&lt;/a&gt; cover the next steps. For setup questions or sharing a plugin, our &lt;a href="https://discord.gg/KKPUeeqgn9" rel="noopener noreferrer"&gt;community Discord&lt;/a&gt; is open.&lt;/p&gt;

</description>
      <category>java</category>
      <category>opensource</category>
    </item>
  </channel>
</rss>
