- Thread Author
- #1
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
After that, you need to ensure that you submit your InventoryListener to the event processor so it's notified when inventory related events happen
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.
The first step to using it is to make your script implement InventoryListener
Code:
public final class ListenerTest extends LoopingScript implements InventoryListener {
Code:
@Override
public void onStart() {
getEventProcessor().addListener(this);
}
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() + ")");
}