mirror of
https://github.com/2006-Scape/Parabot.git
synced 2026-07-05 16:49:41 +00:00
Merge branch 'master' of https://github.com/Parabot/Parabot.git
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
# Parabot
|
# Parabot
|
||||||
|
|
||||||
Parabot V2.08.
|
Parabot V2.09.
|
||||||
|
|
||||||
#### Website
|
#### Website
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,7 @@
|
|||||||
package org.parabot.core.ui;
|
package org.parabot.core.ui;
|
||||||
|
|
||||||
import org.parabot.core.Context;
|
import java.awt.BorderLayout;
|
||||||
import org.parabot.core.ui.components.GamePanel;
|
import java.awt.Point;
|
||||||
import org.parabot.core.ui.images.Images;
|
|
||||||
import org.parabot.environment.scripts.Script;
|
|
||||||
|
|
||||||
import javax.swing.*;
|
|
||||||
|
|
||||||
import java.awt.*;
|
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
import java.awt.event.ComponentEvent;
|
import java.awt.event.ComponentEvent;
|
||||||
@@ -15,6 +9,21 @@ import java.awt.event.ComponentListener;
|
|||||||
import java.awt.event.WindowEvent;
|
import java.awt.event.WindowEvent;
|
||||||
import java.awt.event.WindowListener;
|
import java.awt.event.WindowListener;
|
||||||
|
|
||||||
|
import javax.swing.ImageIcon;
|
||||||
|
import javax.swing.JCheckBoxMenuItem;
|
||||||
|
import javax.swing.JDialog;
|
||||||
|
import javax.swing.JFrame;
|
||||||
|
import javax.swing.JMenu;
|
||||||
|
import javax.swing.JMenuBar;
|
||||||
|
import javax.swing.JMenuItem;
|
||||||
|
import javax.swing.JPopupMenu;
|
||||||
|
|
||||||
|
import org.parabot.core.Context;
|
||||||
|
import org.parabot.core.ui.components.GamePanel;
|
||||||
|
import org.parabot.core.ui.images.Images;
|
||||||
|
import org.parabot.core.ui.utils.SwingUtil;
|
||||||
|
import org.parabot.environment.scripts.Script;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* The bot user interface
|
* The bot user interface
|
||||||
@@ -41,11 +50,23 @@ public class BotUI extends JFrame implements ActionListener, ComponentListener,
|
|||||||
setTitle("Parabot");
|
setTitle("Parabot");
|
||||||
setResizable(false);
|
setResizable(false);
|
||||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
setIconImage(Images.getResource("/org/parabot/core/ui/images/icon.png"));
|
createMenu();
|
||||||
|
|
||||||
setLayout(new BorderLayout());
|
setLayout(new BorderLayout());
|
||||||
addComponentListener(this);
|
addComponentListener(this);
|
||||||
addWindowListener(this);
|
addWindowListener(this);
|
||||||
|
|
||||||
|
add(GamePanel.getInstance());
|
||||||
|
GamePanel.getInstance().addLoader();
|
||||||
|
|
||||||
|
SwingUtil.setParabotIcons(this);
|
||||||
|
|
||||||
|
pack();
|
||||||
|
setLocationRelativeTo(null);
|
||||||
|
BotDialog.getInstance(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createMenu() {
|
||||||
JMenuBar menuBar = new JMenuBar();
|
JMenuBar menuBar = new JMenuBar();
|
||||||
|
|
||||||
JMenu file = new JMenu("File");
|
JMenu file = new JMenu("File");
|
||||||
@@ -87,13 +108,6 @@ public class BotUI extends JFrame implements ActionListener, ComponentListener,
|
|||||||
menuBar.add(scripts);
|
menuBar.add(scripts);
|
||||||
|
|
||||||
setJMenuBar(menuBar);
|
setJMenuBar(menuBar);
|
||||||
|
|
||||||
add(GamePanel.getInstance());
|
|
||||||
GamePanel.getInstance().addLoader();
|
|
||||||
|
|
||||||
pack();
|
|
||||||
setLocationRelativeTo(null);
|
|
||||||
BotDialog.getInstance(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import org.parabot.core.Core;
|
|||||||
import org.parabot.core.forum.AccountManager;
|
import org.parabot.core.forum.AccountManager;
|
||||||
import org.parabot.core.forum.AccountManagerAccess;
|
import org.parabot.core.forum.AccountManagerAccess;
|
||||||
import org.parabot.core.ui.images.Images;
|
import org.parabot.core.ui.images.Images;
|
||||||
|
import org.parabot.core.ui.utils.SwingUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -88,8 +89,8 @@ public class LoginUI extends JFrame {
|
|||||||
this.setLocationByPlatform(true);
|
this.setLocationByPlatform(true);
|
||||||
this.setLayout(new BorderLayout());
|
this.setLayout(new BorderLayout());
|
||||||
this.setResizable(false);
|
this.setResizable(false);
|
||||||
this.setIconImage(Images
|
|
||||||
.getResource("/org/parabot/core/ui/images/icon.png"));
|
SwingUtil.setParabotIcons(this);
|
||||||
|
|
||||||
int w = 250;
|
int w = 250;
|
||||||
int x = 8;
|
int x = 8;
|
||||||
|
|||||||
@@ -1,18 +1,20 @@
|
|||||||
package org.parabot.core.ui;
|
package org.parabot.core.ui;
|
||||||
|
|
||||||
|
import java.awt.BorderLayout;
|
||||||
|
import java.awt.Dimension;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.Queue;
|
||||||
|
|
||||||
|
import javax.swing.JFrame;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JScrollPane;
|
||||||
|
|
||||||
import org.parabot.core.desc.ServerDescription;
|
import org.parabot.core.desc.ServerDescription;
|
||||||
import org.parabot.core.parsers.servers.ServerParser;
|
import org.parabot.core.parsers.servers.ServerParser;
|
||||||
import org.parabot.core.ui.components.ServerComponent;
|
import org.parabot.core.ui.components.ServerComponent;
|
||||||
import org.parabot.core.ui.images.Images;
|
|
||||||
import org.parabot.core.ui.utils.SwingUtil;
|
import org.parabot.core.ui.utils.SwingUtil;
|
||||||
import org.parabot.environment.Environment;
|
import org.parabot.environment.Environment;
|
||||||
|
|
||||||
import javax.swing.*;
|
|
||||||
|
|
||||||
import java.awt.*;
|
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.Queue;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Shows a list of every supported server which can be started
|
* Shows a list of every supported server which can be started
|
||||||
@@ -48,7 +50,8 @@ public class ServerSelector extends JFrame {
|
|||||||
this.setTitle("Servers");
|
this.setTitle("Servers");
|
||||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
this.setResizable(false);
|
this.setResizable(false);
|
||||||
this.setIconImage(Images.getResource("/org/parabot/core/ui/images/icon.png"));
|
|
||||||
|
SwingUtil.setParabotIcons(this);
|
||||||
|
|
||||||
this.panel = new JPanel(new BorderLayout());
|
this.panel = new JPanel(new BorderLayout());
|
||||||
this.panel.setPreferredSize(new Dimension(600, 400));
|
this.panel.setPreferredSize(new Dimension(600, 400));
|
||||||
@@ -89,7 +92,6 @@ public class ServerSelector extends JFrame {
|
|||||||
* @param widgets
|
* @param widgets
|
||||||
*/
|
*/
|
||||||
private boolean runServer(Queue<ServerComponent> widgets) {
|
private boolean runServer(Queue<ServerComponent> widgets) {
|
||||||
// TODO: test this method
|
|
||||||
if (widgets == null || widgets.isEmpty()) {
|
if (widgets == null || widgets.isEmpty()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,14 @@
|
|||||||
package org.parabot.core.ui.utils;
|
package org.parabot.core.ui.utils;
|
||||||
|
|
||||||
|
import java.awt.Image;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
|
|
||||||
|
import org.parabot.core.ui.images.Images;
|
||||||
|
import org.parabot.environment.OperatingSystem;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Holds various swing util based methods
|
* Holds various swing util based methods
|
||||||
@@ -21,5 +28,22 @@ public class SwingUtil {
|
|||||||
f.setLocationRelativeTo(null);
|
f.setLocationRelativeTo(null);
|
||||||
f.setVisible(true);
|
f.setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void setParabotIcons(JFrame f) {
|
||||||
|
f.setIconImage(Images.getResource("/org/parabot/core/ui/images/icon.png"));
|
||||||
|
|
||||||
|
if(OperatingSystem.getOS() == OperatingSystem.MAC) {
|
||||||
|
/** Adds the dock icon to mac users */
|
||||||
|
try {
|
||||||
|
Class<?> util = Class.forName("com.apple.eawt.Application");
|
||||||
|
Object application = util.getMethod("getApplication", new Class[] { }).invoke(null);
|
||||||
|
Method setDockIconImage = util.getMethod("setDockIconImage", new Class[] { Image.class });
|
||||||
|
setDockIconImage.invoke(application, Images.getResource("/org/parabot/core/ui/images/icon.png"));
|
||||||
|
} catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | IllegalAccessException ignored) {
|
||||||
|
} catch (Throwable t) {
|
||||||
|
t.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,67 @@
|
|||||||
|
package org.parabot.environment.scripts;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
import org.parabot.environment.scripts.framework.AbstractFramework;
|
||||||
|
import org.parabot.environment.scripts.framework.LoopTask;
|
||||||
|
import org.parabot.environment.scripts.framework.Strategy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Holds various script frameworks
|
||||||
|
*
|
||||||
|
* @author Everel
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class Frameworks {
|
||||||
|
|
||||||
|
public static Looper getLooper(LoopTask loopTask) {
|
||||||
|
return new Looper(loopTask);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static StrategyWorker getStrategyWorker(Collection<Strategy> strategies) {
|
||||||
|
return new StrategyWorker(strategies);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class Looper extends AbstractFramework {
|
||||||
|
private LoopTask loopTask = null;
|
||||||
|
|
||||||
|
public Looper(LoopTask loopTask) {
|
||||||
|
this.loopTask = loopTask;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public boolean execute() {
|
||||||
|
int sleepTime = loopTask.loop();
|
||||||
|
if(sleepTime < 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Thread.sleep(sleepTime);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class StrategyWorker extends AbstractFramework {
|
||||||
|
private Collection<Strategy> strategies;
|
||||||
|
|
||||||
|
public StrategyWorker(Collection<Strategy> strategies) {
|
||||||
|
this.strategies = strategies;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean execute() {
|
||||||
|
for(Strategy s : strategies) {
|
||||||
|
if(s.activate()) {
|
||||||
|
s.execute();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
package org.parabot.environment.servers;
|
||||||
|
|
||||||
|
import org.parabot.core.Core;
|
||||||
|
import org.parabot.core.Directories;
|
||||||
|
import org.parabot.core.build.BuildPath;
|
||||||
|
import org.parabot.core.classpath.ClassPath;
|
||||||
|
import org.parabot.environment.servers.executers.ServerExecuter;
|
||||||
|
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Loads locally stored server providers
|
||||||
|
*
|
||||||
|
* @author Everel
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class LocalServerExecuter extends ServerExecuter {
|
||||||
|
private final ServerProvider serverProvider;
|
||||||
|
private ClassPath classPath;
|
||||||
|
private String serverName;
|
||||||
|
|
||||||
|
public LocalServerExecuter(ServerProvider serverProvider,
|
||||||
|
ClassPath classPath, final String serverName) {
|
||||||
|
this.serverProvider = serverProvider;
|
||||||
|
this.classPath = classPath;
|
||||||
|
this.serverName = serverName;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
// add jar or directory to buildpath.
|
||||||
|
if (this.classPath.isJar()) {
|
||||||
|
Core.verbose("Adding server provider jar to buildpath: "
|
||||||
|
+ this.classPath.lastParsed.toString());
|
||||||
|
this.classPath.addToBuildPath();
|
||||||
|
} else {
|
||||||
|
Core.verbose("Adding server providers directory to buildpath: "
|
||||||
|
+ Directories.getServerPath().getPath());
|
||||||
|
try {
|
||||||
|
BuildPath.add(Directories.getServerPath().toURI().toURL());
|
||||||
|
} catch (MalformedURLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// finalize
|
||||||
|
super.finalize(this.serverProvider, this.serverName);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user