mirror of
https://github.com/2006-Scape/Parabot.git
synced 2026-07-03 00:37:55 +00:00
Spring Cleaning
Clisprail is so bad.
This commit is contained in:
@@ -5,7 +5,6 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.TimerTask;
|
||||
|
||||
|
||||
import org.parabot.core.asm.ASMClassLoader;
|
||||
import org.parabot.core.bot.loader.BotLoader;
|
||||
import org.parabot.core.classpath.ClassPath;
|
||||
@@ -17,8 +16,9 @@ import org.parabot.environment.servers.ServerProvider;
|
||||
|
||||
/**
|
||||
* Game context
|
||||
*
|
||||
* @author Clisprail
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class Context {
|
||||
private static HashMap<ThreadGroup, Context> threadGroups = new HashMap<ThreadGroup, Context>();
|
||||
@@ -29,16 +29,14 @@ public class Context {
|
||||
private ServerProvider serverProvider = null;
|
||||
private int tab = 0;
|
||||
private Applet gameApplet = null;
|
||||
|
||||
|
||||
private Object clientInstance = null;
|
||||
|
||||
|
||||
private static ArrayList<Paintable> paintables = new ArrayList<Paintable>();
|
||||
|
||||
|
||||
private PaintDebugger paintDebugger = new PaintDebugger();
|
||||
|
||||
|
||||
public boolean added = false;
|
||||
|
||||
|
||||
|
||||
public Context(final ServerProvider serverProvider) {
|
||||
threadGroups.put(Thread.currentThread().getThreadGroup(), this);
|
||||
@@ -47,40 +45,44 @@ public class Context {
|
||||
id++;
|
||||
this.classPath = new ClassPath();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the ServerProvider class loader
|
||||
*
|
||||
* @param serverEnvironment
|
||||
*/
|
||||
public void setEnvironment(ASMClassLoader serverEnvironment) {
|
||||
classLoader = new BotLoader(classPath, serverEnvironment);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the main client instance
|
||||
*/
|
||||
public void setClientInstance(Object object) {
|
||||
this.clientInstance = object;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* ClassPath
|
||||
*
|
||||
* @return classpath
|
||||
*/
|
||||
public ClassPath getClassPath() {
|
||||
return classPath;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determines if applet has been set
|
||||
*
|
||||
* @return <b>true</b> if set
|
||||
*/
|
||||
public boolean appletSet() {
|
||||
return gameApplet != null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets game applet
|
||||
*
|
||||
* @return applet
|
||||
*/
|
||||
public Applet getApplet() {
|
||||
@@ -89,6 +91,7 @@ public class Context {
|
||||
|
||||
/**
|
||||
* Resolves the context from threadgroup
|
||||
*
|
||||
* @return context
|
||||
*/
|
||||
public static Context resolve() {
|
||||
@@ -102,10 +105,10 @@ public class Context {
|
||||
serverProvider.parseJar();
|
||||
serverProvider.injectHooks();
|
||||
gameApplet = serverProvider.fetchApplet();
|
||||
if(getClient() == null) {
|
||||
if (getClient() == null) {
|
||||
setClientInstance(gameApplet);
|
||||
}
|
||||
serverProvider.addMenuItems(BotUI.getInstance().getBar());
|
||||
serverProvider.addMenuItems(BotUI.getInstance().getJMenuBar());
|
||||
BotUI.getInstance().validate();
|
||||
final GamePanel panel = GamePanel.getInstance();
|
||||
panel.removeLoader();
|
||||
@@ -122,6 +125,7 @@ public class Context {
|
||||
|
||||
/**
|
||||
* Gets the server prodiver belonging to this context
|
||||
*
|
||||
* @return server provider
|
||||
*/
|
||||
public ServerProvider getServerProvider() {
|
||||
@@ -130,6 +134,7 @@ public class Context {
|
||||
|
||||
/**
|
||||
* Gets class loader from this context
|
||||
*
|
||||
* @return class loader
|
||||
*/
|
||||
public ASMClassLoader getASMClassLoader() {
|
||||
@@ -138,6 +143,7 @@ public class Context {
|
||||
|
||||
/**
|
||||
* Gets the id of this context
|
||||
*
|
||||
* @return id context
|
||||
*/
|
||||
public static int getID() {
|
||||
@@ -146,46 +152,52 @@ public class Context {
|
||||
|
||||
/**
|
||||
* Tab id of this context
|
||||
*
|
||||
* @return tab id of this context
|
||||
*/
|
||||
public int getTab() {
|
||||
return tab;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds a paintable instance to the paintables
|
||||
*
|
||||
* @param paintable
|
||||
*/
|
||||
public void addPaintable(Paintable paintable) {
|
||||
paintables.add(paintable);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Removes a paintable instance from the paintables
|
||||
*
|
||||
* @param paintable
|
||||
*/
|
||||
public void removePaintable(Paintable paintable) {
|
||||
paintables.remove(paintable);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the paintable instances
|
||||
*
|
||||
* @return array of paintable instances
|
||||
*/
|
||||
public Paintable[] getPaintables() {
|
||||
return paintables.toArray(new Paintable[paintables.size()]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The client debug painter
|
||||
*
|
||||
* @return debug painter
|
||||
*/
|
||||
public PaintDebugger getPaintDebugger() {
|
||||
return paintDebugger;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the main/client instance
|
||||
*
|
||||
* @return instance of the the client
|
||||
*/
|
||||
public Object getClient() {
|
||||
|
||||
@@ -1,80 +1,105 @@
|
||||
package org.parabot.core.ui;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
import javax.swing.GroupLayout;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JMenu;
|
||||
import javax.swing.JMenuBar;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JPopupMenu;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JToolBar;
|
||||
import javax.swing.WindowConstants;
|
||||
|
||||
import org.parabot.core.ui.components.BotToolbar;
|
||||
import org.parabot.core.ui.components.GamePanel;
|
||||
import org.parabot.core.ui.components.LogArea;
|
||||
import org.parabot.core.ui.images.Images;
|
||||
import org.parabot.core.ui.utils.AwtUtil;
|
||||
import org.parabot.core.ui.utils.SwingUtil;
|
||||
|
||||
/**
|
||||
* Bot frame
|
||||
*
|
||||
* @author Clisprail
|
||||
* @author Dane
|
||||
*
|
||||
*/
|
||||
public class BotUI extends JFrame {
|
||||
public class BotUI extends JFrame implements ActionListener {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = -2126184292879805519L;
|
||||
private static BotUI instance = null;
|
||||
private JMenuBar bar = null;
|
||||
|
||||
public static BotUI getInstance() {
|
||||
return instance == null ? instance = new BotUI() : instance;
|
||||
}
|
||||
|
||||
public BotUI() {
|
||||
JPopupMenu.setDefaultLightWeightPopupEnabled(false);
|
||||
setDefaultLookAndFeelDecorated(false);
|
||||
bar = new JMenuBar();
|
||||
JMenu file = new JMenu("File");
|
||||
JMenuItem screenshot = new JMenuItem("Screenshot");
|
||||
screenshot.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
});
|
||||
file.add(screenshot);
|
||||
bar.add(file);
|
||||
this.setTitle("Parabot");
|
||||
this.setResizable(false);
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
this.setIconImage(Images.getResource("/org/parabot/core/ui/images/icon.png"));
|
||||
this.setLayout(new BorderLayout());
|
||||
|
||||
JScrollPane textPane = LogArea.getInstance();
|
||||
GroupLayout layout = new GroupLayout(getContentPane());
|
||||
JToolBar tool = BotToolbar.getInstance();
|
||||
GamePanel pane = GamePanel.getInstance();
|
||||
pane.addLoader();
|
||||
getContentPane().setLayout(layout);
|
||||
setJMenuBar(bar);
|
||||
setTitle("Parabot");
|
||||
setIconImage(Images.getResource("/org/parabot/core/ui/images/icon.png"));
|
||||
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
||||
setResizable(false);
|
||||
SwingUtil.center(this);
|
||||
layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addContainerGap().addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING))).addComponent(tool, 768, 768, 768).addComponent(pane, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE).addComponent(textPane, 768, 768, 768));
|
||||
layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addComponent(tool, 30, 30, 30).addComponent(pane, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE).addComponent(textPane, 100, 100, 100).addContainerGap(58, Short.MAX_VALUE)));
|
||||
LogArea.log("Welcome to Parabot v2");
|
||||
int iToolbarHeight = 24;
|
||||
int iGameHeight = 503;
|
||||
int iLogHeight = 128;
|
||||
|
||||
JPanel panel = new JPanel();
|
||||
panel.setLocation(0, 0);
|
||||
panel.setPreferredSize(new Dimension(765, iToolbarHeight + iGameHeight + iLogHeight));
|
||||
|
||||
JMenuBar menubar = new JMenuBar();
|
||||
|
||||
JMenu mnuFile = new JMenu("File");
|
||||
JMenuItem itmScreenshot = new JMenuItem("Screenshot");
|
||||
itmScreenshot.addActionListener(this);
|
||||
|
||||
mnuFile.add(itmScreenshot);
|
||||
menubar.add(mnuFile);
|
||||
|
||||
this.setJMenuBar(menubar);
|
||||
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
|
||||
JToolBar toolbar = BotToolbar.getInstance();
|
||||
toolbar.setPreferredSize(new Dimension(765, iToolbarHeight));
|
||||
toolbar.setLocation(x, y);
|
||||
|
||||
y += iToolbarHeight;
|
||||
|
||||
GamePanel gamePanel = GamePanel.getInstance();
|
||||
gamePanel.setPreferredSize(new Dimension(765, iGameHeight));
|
||||
toolbar.setLocation(x, y);
|
||||
|
||||
y += iGameHeight;
|
||||
|
||||
JScrollPane scrlConsole = LogArea.getInstance();
|
||||
scrlConsole.setPreferredSize(new Dimension(765, iLogHeight));
|
||||
toolbar.setLocation(x, y);
|
||||
|
||||
panel.add(toolbar);
|
||||
panel.add(gamePanel);
|
||||
panel.add(scrlConsole);
|
||||
|
||||
this.add(panel, BorderLayout.CENTER);
|
||||
|
||||
SwingUtil.finalize(this);
|
||||
|
||||
LogArea.log("Welcome to Parabot!");
|
||||
}
|
||||
|
||||
public JMenuBar getBar() {
|
||||
return bar;
|
||||
}
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
String command = e.getActionCommand();
|
||||
|
||||
switch (command) {
|
||||
case "Screenshot":
|
||||
LogArea.log("Boop");
|
||||
break;
|
||||
default:
|
||||
System.out.println("Invalid command: ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package org.parabot.core.ui.components;
|
||||
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.Properties;
|
||||
@@ -21,22 +19,17 @@ public class LogArea extends JScrollPane {
|
||||
private static final long serialVersionUID = 6571141103751675714L;
|
||||
private static LogArea instance = null;
|
||||
private static LogTextArea logArea = new LogTextArea();
|
||||
|
||||
|
||||
private LogArea() {
|
||||
super(TextAreaLogHandler.TEXT_AREA,
|
||||
ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
|
||||
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
|
||||
logArea.setPreferredSize(new Dimension(775, 80));
|
||||
setPreferredSize(new Dimension(776, 100));
|
||||
setSize(775, 100);
|
||||
super(TextAreaLogHandler.TEXT_AREA, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
|
||||
setVisible(true);
|
||||
registerLogging();
|
||||
}
|
||||
|
||||
|
||||
public static LogArea getInstance() {
|
||||
return instance == null ? instance = new LogArea() : instance;
|
||||
}
|
||||
|
||||
|
||||
private static final Logger log = Logger.getLogger("Bot");
|
||||
|
||||
public static void log(String s) {
|
||||
@@ -63,19 +56,15 @@ public class LogArea extends JScrollPane {
|
||||
final Properties logging = new Properties();
|
||||
final String logFormatter = LogFormatter.class.getCanonicalName();
|
||||
final String fileHandler = FileHandler.class.getCanonicalName();
|
||||
logging.setProperty("handlers",
|
||||
TextAreaLogHandler.class.getCanonicalName() + "," + fileHandler);
|
||||
logging.setProperty("handlers", TextAreaLogHandler.class.getCanonicalName() + "," + fileHandler);
|
||||
logging.setProperty(".level", "INFO");
|
||||
logging.setProperty(SystemConsoleHandler.class.getCanonicalName()
|
||||
+ ".formatter", logFormatter);
|
||||
logging.setProperty(SystemConsoleHandler.class.getCanonicalName() + ".formatter", logFormatter);
|
||||
logging.setProperty(fileHandler + ".formatter", logFormatter);
|
||||
logging.setProperty(TextAreaLogHandler.class.getCanonicalName()
|
||||
+ ".formatter", logFormatter);
|
||||
logging.setProperty(TextAreaLogHandler.class.getCanonicalName() + ".formatter", logFormatter);
|
||||
final ByteArrayOutputStream logout = new ByteArrayOutputStream();
|
||||
try {
|
||||
logging.store(logout, "");
|
||||
LogManager.getLogManager().readConfiguration(
|
||||
new ByteArrayInputStream(logout.toByteArray()));
|
||||
LogManager.getLogManager().readConfiguration(new ByteArrayInputStream(logout.toByteArray()));
|
||||
} catch (final Exception ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user