Jump to content

Listener


Joseph

Recommended Posts

How did you create a listener if it wasn't a thread?

well i created a test script and had a method from the listener class loop within the onloop. But since it was a test and there wasnt anything else in the onloop. It was fine. But once i add it into my crafter, i noticed it will excute the listener, then execute the actual on loop. Which wasnt what i wanted. Then i started reading about threads, and i didnt know that when a thread starts it will execute the Run method in the class that implement runnable. Which i had So im guessing this is where i will need the loop, people were telling me about.

 

edit: i guess not lol -.-

Edited by josedpay
Link to comment
Share on other sites

package _test;

import java.util.Arrays;

import org.osbot.rs07.api.model.Item;
import org.osbot.rs07.api.util.ItemContainer;

public class ContainerListener implements Runnable {
	
	private final ItemContainer container;
	private Item[] cache;
	private boolean changed;
	
	public ContainerListener(ItemContainer container) {
	this.container = container;
	}
	
	public void setCache() {
		cache = container.getItems();
		changed = false;
	}
	
	@Override
	public void run() {
		changed = Arrays.equals(cache, container.getItems());
		try {
			Thread.sleep(1200);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
	
	public boolean getChanged() {
		return changed;
	}

}
ContainerListener inventoryListener = new ContainerListener(getInventory());

This most likely won't work as it is, but might inspire you or something ^^

Link to comment
Share on other sites

package _test;

import java.util.Arrays;

import org.osbot.rs07.api.model.Item;
import org.osbot.rs07.api.util.ItemContainer;

public class ContainerListener implements Runnable {
	
	private final ItemContainer container;
	private Item[] cache;
	private boolean changed;
	
	public ContainerListener(ItemContainer container) {
	this.container = container;
	}
	
	public void setCache() {
		cache = container.getItems();
		changed = false;
	}
	
	@Override
	public void run() {
		changed = Arrays.equals(cache, container.getItems());
		try {
			Thread.sleep(1200);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
	
	public boolean getChanged() {
		return changed;
	}

}
ContainerListener inventoryListener = new ContainerListener(getInventory());

This most likely won't work as it is, but might inspire you or something ^^

 

shouldnt the run method contain a loop?

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...