Skip to content

Commit

Permalink
start ext
Browse files Browse the repository at this point in the history
This adds some basic kotlin ext functionality to various api members such as NPC, TileObject, etc to allow for interactions directly from them as opposed to calling the static functions in Ethans and passing the member as a paramater.

This is how we will modify/extend runelite api instead of direct changes to maintain api integrity
  • Loading branch information
zeruth committed Dec 30, 2023
1 parent 681cfc2 commit d43683d
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 1 deletion.
10 changes: 10 additions & 0 deletions runelite-client/src/main/java/hotlite/ext/NPCExt.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package hotlite.ext

import com.example.InteractionApi.NPCInteraction
import net.runelite.api.NPC

object NPCExt {
fun NPC.interact(vararg actions: String) {
NPCInteraction.interact(this, *actions)
}
}
10 changes: 10 additions & 0 deletions runelite-client/src/main/java/hotlite/ext/PlayerExt.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package hotlite.ext

import com.example.InteractionApi.PlayerInteractionHelper
import net.runelite.api.Player

object PlayerExt {
fun Player.interact(vararg actions: String) {
PlayerInteractionHelper.interact(this, *actions)
}
}
14 changes: 14 additions & 0 deletions runelite-client/src/main/java/hotlite/ext/PrayerExt.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package hotlite.ext

import com.example.InteractionApi.PrayerInteraction
import net.runelite.api.Prayer

object PrayerExt {
fun Prayer.toggle() {
PrayerInteraction.togglePrayer(this)
}

fun Prayer.setEnabled(enabled: Boolean) {
PrayerInteraction.setPrayerState(this, enabled)
}
}
10 changes: 10 additions & 0 deletions runelite-client/src/main/java/hotlite/ext/TileObjectExt.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package hotlite.ext

import com.example.InteractionApi.TileObjectInteraction
import net.runelite.api.TileObject

object TileObjectExt {
fun TileObject.interact(vararg actions: String) {
TileObjectInteraction.interact(this, *actions)
}
}
10 changes: 10 additions & 0 deletions runelite-client/src/main/java/hotlite/ext/WidgetExt.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package hotlite.ext

import com.example.InteractionApi.InventoryInteraction
import net.runelite.api.widgets.Widget

object WidgetExt {
fun Widget.useItem(vararg actions: String) {
InventoryInteraction.useItem(this, *actions)
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package hotlite.plugins.example

import com.google.inject.Inject
import com.google.inject.Provides
import hotlite.ext.NPCExt.interact
import net.runelite.api.events.GameTick
import net.runelite.api.events.NpcSpawned
import net.runelite.client.config.ConfigManager
import net.runelite.client.eventbus.Subscribe
import net.runelite.client.plugins.Plugin
Expand All @@ -20,6 +21,13 @@ class ExamplePlugin : Plugin() {
println("Game Tick")
}

@Subscribe
fun onNPCSpawned(npcSpawned: NpcSpawned) {
when (npcSpawned.npc.name) {
"impossible" -> npcSpawned.npc.interact("something")
}
}

@Provides
fun getConfig(configManager: ConfigManager): ExampleConfig {
return configManager.getConfig(ExampleConfig::class.java)
Expand Down

0 comments on commit d43683d

Please sign in to comment.