TRiLeZ
2010-09-29 20:29:52
I noticed that there was a script editor that came with the bot. So, I looked at it and it looked exactly like my bot's script editor. I also when through the GUI and scripts of the bot and I noticed that it looked exactly like RSBot. So, I extracted the bot's main jar file only to find the org.rsbot package. So, this bot is clearly a rip of other bots. I checked out their script editor code and this is what I found:
package org.rsbot.gui;
import info.runedev.Lexer.JavaLexer;
import info.runedev.Lexer.Lexer;
import info.runedev.Lexer.Token;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.Image;
import java.awt.Insets;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintStream;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URI;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.Vector;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.JInternalFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPopupMenu.Separator;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextPane;
import javax.swing.KeyStroke;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.filechooser.FileFilter;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.DefaultStyledDocument;
import javax.swing.text.Element;
import javax.swing.text.Position;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
import org.rsbot.util.GlobalConfiguration;
import org.rsbot.util.GlobalConfiguration.OperatingSystem;
import org.rsbot.util.GlobalConfiguration.Paths;
public class ScriptEditor extends JInternalFrame
{
private static final long serialVersionUID = 8326421682467537173L;
public static File file = new File("");
private JPopupMenu.Separator jSeparator1;
protected JTextPane textPane;
protected HighLightedDocument document;
protected DocumentReader documentReader;
protected Lexer syntaxLexer;
protected Colorer colorer;
private Object doclock = new Object();
public static String defaultLayout = "import java.awt.Graphics; \nimport java.util.Map; \n\nimport org.rsbot.event.listeners.PaintListener; \nimport org.rsbot.script.Script; \nimport org.rsbot.script.ScriptManifest; \n\n@ScriptManifest(authors = { \"Your Name Here\" }, name = \"Script Name Here\",\n category = \"\", version = 1.00, description = \"\") \n public class YourScriptNameHere extends Script implements PaintListener { \n\n public int loop() {\n return (5);\n }\n\n public void onRepaint(final Graphics render) {\n }\n\n public boolean onStart(final Map<String, String> args) {\n return true;\n }\n\n public void onFinish() {\n }\n}";
private Hashtable styles = new Hashtable();
public ScriptEditor()
{
try
{
setFrameIcon(new ImageIcon((GlobalConfiguration.RUNNING_FROM_JAR) ? super.getClass().getResource("/resources/images/script_edit.png") : new File(GlobalConfiguration.Paths.SCRIPT_EDIT).toURI().toURL()));
} catch (MalformedURLException localMalformedURLException) {
}
setTitle("Runedev Script Editor");
setVisible(true);
setBackground(new Color(245, 245, 245));
setResizable(false);
this.document = new HighLightedDocument(null);
this.jSeparator1 = new JPopupMenu.Separator();
this.textPane = new JTextPane(this.document);
this.textPane.setCaretPosition(0);
this.textPane.setMargin(new Insets(5, 5, 5, 5));
JScrollPane localJScrollPane = new JScrollPane(this.textPane);
JPanel localJPanel = new JPanel(new BorderLayout());
localJPanel.add(localJScrollPane, "Center");
setContentPane(localJPanel);
JMenuBar localJMenuBar = new JMenuBar();
JMenu localJMenu1 = new JMenu("File");
JMenuItem localJMenuItem1 = new JMenuItem("New");
localJMenuItem1.setAccelerator(KeyStroke.getKeyStroke(78, 2));
try {
Image localImage1 = Toolkit.getDefaultToolkit().getImage((GlobalConfiguration.RUNNING_FROM_JAR) ? super.getClass().getResource("/resources/images/pencil.png") : new File(GlobalConfiguration.Paths.PENCIL).toURI().toURL());
localJMenuItem1.setIcon(new ImageIcon(localImage1));
} catch (Exception localException1) {
}
localJMenu1.add(localJMenuItem1);
JMenuItem localJMenuItem2 = new JMenuItem("Open");
localJMenuItem2.setAccelerator(KeyStroke.getKeyStroke(79, 2));
try {
Image localImage2 = Toolkit.getDefaultToolkit().getImage((GlobalConfiguration.RUNNING_FROM_JAR) ? super.getClass().getResource("/resources/images/control_play_blue.png") : new File(GlobalConfiguration.Paths.ICON_PLAY).toURI().toURL());
localJMenuItem2.setIcon(new ImageIcon(localImage2));
} catch (Exception localException2) {
}
localJMenu1.add(localJMenuItem2);
JMenuItem localJMenuItem3 = new JMenuItem("Save");
localJMenuItem3.setAccelerator(KeyStroke.getKeyStroke(83, 2));
try {
Image localImage3 = Toolkit.getDefaultToolkit().getImage((GlobalConfiguration.RUNNING_FROM_JAR) ? super.getClass().getResource("/resources/images/save.png") : new File(GlobalConfiguration.Paths.SAVE).toURI().toURL());
localJMenuItem3.setIcon(new ImageIcon(localImage3));
} catch (Exception localException3) {
}
localJMenu1.add(localJMenuItem3);
localJMenuBar.add(localJMenu1);
JMenu localJMenu2 = new JMenu("Edit");
JMenuItem localJMenuItem4 = new JMenuItem("Cut");
localJMenuItem4.setAccelerator(KeyStroke.getKeyStroke(88, 2));
try {
Image localImage4 = Toolkit.getDefaultToolkit().getImage((GlobalConfiguration.RUNNING_FROM_JAR) ? super.getClass().getResource("/resources/images/cut.png") : new File(GlobalConfiguration.Paths.CUT).toURI().toURL());
localJMenuItem4.setIcon(new ImageIcon(localImage4));
} catch (Exception localException4) {
}
localJMenu2.add(localJMenuItem4);
JMenuItem localJMenuItem5 = new JMenuItem("Copy");
localJMenuItem5.setAccelerator(KeyStroke.getKeyStroke(67, 2));
try {
Image localImage5 = Toolkit.getDefaultToolkit().getImage((GlobalConfiguration.RUNNING_FROM_JAR) ? super.getClass().getResource("/resources/images/copy.png") : new File(GlobalConfiguration.Paths.COPY).toURI().toURL());
localJMenuItem5.setIcon(new ImageIcon(localImage5));
} catch (Exception localException5) {
}
localJMenu2.add(localJMenuItem5);
JMenuItem localJMenuItem6 = new JMenuItem("Paste");
localJMenuItem6.setAccelerator(KeyStroke.getKeyStroke(86, 2));
try {
Image localImage6 = Toolkit.getDefaultToolkit().getImage((GlobalConfiguration.RUNNING_FROM_JAR) ? super.getClass().getResource("/resources/images/paste.png") : new File(GlobalConfiguration.Paths.PASTE).toURI().toURL());
localJMenuItem6.setIcon(new ImageIcon(localImage6));
} catch (Exception localException6) {
}
localJMenu2.add(localJMenuItem6);
localJMenu2.add(this.jSeparator1);
JMenuItem localJMenuItem7 = new JMenuItem("Select All");
localJMenuItem7.setAccelerator(KeyStroke.getKeyStroke(65, 2));
localJMenu2.add(localJMenuItem7);
localJMenuBar.add(localJMenu2);
JMenu localJMenu3 = new JMenu("Info");
JMenuItem localJMenuItem8 = new JMenuItem("Troubleshooting");
localJMenuItem8.setAccelerator(KeyStroke.getKeyStroke(84, 2));
try {
Image localImage7 = Toolkit.getDefaultToolkit().getImage((GlobalConfiguration.RUNNING_FROM_JAR) ? super.getClass().getResource("/resources/images/web_small.png") : new File(GlobalConfiguration.Paths.WEB_SMALL).toURI().toURL());
localJMenuItem8.setIcon(new ImageIcon(localImage7));
} catch (Exception localException7) {
}
localJMenu3.add(localJMenuItem8);
JMenuItem localJMenuItem9 = new JMenuItem("about");
localJMenuItem9.setAccelerator(KeyStroke.getKeyStroke(112, 2));
try {
Image localImage8 = Toolkit.getDefaultToolkit().getImage((GlobalConfiguration.RUNNING_FROM_JAR) ? super.getClass().getResource("/resources/images/gui_button.png") : new File(GlobalConfiguration.Paths.GUI_BUTTON).toURI().toURL());
localJMenuItem9.setIcon(new ImageIcon(localImage8));
} catch (Exception localException8) {
}
localJMenu3.add(localJMenuItem9);
localJMenuBar.add(localJMenu3);
localJMenuItem1.addActionListener(new ActionListener(localJPanel)
{
public void actionPerformed(ActionEvent paramActionEvent)
{
if (JOptionPane.showConfirmDialog(this.val$contentPane, "You really want to start a new script? \nAll un-saved work on this script will be lost.") != 0)
return;
try
{
this.this$0.document.remove(0, this.this$0.document.getLength());
this.this$0.document.insertString(this.this$0.document.getLength(), ScriptEditor.defaultLayout, this.this$0.getStyle("text"));
}
catch (BadLocationException localBadLocationException)
{
}
}
});
localJMenuItem2.addActionListener(new ActionListener(localJPanel)
{
public void actionPerformed(ActionEvent paramActionEvent)
{
JFileChooser localJFileChooser = new JFileChooser(ScriptEditor.file);
localJFileChooser.setCurrentDirectory(new File("./scripts/"));
localJFileChooser.addChoosableFileFilter(new ScriptEditor.JavaFilter(this.this$0));
if (localJFileChooser.showOpenDialog(this.val$contentPane) == 0) {
ScriptEditor.file = localJFileChooser.getSelectedFile();
try {
this.this$0.document.remove(0, this.this$0.document.getLength());
BufferedReader localBufferedReader = new BufferedReader(new FileReader(ScriptEditor.file));
String str = null;
while ((str = localBufferedReader.readLine()) != null) {
if (this.this$0.document.getLength() != 0) {
this.this$0.document.insertString(this.this$0.document.getLength(), "\n", this.this$0.getStyle("text"));
}
this.this$0.document.insertString(this.this$0.document.getLength(), str, this.this$0.getStyle("text"));
}
}
catch (Exception localException)
{
}
}
}
});
localJMenuItem3.addActionListener(new ActionListener(localJPanel)
{
public void actionPerformed(ActionEvent paramActionEvent)
{
JFileChooser localJFileChooser = new JFileChooser(ScriptEditor.file);
localJFileChooser.setCurrentDirectory(new File("./scripts/"));
localJFileChooser.addChoosableFileFilter(new ScriptEditor.JavaFilter(this.this$0));
if (localJFileChooser.showSaveDialog(this.val$contentPane) != 0) return;
try {
ScriptEditor.file = localJFileChooser.getSelectedFile();
BufferedWriter localBufferedWriter = new BufferedWriter(new FileWriter(ScriptEditor.file));
localBufferedWriter.write(this.this$0.document.getText(0, this.this$0.document.getLength()));
localBufferedWriter.close();
}
catch (Exception localException)
{
}
}
});
localJMenuItem4.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent paramActionEvent)
{
ScriptEditor.this.textPane.cut();
}
});
localJMenuItem5.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent paramActionEvent)
{
ScriptEditor.this.textPane.copy();
}
});
localJMenuItem6.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent paramActionEvent)
{
ScriptEditor.this.textPane.paste();
}
});
localJMenuItem7.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent paramActionEvent)
{
ScriptEditor.this.textPane.selectAll();
}
});
localJMenuItem8.addActionListener(new ActionListener()
{
public void openURL(String paramString)
{
GlobalConfiguration.OperatingSystem localOperatingSystem = GlobalConfiguration.getCurrentOperatingSystem();
try {
Object localObject;
Method localMethod;
if (localOperatingSystem == GlobalConfiguration.OperatingSystem.MAC) {
localObject = Class.forName("com.apple.eio.FileManager");
localMethod = ((Class)localObject).getDeclaredMethod("openURL", new Class[] { String.class });
localMethod.invoke(null, new Object[] { paramString });
} else if (localOperatingSystem == GlobalConfiguration.OperatingSystem.WINDOWS) {
Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + paramString);
} else {
localObject = new String[] { "firefox", "opera", "konqueror", "epiphany", "mozilla", "netscape" };
localMethod = null;
for (int i = 0; (i < localObject.length) && (localMethod == null); ++i) {
if (Runtime.getRuntime().exec(new String[] { "which", localObject[i] }).waitFor() == 0) {
localMethod = localObject[i];
}
}
if (localMethod == null) {
throw new Exception("Could not find web browser");
}
Runtime.getRuntime().exec(new String[] { localMethod, paramString });
}
}
catch (Exception localException) {
}
}
public void actionPerformed(ActionEvent paramActionEvent) {
openURL("http://forum.runedev.info/viewtopic.php?f=40&t=2629");
}
});
localJMenuItem9.addActionListener(new ActionListener(localJPanel)
{
public void actionPerformed(ActionEvent paramActionEvent)
{
JOptionPane.showMessageDialog(this.val$contentPane, new String[] { "A Script Editor Made for RuneDev.", "\nThis Editor was designed by Sorcermus\nfor the RuneDev gaming client\nFor more information, \nvisit; http://runedev.info/" }, "\nAbout this editor, and the game client", 1);
}
});
setJMenuBar(localJMenuBar);
JTextArea localJTextArea = new JTextArea("");
localJTextArea.setSelectionEnd(this.document.getLength());
localJTextArea.setFont(new Font("Monospaced", 0, 12));
localJTextArea.setBackground(new Color(210, 210, 210));
localJTextArea.setEditable(false);
localJTextArea.setMargin(new Insets(5, 2, 5, 2));
this.document.addDocumentListener(new DocumentListener(localJTextArea)
{
public String getText() {
int i = ScriptEditor.this.document.getEndPosition().getOffset();
Element localElement = ScriptEditor.this.document.getDefaultRootElement();
String str = "1" + System.getProperty("line.separator");
for (int j = 2; j < localElement.getElementIndex(i) + 2; ++j) {
str = str + j + System.getProperty("line.separator");
}
return str;
}
public void changedUpdate(DocumentEvent paramDocumentEvent) {
this.val$lines.setText(getText());
}
public void insertUpdate(DocumentEvent paramDocumentEvent) {
this.val$lines.setText(getText());
}
public void removeUpdate(DocumentEvent paramDocumentEvent) {
this.val$lines.setText(getText());
}
});
localJScrollPane.setRowHeaderView(localJTextArea);
this.colorer = new Colorer(null);
this.colorer.start();
initStyles(12);
this.documentReader = new DocumentReader(this.document);
initDocument();
pack();
setVisible(true);
}
public void colorAll()
{
color(0, this.document.getLength());
}
public void color(int paramInt1, int paramInt2) {
this.colorer.color(paramInt1, paramInt2);
}
private void initDocument()
{
this.syntaxLexer = new JavaLexer(this.documentReader);
try
{
this.document.insertString(this.document.getLength(), defaultLayout, getStyle("text"));
}
catch (BadLocationException localBadLocationException) {
System.err.println("Couldn't insert initial text.");
}
}
private SimpleAttributeSet getStyle(String paramString)
{
return ((SimpleAttributeSet)this.styles.get(paramString));
}
private void initStyles(int paramInt)
{
SimpleAttributeSet localSimpleAttributeSet = new SimpleAttributeSet();
StyleConstants.setFontFamily(localSimpleAttributeSet, "Monospaced");
StyleConstants.setFontSize(localSimpleAttributeSet, paramInt);
StyleConstants.setBackground(localSimpleAttributeSet, Color.white);
StyleConstants.setForeground(localSimpleAttributeSet, Color.black);
StyleConstants.setBold(localSimpleAttributeSet, false);
StyleConstants.setItalic(localSimpleAttributeSet, false);
this.styles.put("body", localSimpleAttributeSet);
localSimpleAttributeSet = new SimpleAttributeSet();
StyleConstants.setFontFamily(localSimpleAttributeSet, "Monospaced");
StyleConstants.setFontSize(localSimpleAttributeSet, paramInt);
StyleConstants.setBackground(localSimpleAttributeSet, Color.white);
StyleConstants.setForeground(localSimpleAttributeSet, Color.blue);
StyleConstants.setBold(localSimpleAttributeSet, true);
StyleConstants.setItalic(localSimpleAttributeSet, false);
this.styles.put("tag", localSimpleAttributeSet);
localSimpleAttributeSet = new SimpleAttributeSet();
StyleConstants.setFontFamily(localSimpleAttributeSet, "Monospaced");
StyleConstants.setFontSize(localSimpleAttributeSet, paramInt);
StyleConstants.setBackground(localSimpleAttributeSet, Color.white);
StyleConstants.setForeground(localSimpleAttributeSet, Color.blue);
StyleConstants.setBold(localSimpleAttributeSet, false);
StyleConstants.setItalic(localSimpleAttributeSet, false);
this.styles.put("endtag", localSimpleAttributeSet);
localSimpleAttributeSet = new SimpleAttributeSet();
StyleConstants.setFontFamily(localSimpleAttributeSet, "Monospaced");
StyleConstants.setFontSize(localSimpleAttributeSet, paramInt);
StyleConstants.setBackground(localSimpleAttributeSet, Color.white);
StyleConstants.setForeground(localSimpleAttributeSet, Color.black);
StyleConstants.setBold(localSimpleAttributeSet, false);
StyleConstants.setItalic(localSimpleAttributeSet, false);
this.styles.put("reference", localSimpleAttributeSet);
localSimpleAttributeSet = new SimpleAttributeSet();
StyleConstants.setFontFamily(localSimpleAttributeSet, "Monospaced");
StyleConstants.setFontSize(localSimpleAttributeSet, paramInt);
StyleConstants.setBackground(localSimpleAttributeSet, Color.white);
StyleConstants.setForeground(localSimpleAttributeSet, new Color(11546720));
StyleConstants.setBold(localSimpleAttributeSet, true);
StyleConstants.setItalic(localSimpleAttributeSet, false);
this.styles.put("name", localSimpleAttributeSet);
localSimpleAttributeSet = new SimpleAttributeSet();
StyleConstants.setFontFamily(localSimpleAttributeSet, "Monospaced");
StyleConstants.setFontSize(localSimpleAttributeSet, paramInt);
StyleConstants.setBackground(localSimpleAttributeSet, Color.white);
StyleConstants.setForeground(localSimpleAttributeSet, new Color(11546720));
StyleConstants.setBold(localSimpleAttributeSet, false);
StyleConstants.setItalic(localSimpleAttributeSet, true);
this.styles.put("value", localSimpleAttributeSet);
localSimpleAttributeSet = new SimpleAttributeSet();
StyleConstants.setFontFamily(localSimpleAttributeSet, "Monospaced");
StyleConstants.setFontSize(localSimpleAttributeSet, paramInt);
StyleConstants.setBackground(localSimpleAttributeSet, Color.white);
StyleConstants.setForeground(localSimpleAttributeSet, Color.black);
StyleConstants.setBold(localSimpleAttributeSet, true);
StyleConstants.setItalic(localSimpleAttributeSet, false);
this.styles.put("text", localSimpleAttributeSet);
localSimpleAttributeSet = new SimpleAttributeSet();
StyleConstants.setFontFamily(localSimpleAttributeSet, "Monospaced");
StyleConstants.setFontSize(localSimpleAttributeSet, paramInt);
StyleConstants.setBackground(localSimpleAttributeSet, Color.white);
StyleConstants.setForeground(localSimpleAttributeSet, Color.blue);
StyleConstants.setBold(localSimpleAttributeSet, false);
StyleConstants.setItalic(localSimpleAttributeSet, false);
this.styles.put("reservedWord", localSimpleAttributeSet);
localSimpleAttributeSet = new SimpleAttributeSet();
StyleConstants.setFontFamily(localSimpleAttributeSet, "Monospaced");
StyleConstants.setFontSize(localSimpleAttributeSet, paramInt);
StyleConstants.setBackground(localSimpleAttributeSet, Color.white);
StyleConstants.setForeground(localSimpleAttributeSet, Color.black);
StyleConstants.setBold(localSimpleAttributeSet, false);
StyleConstants.setItalic(localSimpleAttributeSet, false);
this.styles.put("identifier", localSimpleAttributeSet);
localSimpleAttributeSet = new SimpleAttributeSet();
StyleConstants.setFontFamily(localSimpleAttributeSet, "Monospaced");
StyleConstants.setFontSize(localSimpleAttributeSet, paramInt);
StyleConstants.setBackground(localSimpleAttributeSet, Color.white);
StyleConstants.setForeground(localSimpleAttributeSet, new Color(11546720));
StyleConstants.setBold(localSimpleAttributeSet, false);
StyleConstants.setItalic(localSimpleAttributeSet, false);
this.styles.put("literal", localSimpleAttributeSet);
localSimpleAttributeSet = new SimpleAttributeSet();
StyleConstants.setFontFamily(localSimpleAttributeSet, "Monospaced");
StyleConstants.setFontSize(localSimpleAttributeSet, paramInt);
StyleConstants.setBackground(localSimpleAttributeSet, Color.white);
StyleConstants.setForeground(localSimpleAttributeSet, new Color(128));
StyleConstants.setBold(localSimpleAttributeSet, false);
StyleConstants.setItalic(localSimpleAttributeSet, false);
this.styles.put("separator", localSimpleAttributeSet);
localSimpleAttributeSet = new SimpleAttributeSet();
StyleConstants.setFontFamily(localSimpleAttributeSet, "Monospaced");
StyleConstants.setFontSize(localSimpleAttributeSet, paramInt);
StyleConstants.setBackground(localSimpleAttributeSet, Color.white);
StyleConstants.setForeground(localSimpleAttributeSet, Color.black);
StyleConstants.setBold(localSimpleAttributeSet, true);
StyleConstants.setItalic(localSimpleAttributeSet, false);
this.styles.put("operator", localSimpleAttributeSet);
localSimpleAttributeSet = new SimpleAttributeSet();
StyleConstants.setFontFamily(localSimpleAttributeSet, "Monospaced");
StyleConstants.setFontSize(localSimpleAttributeSet, paramInt);
StyleConstants.setBackground(localSimpleAttributeSet, Color.white);
StyleConstants.setForeground(localSimpleAttributeSet, Color.green.darker());
StyleConstants.setBold(localSimpleAttributeSet, false);
StyleConstants.setItalic(localSimpleAttributeSet, false);
this.styles.put("comment", localSimpleAttributeSet);
localSimpleAttributeSet = new SimpleAttributeSet();
StyleConstants.setFontFamily(localSimpleAttributeSet, "Monospaced");
StyleConstants.setFontSize(localSimpleAttributeSet, paramInt);
StyleConstants.setBackground(localSimpleAttributeSet, Color.white);
StyleConstants.setForeground(localSimpleAttributeSet, new Color(10494192).darker());
StyleConstants.setBold(localSimpleAttributeSet, false);
StyleConstants.setItalic(localSimpleAttributeSet, false);
this.styles.put("preprocessor", localSimpleAttributeSet);
localSimpleAttributeSet = new SimpleAttributeSet();
StyleConstants.setFontFamily(localSimpleAttributeSet, "Monospaced");
StyleConstants.setFontSize(localSimpleAttributeSet, paramInt);
StyleConstants.setBackground(localSimpleAttributeSet, Color.white);
StyleConstants.setForeground(localSimpleAttributeSet, Color.black);
StyleConstants.setBold(localSimpleAttributeSet, false);
StyleConstants.setItalic(localSimpleAttributeSet, false);
this.styles.put("whitespace", localSimpleAttributeSet);
localSimpleAttributeSet = new SimpleAttributeSet();
StyleConstants.setFontFamily(localSimpleAttributeSet, "Monospaced");
StyleConstants.setFontSize(localSimpleAttributeSet, paramInt);
StyleConstants.setBackground(localSimpleAttributeSet, Color.white);
StyleConstants.setForeground(localSimpleAttributeSet, Color.red);
StyleConstants.setBold(localSimpleAttributeSet, false);
StyleConstants.setItalic(localSimpleAttributeSet, false);
this.styles.put("error", localSimpleAttributeSet);
localSimpleAttributeSet = new SimpleAttributeSet();
StyleConstants.setFontFamily(localSimpleAttributeSet, "Monospaced");
StyleConstants.setFontSize(localSimpleAttributeSet, paramInt);
StyleConstants.setBackground(localSimpleAttributeSet, Color.white);
StyleConstants.setForeground(localSimpleAttributeSet, Color.orange);
StyleConstants.setBold(localSimpleAttributeSet, false);
StyleConstants.setItalic(localSimpleAttributeSet, false);
this.styles.put("unknown", localSimpleAttributeSet);
}
private class HighLightedDocument extends DefaultStyledDocument
{
public void insertString(int paramInt, String paramString, AttributeSet paramAttributeSet)
throws BadLocationException
{
synchronized (ScriptEditor.this.doclock) {
super.insertString(paramInt, paramString, paramAttributeSet);
ScriptEditor.this.color(paramInt, paramString.length());
ScriptEditor.this.documentReader.update(paramInt, paramString.length());
}
}
public void remove(int paramInt1, int paramInt2) throws BadLocationException
{
synchronized (ScriptEditor.this.doclock) {
super.remove(paramInt1, paramInt2);
ScriptEditor.this.color(paramInt1, -paramInt2);
ScriptEditor.this.documentReader.update(paramInt1, -paramInt2);
}
}
}
private class Colorer extends Thread
{
private TreeSet iniPositions;
private HashSet newPositions;
private volatile Vector v;
private volatile int change;
private volatile int lastPosition;
private volatile boolean asleep;
private Object lock;
private Colorer()
{
this.iniPositions = new TreeSet(new DocPositionComparator());
this.newPositions = new HashSet();
this.v = new Vector();
this.change = 0;
this.lastPosition = -1;
this.asleep = false;
this.lock = new Object();
}
public void color(int paramInt1, int paramInt2) {
if (paramInt1 < this.lastPosition) {
if (this.lastPosition < paramInt1 - paramInt2)
this.change -= this.lastPosition - paramInt1;
else {
this.change += paramInt2;
}
}
synchronized (this.lock) {
this.v.add(new RecolorEvent(paramInt1, paramInt2));
if (this.asleep)
interrupt();
}
}
public void run()
{
int i = -1;
int j = 0;
int k = 0;
while (true)
{
Object localObject1;
synchronized (this.lock) {
if (this.v.size() > 0) {
localObject1 = (RecolorEvent)(RecolorEvent)this.v.elementAt(0);
this.v.removeElementAt(0);
i = ((RecolorEvent)localObject1).position;
j = ((RecolorEvent)localObject1).adjustment;
} else {
k = 0;
i = -1;
j = 0;
}
}
if (i != -1)
{
DocPosition localDocPosition1 = new DocPosition(i);
DocPosition localDocPosition2 = new DocPosition(i + ((j >= 0) ? j : -j));
DocPosition localDocPosition4 = null;
DocPosition localDocPosition5 = null;
try
{
??? = this.iniPositions.headSet(localDocPosition1);
localDocPosition4 = (DocPosition)((SortedSet)???).last();
} catch (NoSuchElementException localNoSuchElementException) {
localDocPosition4 = new DocPosition(0);
}
if (j < 0) {
??? = this.iniPositions.subSet(localDocPosition1, localDocPosition2);
localObject1 = ((SortedSet)???).iterator();
while (((Iterator)localObject1).hasNext()) {
((Iterator)localObject1).next();
((Iterator)localObject1).remove();
}
}
??? = this.iniPositions.tailSet(localDocPosition1);
localObject1 = ((SortedSet)???).iterator();
while (((Iterator)localObject1).hasNext()) {
((DocPosition)((Iterator)localObject1).next()).adjustPosition(j);
}
??? = this.iniPositions.tailSet(localDocPosition4);
localObject1 = ((SortedSet)???).iterator();
DocPosition localDocPosition3 = null;
if (((Iterator)localObject1).hasNext()) {
localDocPosition3 = (DocPosition)((Iterator)localObject1).next();
}
try
{
Token localToken;
int l = 0;
localDocPosition5 = localDocPosition4;
synchronized (ScriptEditor.this.doclock) {
ScriptEditor.this.syntaxLexer.reset(ScriptEditor.this.documentReader, 0, localDocPosition4.getPosition(), 0);
ScriptEditor.this.documentReader.seek(localDocPosition4.getPosition());
localToken = ScriptEditor.this.syntaxLexer.getNextToken();
}
this.newPositions.add(localDocPosition4);
while ((l == 0) && (localToken != null)) {
synchronized (ScriptEditor.this.doclock) {
if (localToken.getCharEnd() <= ScriptEditor.this.document.getLength()) {
ScriptEditor.this.document.setCharacterAttributes(localToken.getCharBegin() + this.change, localToken.getCharEnd() - localToken.getCharBegin(), ScriptEditor.this.getStyle(localToken.getDescription()), true);
localDocPosition5 = new DocPosition(localToken.getCharEnd());
}
this.lastPosition = (localToken.getCharEnd() + this.change);
}
if (localToken.getState() == 0)
{
while ((localDocPosition3 != null) && (localDocPosition3.getPosition() <= localToken.getCharEnd())) {
if ((localDocPosition3.getPosition() == localToken.getCharEnd()) && (localDocPosition3.getPosition() >= localDocPosition2.getPosition()))
{
l = 1;
localDocPosition3 = null; }
if (((Iterator)localObject1).hasNext()) {
localDocPosition3 = (DocPosition)((Iterator)localObject1).next();
}
localDocPosition3 = null;
}
this.newPositions.add(localDocPosition5);
}
synchronized (ScriptEditor.this.doclock) {
localToken = ScriptEditor.this.syntaxLexer.getNextToken();
}
}
localObject1 = this.iniPositions.subSet(localDocPosition4, localDocPosition5).iterator();
while (((Iterator)localObject1).hasNext()) {
((Iterator)localObject1).next();
((Iterator)localObject1).remove();
}
localObject1 = this.iniPositions.tailSet(new DocPosition(ScriptEditor.this.document.getLength())).iterator();
while (((Iterator)localObject1).hasNext()) {
((Iterator)localObject1).next();
((Iterator)localObject1).remove();
}
this.iniPositions.addAll(this.newPositions);
this.newPositions.clear();
} catch (IOException localIOException) {
}
synchronized (ScriptEditor.this.doclock) {
this.lastPosition = -1;
this.change = 0;
}
k = 1;
}
this.asleep = true;
if (k == 0)
try {
sleep(16777215L);
}
catch (InterruptedException localInterruptedException)
{
}
this.asleep = false;
}
}
private class RecolorEvent
{
public int position;
public int adjustment;
public RecolorEvent(int paramInt1, int paramInt2)
{
this.position = paramInt1;
this.adjustment = paramInt2;
}
}
}
class JavaFilter extends FileFilter
{
public boolean accept(File paramFile)
{
String str = paramFile.getName();
return str.endsWith(".java");
}
public String getDescription() {
return "*.java";
}
}
}
This is TRiBot's script editor code:
package org.tribot.gui;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.Frame;
import java.awt.Insets;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.Vector;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.JInternalFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextPane;
import javax.swing.ScrollPaneConstants;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.text.AbstractDocument;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.DefaultStyledDocument;
import javax.swing.text.Element;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
import org.tribot.bot.TRiBot;
import org.tribot.loader.Client;
import com.Ostermiller.Syntax.Lexer.JavaLexer;
import com.Ostermiller.Syntax.Lexer.Lexer;
import com.Ostermiller.Syntax.Lexer.Token;
public class ScriptEditor extends JInternalFrame {
private static final long serialVersionUID = 8326421682467537173L;
public static File file = new File("");
protected JTextPane textPane;
protected HighLightedDocument document;
protected DocumentReader documentReader;
protected Lexer syntaxLexer;
protected Colorer colorer;
private Object doclock = new Object();
public String defaultLayout = "package scripts;"
+ "\n"
+ "\nimport java.awt.Graphics;"
+ "\n"
+ "\nimport org.tribot.loader.Client;"
+ "\nimport org.tribot.script.Script;"
+ "\nimport org.tribot.wrappers.RSInterface;"
+ "\nimport org.tribot.script.ScriptManifest;"
+ "\n"
+ "\n@ScriptManifest(authors = { \"TRiLeZ\" }, name = \"Script Skeleton\", category = \"Skeleton\")"
+ "\npublic class ScriptSkeleton extends Script {" + "\n"
+ "\n public ScriptSkeleton(Client bot) {" + "\n super(bot);"
+ "\n }" + "\n" + "\n public void onPause() {" + "\n" + "\n }"
+ "\n" + "\n public void onResume() {" + "\n" + "\n }" + "\n"
+ "\n public void onBreakStart() {" + "\n" + "\n }" + "\n"
+ "\n public void onBreakEnd() {" + "\n" + "\n }" + "\n"
+ "\n public void onEnd() {" + "\n" + "\n }" + "\n"
+ "\n public void onPaint(Graphics g) {" + "\n" + "\n }" + "\n"
+ "\n public void run() {" + "\n" + "\n }" + "\n" + "\n}";
public ScriptEditor() {
this.setTitle("Script Editor");
this.setVisible(true);
this.setBackground(new Color(245, 245, 245));
this.setResizable(false);
this.setFrameIcon(new ImageIcon("images/script icon.png"));
document = new HighLightedDocument();
textPane = new JTextPane(document);
textPane.setCaretPosition(0);
textPane.setMargin(new Insets(5, 5, 5, 5));
JScrollPane scrollPane = new JScrollPane(textPane);
scrollPane
.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
final JPanel contentPane = new JPanel(new BorderLayout());
contentPane.add(scrollPane, BorderLayout.CENTER);
setContentPane(contentPane);
JMenuBar menuBar = new JMenuBar();
JMenu fileMenu = new JMenu("File");
Icon icon = new ImageIcon("images\\new.png");
JMenuItem newScript = new JMenuItem("New", icon);
fileMenu.add(newScript);
icon = new ImageIcon("images\\open.png");
JMenuItem openScript = new JMenuItem("Open", icon);
fileMenu.add(openScript);
icon = new ImageIcon("images\\save.png");
JMenuItem saveScript = new JMenuItem("Save", icon);
fileMenu.add(saveScript);
menuBar.add(fileMenu);
JMenu editMenu = new JMenu("Edit");
icon = new ImageIcon("images\\cut.png");
JMenuItem cut = new JMenuItem("Cut", icon);
editMenu.add(cut);
icon = new ImageIcon("images\\copy.png");
JMenuItem copy = new JMenuItem("Copy", icon);
editMenu.add(copy);
icon = new ImageIcon("images\\paste.png");
JMenuItem paste = new JMenuItem("Paste", icon);
editMenu.add(paste);
icon = new ImageIcon("images\\select all.png");
JMenuItem selectAll = new JMenuItem("Select All", icon);
editMenu.add(selectAll);
menuBar.add(editMenu);
JMenu scriptMenu = new JMenu("Script");
icon = new ImageIcon("images\\compile.png");
JMenuItem compileScript = new JMenuItem("Compile", icon);
scriptMenu.add(compileScript);
icon = new ImageIcon("images\\terminal.png");
JMenuItem runScript = new JMenuItem("Run", icon);
scriptMenu.add(runScript);
menuBar.add(scriptMenu);
class newClick implements ActionListener {
public void actionPerformed(ActionEvent e) {
if (JOptionPane
.showConfirmDialog(contentPane,
"You really want to start a new script? All un-saved work will be lost.") == 0)
try {
document.remove(0, document.getLength());
document.insertString(document.getLength(),
defaultLayout, getStyle("text"));
} catch (BadLocationException e1) {
e1.printStackTrace();
}
}
}
class openClick implements ActionListener {
public void actionPerformed(ActionEvent e) {
Frame f = new Frame("Open");
f.setIconImage(Toolkit.getDefaultToolkit().getImage(
"images/open.png"));
final JFileChooser fc = new JFileChooser(file);
fc.setCurrentDirectory(new File("./src/scripts/"));
fc.addChoosableFileFilter(new JavaFilter());
if (fc.showOpenDialog(f) == JFileChooser.APPROVE_OPTION) {
file = fc.getSelectedFile();
try {
document.remove(0, document.getLength());
BufferedReader in = new BufferedReader(new FileReader(
file));
String line = null;
while ((line = in.readLine()) != null) {
if (document.getLength() != 0)
document.insertString(document.getLength(),
"\n", getStyle("text"));
document.insertString(document.getLength(), line,
getStyle("text"));
}
} catch (Exception ee) {
}
}
}
}
class saveClick implements ActionListener {
public void actionPerformed(ActionEvent e) {
Frame f = new Frame("Open");
f.setIconImage(Toolkit.getDefaultToolkit().getImage(
"images/save.png"));
final JFileChooser fc = new JFileChooser(file);
fc.setCurrentDirectory(new File("./src/scripts/"));
fc.addChoosableFileFilter(new JavaFilter());
if (fc.showSaveDialog(f) == JFileChooser.APPROVE_OPTION) {
try {
Boolean b = true;
file = fc.getSelectedFile();
if (file.exists())
if (JOptionPane.showConfirmDialog(contentPane,
"Overwrite file?") != 0)
b = false;
if (b == true) {
BufferedWriter out = new BufferedWriter(
new FileWriter(file));
out.write(document.getText(0, document.getLength()));
out.close();
}
b = false;
} catch (Exception ee) {
ee.printStackTrace();
}
}
}
}
class Cut implements ActionListener {
public void actionPerformed(ActionEvent e) {
textPane.cut();
}
}
class Copy implements ActionListener {
public void actionPerformed(ActionEvent e) {
textPane.copy();
}
}
class Paste implements ActionListener {
public void actionPerformed(ActionEvent e) {
textPane.paste();
}
}
class SelectAll implements ActionListener {
public void actionPerformed(ActionEvent e) {
textPane.selectAll();
}
}
class compileClick implements ActionListener {
public void actionPerformed(ActionEvent e) {
try {
/* Writes script to temporary file */
File tempFile = new File("data\\temp\\temp.java");
BufferedWriter tempOut = new BufferedWriter(new FileWriter(
tempFile));
tempOut.write(document.getText(0, document.getLength()));
tempOut.close();
String scriptName = "";
try {
BufferedReader in = new BufferedReader(new FileReader(
tempFile));
String line = null;
while ((line = in.readLine()) != null) {
if (line.contains("public class")) {
String data[] = line.split(" ");
scriptName = data[2];
}
}
in.close();
} catch (Exception ee) {
}
tempFile.delete();
if (scriptName == "") {
TRiBot.mainGUI
.println("Script Editor: Script name not found! Compiling failed!");
} else {
/* Writes script to temporary file with proper name */
File tempScriptFile = new File("data\\temp\\"
+ scriptName + ".java");
BufferedWriter scriptOut = new BufferedWriter(
new FileWriter(tempScriptFile));
scriptOut.write(document.getText(0,
document.getLength()));
scriptOut.close();
/* Makes a batch file for tempScriptFile */
File cmdfile = new File("Comile Script.cmd");
BufferedWriter cmdOut = new BufferedWriter(
new FileWriter(cmdfile));
cmdOut.write("@ECHO OFF\njavac -cp \"bin\" data\\temp\\"
+ scriptName + ".java");
cmdOut.close();
try {
Process p = Runtime.getRuntime().exec(
"Comile Script.cmd");
p.waitFor();
cmdfile.delete();
tempScriptFile.delete();
BufferedInputStream bis = new BufferedInputStream(
p.getInputStream());
BufferedReader stdError = new BufferedReader(
new InputStreamReader(p.getErrorStream()));
while (bis.available() > 0) {
TRiBot.mainGUI.println("" + (char) bis.read());
}
String s = null;
Boolean errors = false;
if (((s = stdError.readLine()) != null)) {
TRiBot.mainGUI.println(
"\nCompilation Errors:\n", false);
}
while ((s = stdError.readLine()) != null) {
TRiBot.mainGUI.println(s, false);
errors = true;
}
if (errors == false) {
File outputFile = new File("data\\temp\\"
+ scriptName + ".class");
outputFile.delete();
TRiBot.mainGUI.println(scriptName
+ " compiled successfully! No errors!");
if (JOptionPane
.showConfirmDialog(contentPane,
"Would you like to save this script to the scripts folder?") == 0) {
/* Saves the script source */
File newScriptFile = new File(
"src\\scripts\\" + scriptName
+ ".java");
Boolean b = true;
if (newScriptFile.exists())
if (!(JOptionPane.showConfirmDialog(
contentPane,
"Overwrite script: "
+ scriptName + "?") == 0))
b = false;
if (b == true) {
BufferedWriter newScriptOut = new BufferedWriter(
new FileWriter(newScriptFile));
newScriptOut.write(document.getText(0,
document.getLength()));
newScriptOut.close();
/* Makes a batch file for script */
cmdfile = new File("Comile Script.cmd");
cmdOut = new BufferedWriter(
new FileWriter(cmdfile));
cmdOut.write("@ECHO OFF\njavac -cp \"bin\" -d \"bin\" src\\scripts\\"
+ scriptName + ".java");
cmdOut.close();
p = Runtime.getRuntime().exec(
"Comile Script.cmd");
p.waitFor();
cmdfile.delete();
TRiBot.mainGUI
.println("Script source and code saved!");
}
b = false;
}
}
} catch (Exception ee) {
ee.printStackTrace();
}
}
} catch (Exception ee) {
ee.printStackTrace();
}
}
}
class runClick implements ActionListener {
public void actionPerformed(ActionEvent e) {
compileAndRun();
}
}
newScript.addActionListener(new newClick());
openScript.addActionListener(new openClick());
saveScript.addActionListener(new saveClick());
cut.addActionListener(new Cut());
copy.addActionListener(new Copy());
paste.addActionListener(new Paste());
selectAll.addActionListener(new SelectAll());
compileScript.addActionListener(new compileClick());
runScript.addActionListener(new runClick());
this.setJMenuBar(menuBar);
final JTextArea lines = new JTextArea("");
lines.setSelectionEnd(document.getLength());
lines.setFont(new Font("Monospaced", Font.PLAIN, 12));
lines.setForeground(Color.DARK_GRAY);
lines.setBackground(new Color(210, 210, 210));
lines.setEditable(false);
lines.setMargin(new Insets(5, 2, 5, 2));
document.addDocumentListener(new DocumentListener() {
public String getText() {
int caretPosition = document.getEndPosition().getOffset();
Element root = document.getDefaultRootElement();
String text = "1" + System.getProperty("line.separator");
for (int i = 2; i < root.getElementIndex(caretPosition) + 2; i++) {
text += i + System.getProperty("line.separator");
}
return text;
}
@Override
public void changedUpdate(DocumentEvent de) {
lines.setText(getText());
}
@Override
public void insertUpdate(DocumentEvent de) {
lines.setText(getText());
}
@Override
public void removeUpdate(DocumentEvent de) {
lines.setText(getText());
}
});
scrollPane.setRowHeaderView(lines);
colorer = new Colorer();
colorer.start();
initStyles(12);
documentReader = new DocumentReader(document);
initDocument();
this.pack();
this.updateUI();
this.setVisible(true);
}
private void compileAndRun() {
try {
/* Writes script to temporary file */
File tempFile = new File("data\\temp\\temp.java");
BufferedWriter tempOut = new BufferedWriter(
new FileWriter(tempFile));
tempOut.write(document.getText(0, document.getLength()));
tempOut.close();
String scriptName = "";
try {
BufferedReader in = new BufferedReader(new FileReader(tempFile));
String line = null;
while ((line = in.readLine()) != null) {
if (line.contains("public class")) {
String data[] = line.split(" ");
scriptName = data[2];
}
}
in.close();
} catch (Exception ee) {
}
tempFile.delete();
if (scriptName == "") {
TRiBot.mainGUI
.println("Script Editor: Script name not found! Compiling failed!");
} else {
/* Writes script to temporary file with proper name */
File tempScriptFile = new File("data\\temp\\" + scriptName
+ ".java");
BufferedWriter scriptOut = new BufferedWriter(new FileWriter(
tempScriptFile));
scriptOut.write(document.getText(0, document.getLength())
.replace("package scripts;", ""));
scriptOut.close();
/* Makes a batch file for tempScriptFile */
File cmdfile = new File("Comile Script.cmd");
BufferedWriter cmdOut = new BufferedWriter(new FileWriter(
cmdfile));
cmdOut.write("@ECHO OFF\njavac -cp \"bin\" data\\temp\\"
+ scriptName + ".java");
cmdOut.close();
try {
Process p = Runtime.getRuntime().exec("Comile Script.cmd");
p.waitFor();
cmdfile.delete();
tempScriptFile.delete();
BufferedInputStream bis = new BufferedInputStream(
p.getInputStream());
BufferedReader stdError = new BufferedReader(
new InputStreamReader(p.getErrorStream()));
while (bis.available() > 0) {
TRiBot.mainGUI.println("" + (char) bis.read());
}
String s = null;
Boolean errors = false;
if (((s = stdError.readLine()) != null)) {
TRiBot.mainGUI
.println("\nCompilation Errors:\n", false);
}
while ((s = stdError.readLine()) != null) {
TRiBot.mainGUI.println(s, false);
errors = true;
}
if (errors == false) {
File outputFile = new File("data\\temp\\" + scriptName
+ ".class");
TRiBot.mainGUI
.println(scriptName
+ " compiled successfully! No errors! Running script...");
File directory = new File("data\\temp");
ClassLoader cL;
try {
cL = new URLClassLoader(new URL[] { directory
.toURI().toURL() });
} catch (MalformedURLException e) {
TRiBot.mainGUI
.println("Error loading the compiled script!");
return;
}
Class<?> script = null;
try {
script = cL.loadClass(scriptName);
} catch (Exception e) {
TRiBot.mainGUI
.println("Error loading the compiled script!");
}
Client bot = TRiBot.mainGUI.getVisibleClient();
if (bot == null) {
TRiBot.mainGUI
.println("Please start a client before trying to run a script.");
} else if (TRiBot.mainGUI.getVisibleClient().scriptHandler.isRunning) {
TRiBot.mainGUI
.println("Another script is already running. Please close that script before you try to run another script.");
} else {
TRiBot.mainGUI.getVisibleClient().scriptHandler
.startScript(script, scriptName, null);
}
outputFile.delete();
}
} catch (Exception ee) {
ee.printStackTrace();
}
}
} catch (Exception ee) {
ee.printStackTrace();
}
}
class JavaFilter extends javax.swing.filechooser.FileFilter {
public boolean accept(File file) {
String filename = file.getName();
return filename.endsWith(".java");
}
public String getDescription() {
return "*.java";
}
}
public class Colorer extends Thread {
@SuppressWarnings("unchecked")
private TreeSet<DocPosition> iniPositions = new TreeSet<DocPosition>(
new DocPositionComparator());
private HashSet<DocPosition> newPositions = new HashSet<DocPosition>();
public class RecolorEvent {
public int position;
public int adjustment;
public RecolorEvent(int position, int adjustment) {
this.position = position;
this.adjustment = adjustment;
}
}
@SuppressWarnings({ "rawtypes" })
private volatile Vector v = new Vector<RecolorEvent>();
private volatile int change = 0;
private volatile int lastPosition = -1;
private volatile boolean asleep = false;
private Object lock = new Object();
@SuppressWarnings("unchecked")
public void color(int position, int adjustment) {
if (position < lastPosition) {
if (lastPosition < position - adjustment) {
change -= lastPosition - position;
} else {
change += adjustment;
}
}
synchronized (lock) {
v.add(new RecolorEvent(position, adjustment));
if (asleep) {
this.interrupt();
}
}
}
public void run() {
int position = -1;
int adjustment = 0;
boolean tryAgain = false;
for (;;) {
synchronized (lock) {
if (v.size() > 0) {
RecolorEvent re = (RecolorEvent) (v.elementAt(0));
v.removeElementAt(0);
position = re.position;
adjustment = re.adjustment;
} else {
tryAgain = false;
position = -1;
adjustment = 0;
}
}
if (position != -1) {
@SuppressWarnings("rawtypes")
SortedSet workingSet;
@SuppressWarnings("rawtypes")
Iterator workingIt;
DocPosition startRequest = new DocPosition(position);
DocPosition endRequest = new DocPosition(position
+ ((adjustment >= 0) ? adjustment : -adjustment));
DocPosition dp;
DocPosition dpStart = null;
DocPosition dpEnd = null;
try {
workingSet = iniPositions.headSet(startRequest);
dpStart = ((DocPosition) workingSet.last());
} catch (NoSuchElementException x) {
dpStart = new DocPosition(0);
}
if (adjustment < 0) {
workingSet = iniPositions.subSet(startRequest,
endRequest);
workingIt = workingSet.iterator();
while (workingIt.hasNext()) {
workingIt.next();
workingIt.remove();
}
}
workingSet = iniPositions.tailSet(startRequest);
workingIt = workingSet.iterator();
while (workingIt.hasNext()) {
((DocPosition) workingIt.next())
.adjustPosition(adjustment);
}
workingSet = iniPositions.tailSet(dpStart);
workingIt = workingSet.iterator();
dp = null;
if (workingIt.hasNext()) {
dp = (DocPosition) workingIt.next();
}
try {
Token t;
boolean done = false;
dpEnd = dpStart;
synchronized (doclock) {
syntaxLexer.reset(documentReader, 0,
dpStart.getPosition(), 0);
documentReader.seek(dpStart.getPosition());
t = syntaxLexer.getNextToken();
}
newPositions.add(dpStart);
while (!done && t != null) {
synchronized (doclock) {
if (t.getCharEnd() <= document.getLength()) {
document.setCharacterAttributes(
t.getCharBegin() + change,
t.getCharEnd() - t.getCharBegin(),
getStyle(t.getDescription()), true);
dpEnd = new DocPosition(t.getCharEnd());
}
lastPosition = (t.getCharEnd() + change);
}
if (t.getState() == Token.INITIAL_STATE) {
while (dp != null
&& dp.getPosition() <= t.getCharEnd()) {
if (dp.getPosition() == t.getCharEnd()
&& dp.getPosition() >= endRequest
.getPosition()) {
done = true;
dp = null;
} else if (workingIt.hasNext()) {
dp = (DocPosition) workingIt.next();
} else {
dp = null;
}
}
newPositions.add(dpEnd);
}
synchronized (doclock) {
t = syntaxLexer.getNextToken();
}
}
workingIt = iniPositions.subSet(dpStart, dpEnd)
.iterator();
while (workingIt.hasNext()) {
workingIt.next();
workingIt.remove();
}
workingIt = iniPositions.tailSet(
new DocPosition(document.getLength()))
.iterator();
while (workingIt.hasNext()) {
workingIt.next();
workingIt.remove();
}
iniPositions.addAll(newPositions);
newPositions.clear();
} catch (IOException x) {
}
synchronized (doclock) {
lastPosition = -1;
change = 0;
}
tryAgain = true;
}
asleep = true;
if (!tryAgain) {
try {
sleep(0xffffff);
} catch (InterruptedException x) {
}
}
asleep = false;
}
}
}
public void colorAll() {
color(0, document.getLength());
}
public void color(int position, int adjustment) {
colorer.color(position, adjustment);
}
private void initDocument() {
syntaxLexer = new JavaLexer(documentReader);
try {
document.insertString(document.getLength(), defaultLayout,
getStyle("text"));
} catch (BadLocationException ble) {
System.err.println("Couldn't insert initial text.");
}
}
@SuppressWarnings({ "rawtypes" })
private Hashtable styles = new Hashtable();
private SimpleAttributeSet getStyle(String styleName) {
return ((SimpleAttributeSet) styles.get(styleName));
}
@SuppressWarnings("unchecked")
private void initStyles(int fontSize) {
SimpleAttributeSet style;
style = new SimpleAttributeSet();
StyleConstants.setFontFamily(style, "Monospaced");
StyleConstants.setFontSize(style, fontSize);
StyleConstants.setForeground(style, Color.LIGHT_GRAY);
StyleConstants.setBold(style, false);
StyleConstants.setItalic(style, false);
styles.put("body", style);
style = new SimpleAttributeSet();
StyleConstants.setFontFamily(style, "Monospaced");
StyleConstants.setFontSize(style, fontSize);
StyleConstants.setForeground(style, Color.blue);
StyleConstants.setBold(style, true);
StyleConstants.setItalic(style, false);
styles.put("tag", style);
style = new SimpleAttributeSet();
StyleConstants.setFontFamily(style, "Monospaced");
StyleConstants.setFontSize(style, fontSize);
StyleConstants.setForeground(style, Color.blue);
StyleConstants.setBold(style, false);
StyleConstants.setItalic(style, false);
styles.put("endtag", style);
style = new SimpleAttributeSet();
StyleConstants.setFontFamily(style, "Monospaced");
StyleConstants.setFontSize(style, fontSize);
StyleConstants.setForeground(style, Color.LIGHT_GRAY);
StyleConstants.setBold(style, false);
StyleConstants.setItalic(style, false);
styles.put("reference", style);
style = new SimpleAttributeSet();
StyleConstants.setFontFamily(style, "Monospaced");
StyleConstants.setFontSize(style, fontSize);
StyleConstants.setForeground(style, new Color(0xB03060));
StyleConstants.setBold(style, true);
StyleConstants.setItalic(style, false);
styles.put("name", style);
style = new SimpleAttributeSet();
StyleConstants.setFontFamily(style, "Monospaced");
StyleConstants.setFontSize(style, fontSize);
StyleConstants.setForeground(style, new Color(0xB03060));
StyleConstants.setBold(style, false);
StyleConstants.setItalic(style, true);
styles.put("value", style);
style = new SimpleAttributeSet();
StyleConstants.setFontFamily(style, "Monospaced");
StyleConstants.setFontSize(style, fontSize);
StyleConstants.setForeground(style, Color.LIGHT_GRAY);
StyleConstants.setBold(style, true);
StyleConstants.setItalic(style, false);
styles.put("text", style);
style = new SimpleAttributeSet();
StyleConstants.setFontFamily(style, "Monospaced");
StyleConstants.setFontSize(style, fontSize);
StyleConstants.setForeground(style, new Color(220, 0, 94).brighter());
StyleConstants.setBold(style, false);
StyleConstants.setItalic(style, false);
styles.put("reservedWord", style);
style = new SimpleAttributeSet();
StyleConstants.setFontFamily(style, "Monospaced");
StyleConstants.setFontSize(style, fontSize);
StyleConstants.setForeground(style, Color.LIGHT_GRAY);
StyleConstants.setBold(style, false);
StyleConstants.setItalic(style, false);
styles.put("identifier", style);
style = new SimpleAttributeSet();
StyleConstants.setFontFamily(style, "Monospaced");
StyleConstants.setFontSize(style, fontSize);
StyleConstants.setForeground(style, new Color(34, 122, 225).brighter());
StyleConstants.setBold(style, false);
StyleConstants.setItalic(style, false);
styles.put("literal", style);
style = new SimpleAttributeSet();
StyleConstants.setFontFamily(style, "Monospaced");
StyleConstants.setFontSize(style, fontSize);
StyleConstants.setForeground(style, Color.LIGHT_GRAY.darker());
StyleConstants.setBold(style, false);
StyleConstants.setItalic(style, false);
styles.put("separator", style);
style = new SimpleAttributeSet();
StyleConstants.setFontFamily(style, "Monospaced");
StyleConstants.setFontSize(style, fontSize);
StyleConstants.setForeground(style, Color.LIGHT_GRAY.darker());
StyleConstants.setBold(style, true);
StyleConstants.setItalic(style, false);
styles.put("operator", style);
style = new SimpleAttributeSet();
StyleConstants.setFontFamily(style, "Monospaced");
StyleConstants.setFontSize(style, fontSize);
StyleConstants.setForeground(style, Color.green.darker());
StyleConstants.setBold(style, false);
StyleConstants.setItalic(style, false);
styles.put("comment", style);
style = new SimpleAttributeSet();
StyleConstants.setFontFamily(style, "Monospaced");
StyleConstants.setFontSize(style, fontSize);
StyleConstants.setForeground(style, new Color(0xA020F0).darker());
StyleConstants.setBold(style, false);
StyleConstants.setItalic(style, false);
styles.put("preprocessor", style);
style = new SimpleAttributeSet();
StyleConstants.setFontFamily(style, "Monospaced");
StyleConstants.setFontSize(style, fontSize);
StyleConstants.setForeground(style, Color.black);
StyleConstants.setBold(style, false);
StyleConstants.setItalic(style, false);
styles.put("whitespace", style);
style = new SimpleAttributeSet();
StyleConstants.setFontFamily(style, "Monospaced");
StyleConstants.setFontSize(style, fontSize);
StyleConstants.setForeground(style, Color.red);
StyleConstants.setBold(style, false);
StyleConstants.setItalic(style, false);
styles.put("error", style);
style = new SimpleAttributeSet();
StyleConstants.setFontFamily(style, "Monospaced");
StyleConstants.setFontSize(style, fontSize);
StyleConstants.setForeground(style, Color.orange);
StyleConstants.setBold(style, false);
StyleConstants.setItalic(style, false);
styles.put("unknown", style);
}
@SuppressWarnings("serial")
private class HighLightedDocument extends DefaultStyledDocument {
public void insertString(int offs, String str, AttributeSet a)
throws BadLocationException {
synchronized (doclock) {
super.insertString(offs, str, a);
color(offs, str.length());
documentReader.update(offs, str.length());
}
}
public void remove(int offs, int len) throws BadLocationException {
synchronized (doclock) {
super.remove(offs, len);
color(offs, -len);
documentReader.update(offs, -len);
}
}
}
}
class DocPosition {
private int position;
int getPosition() {
return position;
}
public DocPosition(int position) {
this.position = position;
}
public DocPosition adjustPosition(int adjustment) {
position += adjustment;
return this;
}
public boolean equals(Object obj) {
if (obj instanceof DocPosition) {
DocPosition d = (DocPosition) (obj);
if (this.position == d.position) {
return true;
} else {
return false;
}
} else {
return false;
}
}
public String toString() {
return "" + position;
}
}
@SuppressWarnings({ "rawtypes" })
class DocPositionComparator implements Comparator {
public boolean equals(Object obj) {
if (obj instanceof DocPositionComparator) {
return true;
} else {
return false;
}
}
public int compare(Object o1, Object o2) {
if (o1 instanceof DocPosition && o2 instanceof DocPosition) {
DocPosition d1 = (DocPosition) (o1);
DocPosition d2 = (DocPosition) (o2);
return (d1.getPosition() - d2.getPosition());
} else if (o1 instanceof DocPosition) {
return -1;
} else if (o2 instanceof DocPosition) {
return 1;
} else if (o1.hashCode() < o2.hashCode()) {
return -1;
} else if (o2.hashCode() > o1.hashCode()) {
return 1;
} else {
return 0;
}
}
}
class DocumentReader extends Reader {
public void update(int position, int adjustment) {
if (position < this.position) {
if (this.position < position - adjustment) {
this.position = position;
} else {
this.position += adjustment;
}
}
}
private long position = 0;
private long mark = -1;
private AbstractDocument document;
public DocumentReader(AbstractDocument document) {
this.document = document;
}
public void close() {
}
public void mark(int readAheadLimit) {
mark = position;
}
public boolean markSupported() {
return true;
}
public int read() {
if (position < document.getLength()) {
try {
char c = document.getText((int) position, 1).charAt(0);
position++;
return c;
} catch (BadLocationException x) {
return -1;
}
} else {
return -1;
}
}
public int read(char[] cbuf) {
return read(cbuf, 0, cbuf.length);
}
public int read(char[] cbuf, int off, int len) {
if (position < document.getLength()) {
int length = len;
if (position + length >= document.getLength()) {
length = document.getLength() - (int) position;
}
if (off + length >= cbuf.length) {
length = cbuf.length - off;
}
try {
String s = document.getText((int) position, length);
position += length;
for (int i = 0; i < length; i++) {
cbuf[off + i] = s.charAt(i);
}
return length;
} catch (BadLocationException x) {
return -1;
}
} else {
return -1;
}
}
public boolean ready() {
return true;
}
public void reset() {
if (mark == -1) {
position = 0;
} else {
position = mark;
}
mark = -1;
}
public long skip(long n) {
if (position + n <= document.getLength()) {
position += n;
return n;
} else {
long oldPos = position;
position = document.getLength();
return (document.getLength() - oldPos);
}
}
public void seek(long n) {
if (n <= document.getLength()) {
position = n;
} else {
position = document.getLength();
}
}
}
So, it's obviously my script editor.
The part that pissed me off the most is this:
public void actionPerformed(ActionEvent paramActionEvent)
{
JOptionPane.showMessageDialog(this.val$contentPane, new String[] { "A Script Editor Made for RuneDev.", "\nThis Editor was designed by Sorcermus\nfor the RuneDev gaming client\nFor more information, \nvisit; http://runedev.info/" }, "\nAbout this editor, and the game client", 1);
}
Which clames that kid made the script editor for RuneDev… he has also made $185 this month from RuneDev, so he is proffiting off of TRiBot / RSBot.
:fiery:
What to do now…
