From bb2864823c05291c6bc0e10bf313f0d42561f869 Mon Sep 17 00:00:00 2001 From: RedSparr0w Date: Sat, 12 Oct 2019 16:49:15 +1300 Subject: [PATCH] Add auto login, update GUI --- .idea/workspace.xml | 8 +- src/ParaScript/Main.java | 6 +- src/ParaScript/data/Variables.java | 8 ++ src/ParaScript/strategies/HandleLogin.java | 74 ++++++++++++ .../strategies/MakeArrowShafts.java | 2 +- src/ParaScript/ui/UI.java | 106 +++++++++++++----- 6 files changed, 167 insertions(+), 37 deletions(-) create mode 100644 src/ParaScript/strategies/HandleLogin.java diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 93e9eda..a82b6f3 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,7 +2,11 @@ - + + + + + + - diff --git a/src/ParaScript/Main.java b/src/ParaScript/Main.java index 5019a25..38b1801 100644 --- a/src/ParaScript/Main.java +++ b/src/ParaScript/Main.java @@ -1,10 +1,7 @@ package ParaScript; import ParaScript.data.Variables; -import ParaScript.strategies.MakeArrowShafts; -import ParaScript.strategies.ScriptState; -import ParaScript.strategies.Thieving; -import ParaScript.strategies.WoodcutTree; +import ParaScript.strategies.*; import ParaScript.ui.UI; import org.parabot.environment.api.utils.Time; import org.parabot.environment.scripts.Script; @@ -31,6 +28,7 @@ public class Main extends Script{ strategies.add(new ScriptState()); strategies.add(new MakeArrowShafts()); strategies.add(new WoodcutTree()); + strategies.add(new HandleLogin()); provide(strategies); return true; } diff --git a/src/ParaScript/data/Variables.java b/src/ParaScript/data/Variables.java index ecff472..2eab33b 100644 --- a/src/ParaScript/data/Variables.java +++ b/src/ParaScript/data/Variables.java @@ -10,6 +10,8 @@ public class Variables { public static boolean running = false; private static String currentStatus = "none"; + private static String username = ""; + private static String password = ""; public static String getStatus() { return currentStatus; @@ -20,4 +22,10 @@ public class Variables { } public final static Zone LUMBRIDGE_NORMAL_TREE_ZONE = new Zone(new Tile(3140, 3260), new Tile(3206, 3206)); + + public static String getAccountUsername() { return username; } + public static void setAccountUsername(String i) { username = i; } + + public static String getAccountPassword() { return password; } + public static void setAccountPassword(String i) { password = i; } } diff --git a/src/ParaScript/strategies/HandleLogin.java b/src/ParaScript/strategies/HandleLogin.java new file mode 100644 index 0000000..e6c2b30 --- /dev/null +++ b/src/ParaScript/strategies/HandleLogin.java @@ -0,0 +1,74 @@ +package ParaScript.strategies; + +import ParaScript.data.Variables; +import org.parabot.environment.api.utils.Time; +import org.parabot.environment.input.Keyboard; +import org.parabot.environment.input.Mouse; +import org.parabot.environment.scripts.framework.SleepCondition; +import org.parabot.environment.scripts.framework.Strategy; +import org.rev317.min.api.methods.Game; + +import java.awt.*; +import java.awt.event.KeyEvent; + +public class HandleLogin implements Strategy { + + private Point point = new Point(432, 282); + private Point point2 = new Point(328, 324); + private Boolean typed = false; + + @Override + public boolean activate() { + return !Game.isLoggedIn() || Game.getOpenBackDialogId() == 15812; + } + + public void execute() { + Variables.setStatus("logging in"); + + if (Game.isLoggedIn() && Game.getOpenInterfaceId() == 15812) { + Mouse.getInstance().click(point2); + Variables.setStatus("none"); + } + if (!Game.isLoggedIn()) { + if(Variables.getAccountPassword() != null && Variables.getAccountUsername() != null) { + if(!typed) { + Mouse.getInstance().click(point); + Time.sleep(1000); + clearInput(); + Keyboard.getInstance().sendKeys(Variables.getAccountUsername()); + Time.sleep(2000); + + clearInput(); + // Checking again so people don't type their passwords ingame. + if(!Game.isLoggedIn()) { + Keyboard.getInstance().sendKeys(Variables.getAccountPassword()); + } + + typed = true; + } + } + + if(typed) { + Time.sleep(new SleepCondition() { + @Override + public boolean isValid() { + return Game.isLoggedIn(); + } + }, 5000); + Mouse.getInstance().click(point); + Time.sleep(1000); + Keyboard.getInstance().clickKey(KeyEvent.VK_ENTER); + Time.sleep(1000); + Keyboard.getInstance().clickKey(KeyEvent.VK_ENTER); + Variables.setStatus("none"); + } + } + } + + private void clearInput() { + for(int i = 0; i < 30; i ++) { + Keyboard.getInstance().clickKey(KeyEvent.VK_DELETE); + Time.sleep(100); + } + } +} diff --git a/src/ParaScript/strategies/MakeArrowShafts.java b/src/ParaScript/strategies/MakeArrowShafts.java index 81f0715..ca3f54f 100644 --- a/src/ParaScript/strategies/MakeArrowShafts.java +++ b/src/ParaScript/strategies/MakeArrowShafts.java @@ -42,6 +42,6 @@ public class MakeArrowShafts implements Strategy { private boolean hasRequiredItems(){ // Make sure we have a knife and logs - return Inventory.contains(947, 1512); + return Inventory.getItem(947) != null && Inventory.getItem(1512) != null; } } \ No newline at end of file diff --git a/src/ParaScript/ui/UI.java b/src/ParaScript/ui/UI.java index f385848..c63584a 100644 --- a/src/ParaScript/ui/UI.java +++ b/src/ParaScript/ui/UI.java @@ -2,9 +2,12 @@ package ParaScript.ui; import ParaScript.data.variables.Trees; import ParaScript.data.Variables; +import org.rev317.min.api.methods.Game; +import org.rev317.min.api.wrappers.Player; import javax.swing.*; import javax.swing.border.EmptyBorder; +import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -15,64 +18,100 @@ public class UI extends JFrame { private JComboBox treeSelect = new JComboBox(); private JRadioButton bank = new JRadioButton("Bank"); private JRadioButton drop = new JRadioButton("Drop"); + private JCheckBox birdsNest = new JCheckBox(); + // Login tab private JTextField username = new JTextField(); private JPasswordField password = new JPasswordField(); - private JCheckBox birdsNest = new JCheckBox(); + private JCheckBox autoLogin = new JCheckBox(); + // Our colors + private Color Color_MidnightBlue = new Color(44, 62, 80); + private Color Color_WetAsphalt = new Color(52, 73, 94); + private Color Color_WhiteSmoke = new Color(245, 245, 245); + private Color Color_Emerald = new Color(46, 204, 113); + private Color Color_Alizarin = new Color(231, 76, 60); public UI() { setTitle("ParaScript"); setResizable(false); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); - setBounds(100, 100, 400, 280); + setBounds(100, 100, 400, 300); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); - setContentPane(contentPane); contentPane.setLayout(null); + contentPane.setForeground(Color_WhiteSmoke); + contentPane.setBackground(Color_MidnightBlue); + setContentPane(contentPane); JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP); - tabbedPane.setBounds(0, 0, 395, 220); + tabbedPane.setBounds(0, 0, 395, 215); contentPane.add(tabbedPane); + /* + * Login Stuff + */ + JPanel loginPanel = new JPanel(); + loginPanel.setForeground(Color_WhiteSmoke); + loginPanel.setBackground(Color_WetAsphalt); + tabbedPane.addTab("Login", null, loginPanel, null); + loginPanel.setLayout(null); + + // Username + JLabel lblUsername = new JLabel("Username:"); + lblUsername.setForeground(Color_WhiteSmoke); + lblUsername.setBounds(20, 20, 73, 20); + loginPanel.add(lblUsername); + username.setBounds(20, 40, 150, 20); + loginPanel.add(username); + + // Password + JLabel lblPassword = new JLabel("Password:"); + lblPassword.setForeground(Color_WhiteSmoke); + lblPassword.setBounds(200, 20, 73, 20); + loginPanel.add(lblPassword); + password.setBounds(200, 40, 150, 20); + loginPanel.add(password); + + // Auto Login + JLabel lblAutoLogin = new JLabel("Auto Login Enabled"); + lblAutoLogin.setForeground(Color_WhiteSmoke); + lblAutoLogin.setBounds(40, 80, 130, 20); + loginPanel.add(lblAutoLogin); + autoLogin.setBackground(Color_WetAsphalt); + autoLogin.setForeground(Color_WhiteSmoke); + autoLogin.setBounds(15, 80, 20, 20); + autoLogin.setSelected(true); + loginPanel.add(autoLogin); + JPanel woodcuttingPanel = new JPanel(); + woodcuttingPanel.setForeground(Color_WhiteSmoke); + woodcuttingPanel.setBackground(Color_WetAsphalt); tabbedPane.addTab("Woodcutting", null, woodcuttingPanel, null); woodcuttingPanel.setLayout(null); - JLabel lblUsername = new JLabel("Username:"); - lblUsername.setBounds(20, 20, 73, 20); - woodcuttingPanel.add(lblUsername); - username.setBounds(20, 40, 150, 20); - woodcuttingPanel.add(username); - - JLabel lblPassword = new JLabel("Password:"); - lblPassword.setBounds(20, 60, 73, 20); - woodcuttingPanel.add(lblPassword); - password.setBounds(20, 80, 150, 20); - woodcuttingPanel.add(password); - + /* JLabel lblLocation = new JLabel("Location"); lblLocation.setBounds(200, 20, 73, 20); woodcuttingPanel.add(lblLocation); - /* - location.setModel( - new DefaultComboBoxModel(Methods.locationToStringArray())); + location.setModel(new DefaultComboBoxModel(Methods.locationToStringArray())); location.setBounds(200, 40, 150, 20); woodcuttingPanel.add(location); */ + // Select which tree to cut JLabel lblTree = new JLabel("Tree"); - lblTree.setBounds(200, 60, 73, 20); + lblTree.setForeground(Color_WhiteSmoke); + lblTree.setBounds(20, 20, 73, 20); woodcuttingPanel.add(lblTree); - treeSelect.setModel(new DefaultComboBoxModel(Trees.toStringArray())); - treeSelect.setBounds(200, 80, 150, 20); + treeSelect.setBounds(20, 40, 150, 20); woodcuttingPanel.add(treeSelect); + /* JLabel lblMethod = new JLabel("Method"); lblMethod.setBounds(20, 120, 73, 20); woodcuttingPanel.add(lblMethod); - /* woodcutOptionButtonGroup.add(bank); bank.setSelected(true); bank.setBounds(20, 140, 80, 20); @@ -83,6 +122,7 @@ public class UI extends JFrame { woodcuttingPanel.add(drop); JLabel lblBirdsNest = new JLabel("Bird nests"); + lblBirdsNest.setForeground(WhiteSmoke); lblBirdsNest.setBounds(200, 120, 150, 20); woodcuttingPanel.add(lblBirdsNest); @@ -106,9 +146,13 @@ public class UI extends JFrame { }); */ - JButton start = new JButton("Start"); + JButton start = new JButton("START"); start.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { + if(autoLogin.isSelected() && !username.getText().equals("")) { + Variables.setAccountUsername(username.getText()); + Variables.setAccountPassword(password.getText()); + } /* for (Location loc : Location.values()) { if (loc.getName().equalsIgnoreCase(location.getSelectedItem().toString())) { @@ -121,10 +165,6 @@ public class UI extends JFrame { System.out.println(selectedTree.getName()); } } - if(!password.getText().equals("") && !username.getText().equals("")) { - Variables.setAccountUsername(username.getText()); - Variables.setAccountPassword(password.getText()); - } if (drop.isSelected()) { Variables.setDrop(true); } @@ -137,10 +177,16 @@ public class UI extends JFrame { dispose(); */ Variables.running = !Variables.running; - start.setText(Variables.running ? "pause" : "start"); + start.setText(Variables.running ? "PAUSE" : "START"); + start.setBackground(Variables.running ? Color_Alizarin : Color_Emerald); } }); - start.setBounds(0, 220, 400, 20); + start.setBackground(Color_Emerald); + start.setForeground(Color_MidnightBlue); + // these next two lines do the magic.. + start.setContentAreaFilled(false); + start.setOpaque(true); + start.setBounds(20, 220, 360, 40); contentPane.add(start); } } \ No newline at end of file