Advertisement
deww1

FuserCook.java - V. 0.5

Sep 8th, 2011
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 35.17 KB | None | 0 0
  1. import java.awt.*;
  2. import java.awt.event.KeyEvent;
  3. import java.io.BufferedReader;
  4. import java.io.IOException;
  5. import java.io.InputStreamReader;
  6. import java.lang.reflect.InvocationTargetException;
  7. import java.net.URL;
  8. import org.rsbot.event.events.MessageEvent;
  9. import org.rsbot.event.listeners.MessageListener;
  10. import org.rsbot.event.listeners.PaintListener;
  11. import org.rsbot.script.*;
  12. import org.rsbot.script.methods.*;
  13. import org.rsbot.script.wrappers.*;
  14. import java.util.Random;
  15. import javax.swing.*;
  16.  
  17. /**
  18.  *
  19.  * @author Dayghost
  20.  * @author Dew
  21.  */
  22. @ScriptManifest(authors = {"Dew"},
  23.         keywords = {"Cook"},
  24.         name = "Fuser Cooker-BETA",
  25.         description = "Cooks food for you! Currently only at Al-Kharid",
  26.         version = 0.5)
  27.        
  28. public class FuserCook extends Script implements PaintListener, MessageListener {
  29.  
  30.     // <editor-fold defaultstate="collapsed" desc="Variables">
  31.     boolean scriptRunning = true;
  32.  
  33.     boolean input = false;
  34.  
  35.     public long startTime = 0;
  36.     public long millis = 0;
  37.     public long hours = 0;
  38.     public long minutes = 0;
  39.     public long seconds = 0;
  40.  
  41.     public int mode;
  42.  
  43.     Areas areas = new Areas();
  44.     Setup set = new Setup();
  45.     WalkPaths paths = new WalkPaths();
  46.     InnerMethods methods = new InnerMethods();
  47.     antiBanThread antibanthread = new antiBanThread();
  48.     FuserCookGui g = new FuserCookGui();
  49.  
  50.     public String status = "null";
  51.  
  52.     public boolean devMode = false;
  53.     public boolean logFinish = false;
  54.  
  55.     private int itemsCooked = 0; //totol cooked
  56.     private int itemsBurned = 0; //total burned
  57.     // </editor-fold>
  58.  
  59.  
  60.     // <editor-fold defaultstate="collapsed" desc="Setup Variables">
  61.     private class Setup {
  62.  
  63.         public int toCook;
  64.         public int toCookList[] = {317, 321, 327, 345, 335, 349, 331, 359, 377, 371};
  65.         public int cookOn;
  66.         public int cookOnList[] = {25730};
  67.         public int bankId;
  68.         public int bankIdList[] = {35647};
  69.         public int areaId = 0;
  70.         public int areadIdList[] = {1};
  71.     }
  72.     // </editor-fold>
  73.    
  74.     // <editor-fold defaultstate="collapsed" desc="Areas">
  75.     private class Areas {
  76.  
  77.         // <editor-fold defaultstate="collapsed" desc="Al-Kharid Area Variables - atAllocation();">
  78.         RSArea alBankArea = new RSArea(new RSTile(3269, 3164), new RSTile(3272, 3171));
  79.         RSArea alCookArea = new RSArea(new RSTile(3272, 3179), new RSTile(3275, 3183));
  80.  
  81.         private boolean atAlbank() { //Al-Kharid bank
  82.             RSArea area1 = alBankArea;
  83.             return area1.contains(getMyPlayer().getLocation());
  84.         }
  85.  
  86.         private boolean atAlcook() { //Al-Kharid cook location
  87.             RSArea area1 = alCookArea;
  88.             return area1.contains(getMyPlayer().getLocation());
  89.         }
  90.         // </editor-fold>
  91.  
  92.         private boolean atBank() {
  93.             if (set.areaId == 1) {
  94.                 return atAlbank();
  95.             }
  96.             return false;
  97.         }
  98.         private boolean atCook() {
  99.             if (set.areaId == 1) {
  100.                 return atAlcook();
  101.             }
  102.             return false;
  103.         }
  104.  
  105.     }
  106.     // </editor-fold>
  107.  
  108.     // <editor-fold defaultstate="collapsed" desc="Walk Paths">
  109.     public class WalkPaths {
  110.  
  111.         public RSTile[] pathToCookAl = {new RSTile(3269, 3167),
  112.             new RSTile(3275, 3172),
  113.             new RSTile(3273, 3180)
  114.         };
  115.         public RSTile[] pathToBankAl = {new RSTile(3273, 3180),
  116.             new RSTile(3275, 3172),
  117.             new RSTile(3269, 3167)
  118.         };
  119.  
  120.         private void walkToBank() {
  121.             if (set.areaId == 1) {
  122.                 if (!areas.atBank()) {
  123.                     RSTilePath walkingBank = walking.newTilePath(pathToBankAl);
  124.                     walkingBank.randomize(random(1, 2), random(1, 2));
  125.                     walkingBank.traverse();
  126.                     //antiban.antiBanCamera();
  127.                     sleep(random(500, 1000));
  128.                     //timer.reset();
  129.                 }
  130.             }
  131.         }
  132.  
  133.         private void walkToCook() {
  134.             if (set.areaId == 1) {
  135.                 if (!areas.atCook()) {
  136.                     RSTilePath walkingBank = walking.newTilePath(pathToCookAl);
  137.                     walkingBank.randomize(random(1, 2), random(1, 2));
  138.                     walkingBank.traverse();
  139.                     //antiban.antiBanCamera();
  140.                     sleep(random(500, 1000));
  141.                     //timer.reset();
  142.                 }
  143.             }
  144.         }
  145.     }
  146.     // </editor-fold>
  147.  
  148.     // <editor-fold defaultstate="collapsed" desc="Methods Used">
  149.     public class InnerMethods {
  150.  
  151.         // <editor-fold defaultstate="collapsed" desc="Banking">
  152.         public int bankOpen() {
  153.             if (areas.atBank() && players.getMyPlayer().isIdle()) {
  154.                 if (set.areaId == 1) {
  155.                     RSObject bankBooth = objects.getNearest(set.bankId);
  156.                     if (random(1, 4) > 1) {
  157.                         bankBooth.interact("Use-quickly");
  158.                     } else {
  159.                         //antiban.antiban();
  160.                     }
  161.                 }
  162.             }
  163.             return random(800, 1300);
  164.         }
  165.  
  166.         public int withdrawBank() {
  167.             if (bank.getCount(set.toCook) > 0) {
  168.                 bank.withdraw(set.toCook, 0);
  169.             } else {
  170.                 log(Color.CYAN, "[SUCCESS] We have deplenished all cooking material! :)");
  171.                 stopScript();
  172.             }
  173.             return random(300, 1100);
  174.         }
  175.  
  176.         public int depositBank() {
  177.             bank.depositAll();
  178.             return random(300, 1100);
  179.         }
  180.  
  181.         public int bankClose() {
  182.             if (bank.isOpen()) {
  183.                 bank.close();
  184.                 sleep(random(200, 1000));
  185.             }
  186.             return random(300, 800);
  187.         }
  188.  
  189.         public void banking() {
  190.             if (!bank.isOpen()) {
  191.                 bankOpen();
  192.             } else {
  193.                 if (!inventory.isFull()) {
  194.                     if (!inventory.contains(set.toCook)) {
  195.                         withdrawBank();
  196.                     } else {
  197.                     }
  198.                 } else {
  199.                     if (!inventory.contains(set.toCook)) {
  200.                         depositBank();
  201.                     }
  202.                 }
  203.                 sleep(random(100, 500));
  204.             }
  205.         }
  206.         // </editor-fold>
  207.  
  208.         // <editor-fold defaultstate="collapsed" desc="Cook Method">
  209.         public void cook() {
  210.             RSItem cook = inventory.getItem(set.toCook);
  211.             RSObject cookOn = objects.getNearest(set.cookOn);
  212.             RSInterface inter = interfaces.get(905);
  213.             RSComponent com = inter.getComponent(14);
  214.             if (mode == 1) {
  215.  
  216.                 if (inter != null && inter.isValid()) {
  217.                     logger("Inter not null");
  218.                     if (com != null && com.isValid()) {
  219.                         logger("com not null");
  220.                         com.doClick(true);
  221.                         Methods.sleep(1000, 2000);
  222.                     }
  223.                 } else {
  224.                     if (cook != null && cookOn != null) {
  225.                         inventory.useItem(cook, cookOn);
  226.                         sleep(1000, 2000);
  227.                     }
  228.                 }
  229.             } else if (mode == 2) {
  230.                 if (inter != null && inter.isValid()) {
  231.                     if (com != null && com.isValid()) {
  232.                         Point p = com.getPoint();
  233.                         mouse.move(p, 40, 40);
  234.                         sleep(250, 750);
  235.                         mouse.click(true);
  236.                     }
  237.                 } else if (cook != null && cookOn != null) {
  238.                     if (random(1, 5) > 2) {
  239.                         camera.turnTo(cookOn);
  240.                     }
  241.                     inventory.useItem(cook, cookOn);
  242.                     sleep(750, 1250);
  243.                 }
  244.             }
  245.         }
  246.         // </editor-fold>
  247.  
  248.         // <editor-fold defaultstate="collapsed" desc="anim(int animID)">
  249.         public boolean anim(int animID) {
  250.             return getMyPlayer().getAnimation() == animID;
  251.         }
  252.         // </editor-fold>
  253.  
  254.         public final String fishName() {
  255.             String s = "";
  256.             switch (g.fishType.getSelectedIndex()) {
  257.                 case 0:
  258.                     s = "NULL";
  259.                     break;
  260.                 case 1:
  261.                     s = "Shrimp";
  262.                     break;
  263.                 case 2:
  264.                     s = "Anchovies";
  265.                     break;
  266.                 case 3:
  267.                     s = "Sardine";
  268.                     break;
  269.                 case 4:
  270.                     s = "Herring";
  271.                     break;
  272.                 case 5:
  273.                     s = "Trout";
  274.                     break;
  275.                 case 6:
  276.                     s = "Pike";
  277.                     break;
  278.                 case 7:
  279.                     s = "Salmon";
  280.                     break;
  281.                 case 8:
  282.                     s = "Tuna";
  283.                     break;
  284.                 case 9:
  285.                     s = "Lobster";
  286.                     break;
  287.                 case 10:
  288.                     s = "Swordfish";
  289.                     break;
  290.             }
  291.             return s;
  292.         }
  293.     }
  294.     // </editor-fold>
  295.  
  296.     // <editor-fold defaultstate="collapsed" desc="createandwaitGUI st00f">
  297.     private void createAndWaitForGUI() {
  298.         if (SwingUtilities.isEventDispatchThread()) {
  299.             g.setResizable(false);
  300.             g.setVisible(true);
  301.         } else {
  302.             try {
  303.                 SwingUtilities.invokeAndWait(new Runnable() {
  304.  
  305.                     public void run() {
  306.                         g.setResizable(false);
  307.                         g.setVisible(true);
  308.                     }
  309.                 });
  310.             } catch (InvocationTargetException e) {
  311.                 log.warning("InvocationTargetExpection Error!!");
  312.                 log(e);
  313.                 log.warning("InvocationTargetExpection Error!!");
  314.             } catch (InterruptedException x) {
  315.                 log.warning("InterruptionException Error!!");
  316.                 log(x);
  317.                 log.warning("InterruptionException Error!!");
  318.             }
  319.         }
  320.         sleep(1000);
  321.         while (g.isVisible()) {
  322.             sleep(1000);
  323.         }
  324.     }
  325.     // </editor-fold>
  326.  
  327.  
  328.     private enum Action {
  329.         WALKTOBANK, OPENBANK, COOKFOOD, WAITWHILECOOKING, WALKTOCOOK, SLEEP, UNKNOWN;
  330.     }
  331.  
  332.     // <editor-fold defaultstate="collapsed" desc="Get Action">
  333.     /**
  334.      * Try to make as much logic as possible happen here instead of in the loop.
  335.      *
  336.      * @return Action
  337.      */
  338.     public Action getAction() {
  339.         try {
  340.             if (game.getClientState() != 11) {
  341.                 return Action.SLEEP;
  342.             } else {
  343.                 if (inventory.contains(set.toCook)) {
  344.                     //logger("Inventory does contain food");
  345.                     if (areas.atBank()) {
  346.                         //  logger("Walk To Cook");
  347.                         return Action.WALKTOCOOK;
  348.                     } else if (areas.atCook()) {
  349.                         if (methods.anim(896) && !inventory.containsAll(set.toCook)
  350.                                 || methods.anim(896) || !inventory.containsAll(set.toCook)) {
  351.                             //    logger("Cook Food");
  352.                             return Action.WAITWHILECOOKING;
  353.                         } else if (inventory.containsAll(set.toCook) && !methods.anim(896)) {
  354.                             //  logger("Cook Food");
  355.                             return Action.COOKFOOD;
  356.                         } else {
  357.                             return Action.WAITWHILECOOKING;
  358.                         }
  359.                     } else {
  360.                         //logger("Else: Walk to Cook");
  361.                         return Action.WALKTOCOOK;
  362.                     }
  363.                 } else {
  364.                     //logger("Inventory does not contain food");
  365.                     if (areas.atCook()) {
  366.                         //  logger("Walk to Bank");
  367.                         return Action.WALKTOBANK;
  368.                     } else if (areas.atBank()) {
  369.                         //logger("Banking");
  370.                         return Action.OPENBANK;
  371.                     } else {
  372.                         //logger("Else: Walk to Bank");
  373.                         return Action.WALKTOBANK;
  374.                     }
  375.                 }
  376.             }
  377.         } catch (final Exception e) {
  378.             return Action.UNKNOWN;
  379.         }
  380.     }
  381.     // </editor-fold>
  382.  
  383.     @Override
  384.     public boolean onStart() {
  385.         createAndWaitForGUI();
  386.         startTime = System.currentTimeMillis();
  387.         mode = g.mode.getSelectedIndex();
  388.         devMode = g.devMode.isSelected();
  389.         logFinish = g.logBurnCook.isSelected();
  390.         set.areaId = set.areadIdList[0];
  391.         set.toCook = set.toCookList[g.fishType.getSelectedIndex()-1];
  392.         set.bankId = set.bankIdList[0];
  393.         set.cookOn = set.cookOnList[0];
  394.         log("We will be cooking: "+methods.fishName());
  395.         logger("FishCookID: "+set.toCook);
  396.         logger("Mode: "+mode);
  397.         antibanthread.start();
  398.         if (set.areaId == 0) {
  399.             return false;
  400.         }
  401.         return true;
  402.     }
  403.    
  404.     public int loop() {
  405.         if (scriptRunning) {
  406.             try {
  407.                 mouse.setSpeed(Methods.random(4, 7));
  408.                 switch (getAction()) {
  409.                     case WALKTOBANK:
  410.                         paths.walkToBank();
  411.                         status = "Walking to Bank";
  412.                         break;
  413.                     case WALKTOCOOK:
  414.                         paths.walkToCook();
  415.                         status = "Walking to Cook";
  416.                         break;
  417.                     case COOKFOOD:
  418.                         methods.cook();
  419.                         if (mode == 1) {
  420.                             Methods.sleep(1000, 2000);
  421.                         }
  422.                         status = "Cooking Food";
  423.                         break;
  424.                     case WAITWHILECOOKING:
  425.                         Methods.sleep(1000,3000);
  426.                         break;
  427.                     case OPENBANK:
  428.                         methods.banking();
  429.                         status = "Banking";
  430.                         break;
  431.                     case SLEEP:
  432.                         Methods.sleep(1000, 2000);
  433.                         status = "Waiting";
  434.                         break;
  435.                 }
  436.             } catch (final Exception e) {
  437.                 return 25;
  438.             }
  439.         }
  440.         return Methods.random(400,1100);
  441.     }
  442.  
  443.     @Override
  444.     public void onFinish() {
  445.         if (logFinish) {
  446.             log("We Burned: "+itemsBurned);
  447.             log("We Cooked: "+itemsCooked);
  448.             if (itemsCooked > 0 && itemsBurned > 0) {
  449.                 log("Cook/Burn Ratio: " + itemsCooked / itemsBurned);
  450.             } else if (itemsCooked > 0 && itemsBurned == 0) {
  451.                 log("Cook/Burn Ratio: 1");
  452.             }
  453.         }
  454.         for (int Tries = 0; antibanthread.isAlive(); Tries++) {
  455.             if (Tries > 2400) {
  456.                 antibanthread.interrupt();
  457.                 Methods.sleep(25);
  458.                 if (antibanthread.isInterrupted()) {
  459.                     break;
  460.                 } else if (Tries > 4800) {
  461.                     break;
  462.                 }
  463.             } else {
  464.                 antibanthread.stopThread = true;
  465.                 Methods.sleep(25);
  466.                 if (antibanthread.isInterrupted()) {
  467.                     break;
  468.                 }
  469.             }
  470.         }        
  471.         scriptRunning = false;
  472.     }
  473.    
  474.     /**
  475.      * NOTE: Only logs if in devMode
  476.      * @param text the string to send
  477.      * @return true if successfully sent
  478.      */
  479.     public void logger(String text) {
  480.         if (devMode) {
  481.             log(Color.GREEN, "[DEBUG]: "+text);
  482.         }
  483.     }
  484.  
  485.     // <editor-fold defaultstate="collapsed" desc="Paint">
  486.     private final Color restCol3 = new Color(255, 255, 255);
  487.     private final Font restFont = new Font("Calibri", 0, 12);
  488.  
  489.     public void onRepaint(Graphics g1) {
  490.         millis = System.currentTimeMillis() - startTime;
  491.         hours = millis / (1000 * 60 * 60);
  492.         millis -= hours * (1000 * 60 * 60);
  493.         minutes = millis / (1000 * 60);
  494.         millis -= minutes * (1000 * 60);
  495.         seconds = millis / 1000;
  496.  
  497.         Graphics2D g = (Graphics2D) g1;
  498.         g.setFont(restFont);
  499.         g.setColor(restCol3);
  500.         g.drawString("Status: " + status, 357, 330);
  501.         g.drawString("Cooked: " + itemsCooked, 357, 330 - 15);
  502.         g.drawString("Burned: " + itemsBurned, 357, 330 - 30);
  503.         g.drawString("Time Ran: " + hours + ":" + minutes + ":" + seconds, 357, 330 - 45);
  504.         g.drawString("Mode: "+mode, 357, 330-60);
  505.     }
  506.     // </editor-fold>
  507.  
  508.     // <editor-fold defaultstate="collapsed" desc="MessageListener">
  509.     public void messageReceived(MessageEvent e) {
  510.         String x = e.getMessage().toLowerCase();
  511.         if (x.contains("success")) {
  512.             itemsCooked++;
  513.         } else if (x.contains("accidentally burn the")) {
  514.             itemsBurned++;
  515.         }
  516.     }
  517.     // </editor-fold>
  518.    
  519.     // <editor-fold defaultstate="collapsed" desc="Looped Antiban">
  520.     /**
  521.      * Looped antiBan version 1.00
  522.      *
  523.      * @Author Ubuntu4life
  524.      */
  525.     private void antiBan() {
  526.         // CHANGE randomInteger to tune the frequency of the antiBan.
  527.         final int randomInteger = Methods.random(1, 11);
  528.         switch (randomInteger) {
  529.             case 1:
  530.                 // CHANGE this random integer generator to tune the relative
  531.                 // distribution of antiBan actions.
  532.                 if (Methods.random(1, 17) != 1) {
  533.                     break;
  534.                 } else {
  535.                     mouse.move(random(10, 750), random(10, 495));
  536.                     if (Methods.random(1, 7) == 1) {
  537.                         mouse.move(random(10, 750), random(10, 495));
  538.                     }
  539.                 }
  540.                 break;
  541.             case 2:
  542.                 if (Methods.random(1, 12) != 1) {
  543.                     break;
  544.                 } else {
  545.                     mouse.moveSlightly();
  546.                 }
  547.                 break;
  548.             case 3:
  549.                 if (Methods.random(1, 18) != 1) {
  550.                     break;
  551.                 } else {
  552.                     if (Methods.random(1, 11) == 1) {
  553.                         camera.setPitch(true);
  554.                     }
  555.                     int angle = camera.getAngle() + Methods.random(-45, 45);
  556.                     if (angle < 0) {
  557.                         angle = Methods.random(0, 10);
  558.                     }
  559.                     if (angle > 359) {
  560.                         angle = Methods.random(0, 10);
  561.                     }
  562.                     char Direction = 37;
  563.                     if (Methods.random(0, 100) < 50) {
  564.                         Direction = 39;
  565.                     }
  566.                     keyboard.pressKey(Direction);
  567.                     Methods.sleep(Methods.random(100, 700));
  568.                     keyboard.releaseKey(Direction);
  569.                 }
  570.                 break;
  571.             default:
  572.                 return;
  573.         }
  574.     }
  575.     // </editor-fold>
  576.    
  577.     // <editor-fold defaultstate="collapsed" desc="Threaded Antiban">
  578.     /**
  579.      * Multi-threaded antiBan version 1.00
  580.      *
  581.      * @Author Ubuntu4life
  582.      */
  583.     private class antiBanThread extends Thread {
  584.  
  585.         private volatile boolean stopThread = false;
  586.         Random javaUtilRandom = new Random();
  587.  
  588.         @Override
  589.         public void run() {
  590.             try {
  591.                 while (!stopThread && !isPaused()
  592.                         && game.isLoggedIn()) {
  593.                     // CHANGE this integer to tune the frequency of the antiBan
  594.                     if (javaUtilRandom.nextInt(Math.abs(0 - 21)) == 1) {
  595.                         final char[] leftRight = new char[]{KeyEvent.VK_LEFT,
  596.                             KeyEvent.VK_RIGHT};
  597.                         final char[] upDown = new char[]{KeyEvent.VK_DOWN,
  598.                             KeyEvent.VK_UP};
  599.                         final char[] leftRightUpDown = new char[]{
  600.                             KeyEvent.VK_LEFT, KeyEvent.VK_RIGHT,
  601.                             KeyEvent.VK_UP, KeyEvent.VK_UP};
  602.                         final int random1 = javaUtilRandom.nextInt(Math.abs(2 - 0));
  603.                         final int random2 = javaUtilRandom.nextInt(Math.abs(2 - 0));
  604.                         final int random3 = javaUtilRandom.nextInt(Math.abs(4 - 0));
  605.                         boolean didLeftRight = false;
  606.                         if (javaUtilRandom.nextInt(Math.abs(3 - 0)) == 1) {
  607.                             if (random(0, 5) != 1) {
  608.                                 keyboard.pressKey(leftRight[random1]);
  609.                                 Thread.sleep(javaUtilRandom.nextInt(Math.abs(101 - 402)));
  610.                                 didLeftRight = true;
  611.                             }
  612.                             keyboard.pressKey(upDown[random2]);
  613.                             Thread.sleep(javaUtilRandom.nextInt(Math.abs(301 - 601)));
  614.                             keyboard.releaseKey(upDown[random2]);
  615.                             Thread.sleep(javaUtilRandom.nextInt(Math.abs(99 - 399)));
  616.                             if (didLeftRight) {
  617.                                 keyboard.releaseKey(leftRight[random1]);
  618.                             }
  619.                         } else {
  620.                             keyboard.pressKey(leftRightUpDown[random3]);
  621.                             if (random3 > 1) {
  622.                                 Thread.sleep(javaUtilRandom.nextInt(Math.abs(601 - 298)));
  623.                             } else {
  624.                                 Thread.sleep(javaUtilRandom.nextInt(Math.abs(903 - 501)));
  625.                             }
  626.                             keyboard.releaseKey(leftRightUpDown[random3]);
  627.                         }
  628.                     } else {
  629.                         Thread.sleep(javaUtilRandom.nextInt(Math.abs(2004 - 198)));
  630.                     }
  631.                 }
  632.             } catch (final Exception e) {
  633.             }
  634.         }
  635.     }
  636.     // </editor-fold>
  637.  
  638.     // <editor-fold defaultstate="collapsed" desc="FuserCookGui">
  639.     public class FuserCookGui extends javax.swing.JFrame {
  640.  
  641.         // <editor-fold defaultstate="collapsed" desc="TWITTER STUFF">
  642.         public final String TWITTER_NAME = ""; //name of the twitter account
  643.         public String loadTwitterName = null; //the name that is displayed at beginning of the text field.
  644.         public String loadTwitterUpdate = null; //the actual twitter update that will be viewed.
  645.         public boolean tweetsLoaded = false; //true if the twitter update was loaded successfully
  646.  
  647.         // <editor-fold defaultstate="collapsed" desc="Twitter Updateer">
  648.         public final void loadTweets(int count) {
  649.             loadTwitterName = "" + TWITTER_NAME; //initializes the twitter name
  650.  
  651.             final StringBuilder url = new StringBuilder(); //will build the following URL
  652.             url.append("http://scripters.powerbot.org/files/316383/scriptdir/fusercook/msgdew.xml");
  653.             //url.append(TWITTER_NAME);
  654.             //url.append("&count=");
  655.             //url.append(count); //this is what the program will load to view the twitter update
  656.  
  657.             InputStreamReader stream = null;
  658.             BufferedReader reader = null;
  659.  
  660.             try {
  661.                 stream = new InputStreamReader(new URL(url.toString()).openStream()); //sets our stream to open a stream to url above
  662.                 reader = new BufferedReader(stream); //reads the webpage
  663.                 String s;
  664.                 int c = 0;
  665.                 while ((s = reader.readLine()) != null) { //while reader can read
  666.                     final String a = "<text>", b = "</text>";
  667.                     int x = s.indexOf(a);
  668.                     if (x == -1) {
  669.                         continue;
  670.                     }
  671.                     x += a.length();
  672.                     final int y = s.indexOf(b, x);
  673.                     if (y == -1) {
  674.                         continue;
  675.                     }
  676.                     String msg = s.substring(x, y).trim(); //s, the actual message, will cut off <text> and </text> and trim out all unneeded spaces
  677.                     //                if (!msg.contains(HASHTAG)) { //if hashtag is not there, it's done
  678.                     //                    continue;
  679.                     //                }
  680.                     //                if (msg.endsWith(HASHTAG)) { //if it has hashtag, set message
  681.                     //                    msg = msg.substring(0, msg.length() - HASHTAG.length()).trim(); //sets the message, to msg's substring with length, without the hashtag trimmed
  682.                     //                }
  683.                     if (msg.isEmpty()) { //if the msg is empty, we're done.
  684.                         msg = "There is no message at this moment!";
  685.                         continue;
  686.                     }
  687.                     if (msg == null) {
  688.                         msg = "There is no message at this moment!";
  689.                     }
  690.                     loadTwitterUpdate = loadTwitterName + "" + msg; //sets the update to the message visible
  691.                     if (++c == count) { //count is how many to check
  692.                         break;
  693.                     }
  694.                     tweetsLoaded = true; //tells the program that the tweets were successfully loaded.
  695.                 }
  696.             } catch (final IOException ignored) {
  697.  
  698.             } finally {
  699.                 try {
  700.                     if (reader != null) {
  701.                         reader.close();
  702.                     }
  703.                     if (stream != null) {
  704.                         stream.close();
  705.                     }
  706.                 } catch (final IOException ignored) {
  707.  
  708.                 }
  709.             }
  710.         }
  711.         // </editor-fold>
  712.         // </editor-fold>
  713.  
  714.         /** Creates new form FuserCookGui */
  715.         public FuserCookGui() {
  716.             this.loadTweets(5);
  717.             initComponents();
  718.         }
  719.  
  720.         /** This method is called from within the constructor to
  721.          * initialize the form.
  722.          * WARNING: Do NOT modify this code. The content of this method is
  723.          * always regenerated by the Form Editor.
  724.          */
  725.         @SuppressWarnings("unchecked")
  726.         // <editor-fold defaultstate="collapsed" desc="Generated Code">
  727.     private void initComponents() {
  728.  
  729.         jLabel1 = new javax.swing.JLabel();
  730.         start = new javax.swing.JButton();
  731.         mode = new javax.swing.JComboBox();
  732.         jScrollPane1 = new javax.swing.JScrollPane();
  733.         modeDesc = new javax.swing.JTextArea();
  734.         devMode = new javax.swing.JCheckBox();
  735.         msgfromdew = new javax.swing.JTextField();
  736.         jLabel2 = new javax.swing.JLabel();
  737.         fishType = new javax.swing.JComboBox();
  738.         jLabel3 = new javax.swing.JLabel();
  739.         logBurnCook = new javax.swing.JCheckBox();
  740.  
  741.         setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
  742.         setTitle("Fuser Cook GUI");
  743.         setAlwaysOnTop(true);
  744.  
  745.         jLabel1.setFont(new java.awt.Font("Calibri", 1, 18)); // NOI18N
  746.         jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
  747.         jLabel1.setText("Temporary GUI & Paint");
  748.         jLabel1.setName("jLabel1"); // NOI18N
  749.  
  750.         start.setFont(new java.awt.Font("Calibri", 1, 14)); // NOI18N
  751.         start.setText("Start Script");
  752.         start.setName("start"); // NOI18N
  753.         start.addActionListener(new java.awt.event.ActionListener() {
  754.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  755.                 startActionPerformed(evt);
  756.             }
  757.         });
  758.  
  759.         mode.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Select a Mode", "Mode 1", "Mode 2" }));
  760.         mode.setName("mode"); // NOI18N
  761.         mode.addActionListener(new java.awt.event.ActionListener() {
  762.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  763.                 modeActionPerformed(evt);
  764.             }
  765.         });
  766.  
  767.         jScrollPane1.setName("jScrollPane1"); // NOI18N
  768.  
  769.         modeDesc.setColumns(20);
  770.         modeDesc.setEditable(false);
  771.         modeDesc.setLineWrap(true);
  772.         modeDesc.setRows(5);
  773.         modeDesc.setText("Please Select a Mode!");
  774.         modeDesc.setWrapStyleWord(true);
  775.         modeDesc.setName("modeDesc"); // NOI18N
  776.         jScrollPane1.setViewportView(modeDesc);
  777.  
  778.         devMode.setText("Debug Mode");
  779.         devMode.setName("devMode"); // NOI18N
  780.  
  781.         msgfromdew.setEditable(false);
  782.         msgfromdew.setText(loadTwitterUpdate);
  783.         msgfromdew.setName("msgfromdew"); // NOI18N
  784.  
  785.         jLabel2.setText("Message From Dew");
  786.         jLabel2.setName("jLabel2"); // NOI18N
  787.  
  788.         fishType.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Pick a Fish", "Shrimp", "Anchovies", "Sardine", "Herring", "Trout", "Pike", "Salmon", "Tuna", "Lobster", "Swordfish" }));
  789.         fishType.setName("fishType"); // NOI18N
  790.  
  791.         jLabel3.setText("Fish Type:");
  792.         jLabel3.setName("jLabel3"); // NOI18N
  793.  
  794.         logBurnCook.setText("Log Burned/Cooked");
  795.         logBurnCook.setName("logBurnCook"); // NOI18N
  796.  
  797.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  798.         getContentPane().setLayout(layout);
  799.         layout.setHorizontalGroup(
  800.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  801.             .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
  802.             .addGroup(layout.createSequentialGroup()
  803.                 .addContainerGap()
  804.                 .addComponent(mode, 0, 380, Short.MAX_VALUE)
  805.                 .addContainerGap())
  806.             .addComponent(start, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
  807.             .addGroup(layout.createSequentialGroup()
  808.                 .addContainerGap()
  809.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  810.                     .addGroup(layout.createSequentialGroup()
  811.                         .addComponent(devMode)
  812.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  813.                         .addComponent(logBurnCook, javax.swing.GroupLayout.DEFAULT_SIZE, 130, Short.MAX_VALUE)
  814.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  815.                         .addComponent(jLabel3)
  816.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  817.                         .addComponent(fishType, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE))
  818.                     .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE))
  819.                 .addContainerGap())
  820.             .addGroup(layout.createSequentialGroup()
  821.                 .addContainerGap()
  822.                 .addComponent(jLabel2)
  823.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  824.                 .addComponent(msgfromdew, javax.swing.GroupLayout.DEFAULT_SIZE, 283, Short.MAX_VALUE)
  825.                 .addContainerGap())
  826.         );
  827.         layout.setVerticalGroup(
  828.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  829.             .addGroup(layout.createSequentialGroup()
  830.                 .addComponent(jLabel1)
  831.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  832.                 .addComponent(mode, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  833.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  834.                 .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
  835.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  836.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  837.                     .addComponent(devMode)
  838.                     .addComponent(fishType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  839.                     .addComponent(jLabel3)
  840.                     .addComponent(logBurnCook))
  841.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 13, Short.MAX_VALUE)
  842.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  843.                     .addComponent(msgfromdew, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  844.                     .addComponent(jLabel2))
  845.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  846.                 .addComponent(start, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE))
  847.         );
  848.  
  849.         pack();
  850.     }// </editor-fold>
  851.  
  852.         private void startActionPerformed(java.awt.event.ActionEvent evt) {
  853.             if (mode.getSelectedIndex() == 0) {
  854.                 JOptionPane j = new JOptionPane();
  855.                 j.showMessageDialog(rootPane, "You must select a mode before continuing!", "WARNING:", j.WARNING_MESSAGE);
  856.                 return;
  857.             }
  858.             if (fishType.getSelectedIndex() == 0) {
  859.                 JOptionPane j = new JOptionPane();
  860.                 j.showMessageDialog(rootPane, "You must select a Fish Type before continuing!", "WARNING:", j.WARNING_MESSAGE);
  861.                 return;
  862.             }
  863.             setVisible(false);
  864.         }
  865.  
  866.         private void modeActionPerformed(java.awt.event.ActionEvent evt) {
  867.             if (mode.getSelectedIndex() == 0) {
  868.                 modeDesc.setText("You must first select a Mode to use!");
  869.             } else if (mode.getSelectedIndex() == 1) {
  870.                 modeDesc.setText("Mode 1:\n"
  871.                         + "This mode uses interfaces, so is more accurate than Mode 2");
  872.             } else if (mode.getSelectedIndex() == 2) {
  873.                 modeDesc.setText("Mode 2:\n"
  874.                         + "This mode uses mouse movements, meaning it is more optimized for speed.");
  875.             }
  876.         }
  877.         // Variables declaration - do not modify
  878.         protected javax.swing.JCheckBox devMode;
  879.         protected javax.swing.JComboBox fishType;
  880.         protected javax.swing.JLabel jLabel1;
  881.         protected javax.swing.JLabel jLabel2;
  882.         protected javax.swing.JLabel jLabel3;
  883.         protected javax.swing.JScrollPane jScrollPane1;
  884.         protected javax.swing.JCheckBox logBurnCook;
  885.         protected javax.swing.JComboBox mode;
  886.         protected javax.swing.JTextArea modeDesc;
  887.         protected javax.swing.JTextField msgfromdew;
  888.         protected javax.swing.JButton start;
  889.         // End of variables declaration
  890.     }
  891.     // </editor-fold>
  892. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement