Exemplo n.º 1
0
 public Bot getBot(final Object o) {
   final ClassLoader cl = o.getClass().getClassLoader();
   for (final Bot bot : bots) {
     if (cl == bot.getLoader().getClient().getClass().getClassLoader()) {
       panel.offset();
       return bot;
     }
   }
   return null;
 }
Exemplo n.º 2
0
 private void init() {
   setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
   addWindowListener(
       new WindowAdapter() {
         @Override
         public void windowClosing(final WindowEvent e) {
           cleanExit();
         }
       });
   addWindowStateListener(
       new WindowStateListener() {
         public void windowStateChanged(final WindowEvent arg0) {
           switch (arg0.getID()) {
             case WindowEvent.WINDOW_ICONIFIED:
               lessCpu(true);
               break;
             case WindowEvent.WINDOW_DEICONIFIED:
               lessCpu(false);
               break;
           }
         }
       });
   setIconImage(Configuration.getImage(Configuration.Paths.Resources.ICON));
   JPopupMenu.setDefaultLightWeightPopupEnabled(false);
   WindowUtil.setFrame(this);
   panel = new BotPanel();
   menuBar = new BotMenuBar(this);
   toolBar = new BotToolBar(this, menuBar);
   panel.setFocusTraversalKeys(0, new HashSet<AWTKeyStroke>());
   new BotKeyboardShortcuts(KeyboardFocusManager.getCurrentKeyboardFocusManager(), this, this);
   menuBar.setBot(null);
   setJMenuBar(menuBar);
   textScroll =
       new JScrollPane(
           TextAreaLogHandler.TEXT_AREA,
           ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
           ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
   textScroll.setBorder(null);
   textScroll.setPreferredSize(new Dimension(PANEL_WIDTH, 120));
   textScroll.setVisible(true);
   JScrollPane scrollableBotPanel = new JScrollPane(panel);
   add(toolBar, BorderLayout.NORTH);
   add(scrollableBotPanel, BorderLayout.CENTER);
   add(textScroll, BorderLayout.SOUTH);
 }
Exemplo n.º 3
0
 public void actionPerformed(final ActionEvent evt) {
   final String action = evt.getActionCommand();
   final String menu, option;
   final int z = action.indexOf('.');
   if (z == -1) {
     menu = action;
     option = "";
   } else {
     menu = action.substring(0, z);
     option = action.substring(z + 1);
   }
   if (menu.equals(Messages.CLOSEBOT)) {
     final int idx = Integer.parseInt(option);
     removeBot(bots.get(idx));
   } else if (menu.equals(Messages.FILE)) {
     if (option.equals(Messages.NEWBOT)) {
       addBot();
     } else if (option.equals(Messages.CLOSEBOT)) {
       removeBot(getCurrentBot());
     } else if (option.equals(Messages.ADDSCRIPT)) {
       final String pretext = "";
       final String key =
           (String)
               JOptionPane.showInputDialog(
                   this,
                   "Enter the script URL e.g. pastebin link or direct compiled file:",
                   option,
                   JOptionPane.QUESTION_MESSAGE,
                   null,
                   null,
                   pretext);
       if (!(key == null || key.trim().isEmpty())) {
         ScriptDownloader.save(key);
       }
     } else if (option.equals(Messages.RUNSCRIPT)) {
       final Bot current = getCurrentBot();
       if (current != null) {
         showScriptSelector(current);
       }
     } else if (option.equals(Messages.STOPSCRIPT)) {
       final Bot current = getCurrentBot();
       if (current != null) {
         showStopScript(current);
       }
     } else if (option.equals(Messages.PAUSESCRIPT)) {
       final Bot current = getCurrentBot();
       if (current != null) {
         pauseScript(current);
       }
     } else if (option.equals(Messages.SAVESCREENSHOT)) {
       final Bot current = getCurrentBot();
       if (current != null && current.getMethodContext() != null) {
         ScreenshotUtil.saveScreenshot(current, current.getMethodContext().game.isLoggedIn());
       }
     } else if (option.equals(Messages.HIDE)) {
       setTray();
     } else if (option.equals(Messages.EXIT)) {
       cleanExit();
     }
   } else if (menu.equals(Messages.EDIT)) {
     if (option.equals(Messages.ACCOUNTS)) {
       AccountManager.getInstance().showGUI();
     } else {
       final Bot current = getCurrentBot();
       if (current != null) {
         if (option.equals(Messages.FORCEINPUT)) {
           current.overrideInput = ((JCheckBoxMenuItem) evt.getSource()).isSelected();
           updateScriptControls();
         } else if (option.equals(Messages.LESSCPU)) {
           current.disableRendering = ((JCheckBoxMenuItem) evt.getSource()).isSelected();
         } else if (option.equals(Messages.DISABLECANVAS)) {
           current.disableGraphics = ((JCheckBoxMenuItem) evt.getSource()).isSelected();
         } else if (option.equals(Messages.EXTDVIEWS)) {
           menuBar.setExtendedView(((JCheckBoxMenuItem) evt.getSource()).isSelected());
         } else if (option.equals(Messages.DISABLEANTIRANDOMS)) {
           current.disableRandoms = ((JCheckBoxMenuItem) evt.getSource()).isSelected();
         } else if (option.equals(Messages.DISABLEAUTOLOGIN)) {
           current.disableAutoLogin = ((JCheckBoxMenuItem) evt.getSource()).isSelected();
         } else if (option.equals(Messages.DISABLETHEME)) {
           Preferences.getInstance().theme = !((JCheckBoxMenuItem) evt.getSource()).isSelected();
           log.info(
               "Themes will be "
                   + (Preferences.getInstance().theme ? "enabled" : "disabled")
                   + " next time you run the application");
         } else if (option.equals(Messages.DISABLEADS)) {
           Preferences.getInstance().hideAds = ((JCheckBoxMenuItem) evt.getSource()).isSelected();
         }
       }
     }
   } else if (menu.equals(Messages.VIEW)) {
     final Bot current = getCurrentBot();
     final boolean selected = ((JCheckBoxMenuItem) evt.getSource()).isSelected();
     if (option.equals(Messages.HIDETOOLBAR)) {
       toggleViewState(toolBar, selected);
     } else if (option.equals(Messages.HIDELOGPANE)) {
       toggleViewState(textScroll, selected);
     } else if (current != null) {
       if (option.equals(Messages.ALLDEBUGGING)) {
         for (final String key : BotMenuBar.DEBUG_MAP.keySet()) {
           final Class<?> el = BotMenuBar.DEBUG_MAP.get(key);
           if (menuBar.getCheckBox(key).isVisible()) {
             final boolean wasSelected = menuBar.getCheckBox(key).isSelected();
             menuBar.getCheckBox(key).setSelected(selected);
             if (selected) {
               if (!wasSelected) {
                 current.addListener(el);
               }
             } else {
               if (wasSelected) {
                 current.removeListener(el);
               }
             }
           }
         }
       } else {
         final Class<?> el = BotMenuBar.DEBUG_MAP.get(option);
         menuBar.getCheckBox(option).setSelected(selected);
         if (selected) {
           current.addListener(el);
         } else {
           menuBar.getCheckBox(Messages.ALLDEBUGGING).setSelected(false);
           current.removeListener(el);
         }
       }
     }
   } else if (menu.equals(Messages.TOOLS)) {
     if (option.equals(Messages.LICENSES)) {
       log.warning("License manager coming soon");
     }
   } else if (menu.equals(Messages.HELP)) {
     if (option.equals(Messages.SITE)) {
       openURL(Configuration.Paths.URLs.SITE);
     } else if (option.equals(Messages.PROJECT)) {
       openURL(Configuration.Paths.URLs.PROJECT);
     } else if (option.equals(Messages.LICENSE)) {
       openURL(Configuration.Paths.URLs.LICENSE);
     } else if (option.equals(Messages.ABOUT)) {
       JOptionPane.showMessageDialog(
           this,
           new String[] {
             "An open source bot developed by the community.",
             "",
             "RuneScape® is a trademark of Jagex © 1999 - 2011 Jagex, Ltd.",
             "RuneScape content and materials are trademarks and copyrights of Jagex or its licensees.",
             "This program is issued with no warranty and is not affiliated with Jagex Ltd., nor do they endorse usage of our software.",
             "",
             "Visit " + Configuration.Paths.URLs.SITE + "/ for more information."
           },
           option,
           JOptionPane.INFORMATION_MESSAGE);
     }
   } else if (menu.equals("Tab")) {
     final Bot curr = getCurrentBot();
     menuBar.setBot(curr);
     panel.setBot(curr);
     panel.repaint();
     toolBar.setHome(curr == null);
     setTitle(curr == null ? null : curr.getAccountName());
     updateScriptControls();
   }
 }