Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

Sign up now!
RuneMate will permanently shut down on August 7, 2026
due to events outside our control. You can continue using RuneMate until this date after which it will no longer be available. Thank you to everyone that contributed to RuneMate's success and to the community for the opportunity to serve you all these years.

  • Learn about RuneMate Vault and how its zero knowledge local encryption already protects your sensitive information.
  • Edit or delete your RuneMate account from your Account Settings.
  • All account upgrade subscriptions have been cancelled. No action required.

Resource How to setup and use an InventoryListener

Engineer
Joined
Jul 28, 2013
Messages
2,776
An InventoryListener is a utility used for monitoring inventory changes, such as for detecting when you catch a fish, get a log from cutting a tree, or set a log on the ground for starting a fire.

The first step to using it is to make your script implement InventoryListener
Code:
public final class ListenerTest extends LoopingScript implements InventoryListener {
After that, you need to ensure that you submit your InventoryListener to the event processor so it's notified when inventory related events happen
Code:
@Override
public void onStart() {
     getEventProcessor().addListener(this);
}
Finally, you need to override two methods in your script, one for handling when an item is added and one for handling when an item is removed.

Note: You need to override both even if you only need one.
Code:
@Override
public void onItemAdded(ItemEvent event) {
    System.out.println("Item Added: " + event.getItem() + " (" + event.getQuantityChange() + ")");
}

@Override
public void onItemRemoved(ItemEvent event) {
    System.out.println("Item Removed: " + event.getItem() + " (" + event.getQuantityChange() + ")");
}
 
Author of MaxiBots
Joined
Dec 3, 2013
Messages
7,468
is event.getItem() returning the items name? Nice job by the way :)
 
Engineer
Joined
Jul 28, 2013
Messages
2,776
is event.getItem() returning the items name? Nice job by the way :)
It's returning a SpriteItem instance, which you could use for highlighting the inventory spot, getting the id, getting the name, or anything else you can do with a SpriteItem.
 
Author of MaxiBots
Joined
Dec 3, 2013
Messages
7,468
It's returning a SpriteItem instance, which you could use for highlighting the inventory spot, getting the id, getting the name, or anything else you can do with a SpriteItem.
Ah okay, it's just the way you were printing it out made it look like it was a value not an object
 
Engineer
Joined
Jul 28, 2013
Messages
2,776
Ah okay, it's just the way you were printing it out made it look like it was a value not an object
Well SpriteItem has toString overridden so I figured it was easier.
 
Joined
Dec 10, 2014
Messages
3,377
An InventoryListener is a utility used for monitoring inventory changes, such as for detecting when you catch a fish, get a log from cutting a tree, or set a log on the ground for starting a fire.

The first step to using it is to make your script implement InventoryListener
Code:
public final class ListenerTest extends LoopingScript implements InventoryListener {
After that, you need to ensure that you submit your InventoryListener to the event processor so it's notified when inventory related events happen
Code:
@Override
public void onStart() {
     getEventProcessor().addListener(this);
}
Finally, you need to override two methods in your script, one for handling when an item is added and one for handling when an item is removed.

Note: You need to override both even if you only need one.
Code:
@Override
public void onItemAdded(ItemEvent event) {
    System.out.println("Item Added: " + event.getItem() + " (" + event.getQuantityChange() + ")");
}

@Override
public void onItemRemoved(ItemEvent event) {
    System.out.println("Item Removed: " + event.getItem() + " (" + event.getQuantityChange() + ")");
}
getEventProcessor() has been renamed getEventDispatcher() I assume?
 
Top