All pastes #262684 Raw Edit

Stuff

public java v1 · immutable
#262684 ·published 2006-11-30 20:16 UTC
rendered paste body
import java.awt.event.MouseEvent;import java.awt.event.MouseListener; import impsoft.ibot.Areas;import impsoft.ibot.methods.Menu;import impsoft.ibot.methods.NPCChat;import impsoft.ibot.methods.Script; public class MouseTest extends Script implements MouseListener {	public static double version = 0.0; 	public static String[] commands = new String[] { " " }; 	public static String author = " "; 	public String description = " "; 	public Thread scriptThread; 	public UpdaterThread updaterThread; 	public long lastClickTime = 0; 	int x = 0; 	int y = 0; 	public boolean doStart(String cmd, String[] args) {		return true;	} 	public void script() throws InterruptedException {		scriptThread = this;		updaterThread = new UpdaterThread();		updaterThread.start();		addListener();		while (true) {			if (System.currentTimeMillis() < lastClickTime + 1000) {				boolean found = false;				if (Areas.CHAT.contains(x, y)) {					NPCChat lastNPCChat = updaterThread.lastNPCChat;					if (lastNPCChat != null) {						for (int i = 0; i < lastNPCChat.options.length; i++) {							if (lastNPCChat.locations[i].contains(x, y)) {								log("----------------------------------");								log("[NPCChat] Rectangle ="										+ lastNPCChat.locations[i]);								log("[NPCChat] Color = "										+ lastNPCChat.colors[i]);								log("[NPCChat] Text = "										+ lastNPCChat.options[i]);								log("----------------------------------");								found = true;								break;							}						}					} else {						for (int i = 0; i < 5; i++) {							log("   getChat(" + i + ") = " + getChat(i));						}					}				} else {					Menu lastMenu = updaterThread.lastMenu;					if (lastMenu != null) {						if (lastMenu.location.contains(x, y)) {							for (int i = 0; i < lastMenu.options.length; i++) {								if (lastMenu.getRectange(i).contains(x, y)) {									log("-----------------------------------");									log("[Menu] Rectangle ="											+ lastMenu.getRectange(i));									log("[Menu] Text = " + lastMenu.options[i]);									log("----------------------------------");									found = true;									break;								}							}						}					}				}				if (!found)					log("x=" + x + " y=" + y + "  getRGB(x, y)=" + getRGB(x, y));				sleep(1000);			}			sleep(100);		} 	} 	private class UpdaterThread extends Thread {		public NPCChat lastNPCChat = null; 		public Menu lastMenu = null; 		@Override		public void run() {			try {				while (scriptThread.isAlive()) {					if (System.currentTimeMillis() > lastClickTime + 500) {						lastNPCChat = getNPCChat(400);					}					if (System.currentTimeMillis() > lastClickTime + 500) {						lastMenu = getMenu(Areas.ENTIRE, 400);					}					sleep(100);				}			} catch (InterruptedException e) {				// TODO Auto-generated catch block				e.printStackTrace();			} 		}	} 	public void addListener() {		theBot.theApplet.getComponentAt(1, 1).addMouseListener(this);	} 	public void removeListener() {		theBot.theApplet.getComponentAt(1, 1).removeMouseListener(this);	} 	public void mouseClicked(MouseEvent e) {		if (!scriptThread.isAlive()) {			removeListener();		} else {			x = e.getX();			y = e.getY();			lastClickTime = System.currentTimeMillis(); 		} 	} 	public void mouseEntered(MouseEvent e) {	} 	public void mouseExited(MouseEvent e) {	} 	public void mousePressed(MouseEvent e) {	} 	public void mouseReleased(MouseEvent e) {	} }