megaalgos

MegaPlanker 1.1

Apr 8th, 2012
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 22.26 KB | None | 0 0
  1. //Version 1.1
  2. /**
  3.  * Made failsafes for my methods so the script doesnt just sit there.
  4.  * Made the running method as efficient as I could think it.
  5.  */
  6. import java.awt.*;
  7. import java.awt.event.ActionEvent;
  8. import java.awt.event.ActionListener;
  9. import java.awt.event.KeyEvent;
  10. import java.awt.image.BufferedImage;
  11. import java.io.BufferedInputStream;
  12. import java.io.BufferedOutputStream;
  13. import java.io.BufferedReader;
  14. import java.io.File;
  15. import java.io.FileOutputStream;
  16. import java.io.IOException;
  17. import java.io.InputStreamReader;
  18. import java.net.MalformedURLException;
  19. import java.net.URL;
  20. import java.text.DecimalFormat;
  21.  
  22. import javax.imageio.ImageIO;
  23. import javax.swing.*;
  24.  
  25. import com.rarebot.script.Script;
  26. import com.rarebot.client.m;
  27. import com.rarebot.event.events.MessageEvent;
  28. import com.rarebot.event.listeners.*;
  29. import com.rarebot.script.ScriptManifest;
  30. import com.rarebot.script.methods.Game.Tab;
  31. import com.rarebot.script.wrappers.*;
  32.  
  33. // Script Info
  34. @ScriptManifest(authors = { "MegaAlgos" }, version = 1.1, keywords = ("Money Making"), description = "Makes planks at Varrock East", name = "MegaPlanker")
  35. public class MegaPlanker extends Script implements PaintListener,
  36. MessageListener {
  37.  
  38.     // Script Info for paint and proggies...
  39.     public double getVersion() {
  40.         return (1.1);
  41.     }
  42.  
  43.     public String getName() {
  44.         return ("MegaPlanker");
  45.     }
  46.  
  47.     public String getAuthor() {
  48.         return ("MegaAlgos");
  49.     }
  50.  
  51.     // Script Variables
  52.     RSNPC banker, operator;
  53.     int gePrice = 0, moneyMade, profitHour, planks, counter, fullPrice,
  54.             emptyPrice;
  55.     int pID, lID, iComponent;
  56.     String status, pName, fName;
  57.     String[] list = { "Wood plank", "Oak plank", "Teak plank", "Mahogany Plank" };
  58.     private static final String GE_URL = "http://services.runescape.com/m=itemdb_rs/g=runescape/viewitem.ws?obj=";
  59.     long startTime, checkForFilling;
  60.     double work = 0;
  61.     boolean start = false, fOnScreen = false,
  62.             startUP = false;
  63.     int vP;
  64.     int jP;
  65.     int buP;
  66.     int boP;
  67.     Image arrow = null;
  68.     RSTile[] tO = { new RSTile(3267, 3428), new RSTile(3278, 3436),
  69.             new RSTile(3285, 3449), new RSTile(3290, 3463),
  70.             new RSTile(3299, 3476), new RSTile(3302, 3490) },
  71.             tB = { new RSTile(3293, 3478), new RSTile(3286, 3460),
  72.             new RSTile(3282, 3444), new RSTile(3276, 3429),
  73.             new RSTile(3263, 3429), new RSTile(3253, 3420) };
  74.  
  75.     // What it does on the start of the script
  76.     public boolean onStart() {
  77.         mouse.setSpeed(7);
  78.         startTime = System.currentTimeMillis();
  79.         log("MegaPlanker! Aimed to make you planks... hours on end");
  80.         java.awt.EventQueue.invokeLater(new Runnable() {
  81.             @Override
  82.             public void run() {
  83.                 new MegaGUI().setVisible(true);
  84.             }
  85.         });
  86.  
  87.         if (getOVersion() != getVersion()) {
  88.             java.awt.EventQueue.invokeLater(new Runnable() {
  89.                 @Override
  90.                 public void run() {
  91.                     new VersionGUI().setVisible(true);
  92.                 }
  93.             });
  94.         }
  95.  
  96.         while (!start) {
  97.             sleep(1000);
  98.         }
  99.        
  100.         try {
  101.             arrow = ImageIO.read(new URL("http://megascripts.comyr.com/Arrow.png").openStream());
  102.         } catch (IOException e) {
  103.             // TODO Auto-generated catch block
  104.             e.printStackTrace();
  105.         }
  106.  
  107.         fullPrice = getPrice(pID);
  108.         emptyPrice = getPrice(lID);
  109.         log("" + whereandwhat.getSelectedItem().toString() + " price: "
  110.                 + fullPrice);
  111.         return true;
  112.     }
  113.  
  114.     // Sees the messages in game
  115.     @Override
  116.     public void messageReceived(MessageEvent arg0) {
  117.         if (arg0.getMessage().contains("You fill")) {
  118.         }
  119.  
  120.     }
  121.  
  122.     // Script's graphics
  123.     public void onRepaint(Graphics g) {
  124.         long runTime = System.currentTimeMillis() - startTime;
  125.         long TotalSecs = runTime / 1000;
  126.         long TotalMins = TotalSecs / 60;
  127.         long TotalHours = TotalMins / 60;
  128.         int seconds = (int) TotalSecs % 60;
  129.         int minutes = (int) TotalMins % 60;
  130.         int hours = (int) TotalHours % 60;
  131.  
  132.         StringBuilder b = new StringBuilder();
  133.  
  134.         if (hours < 10)
  135.             b.append('0');
  136.         b.append(hours);
  137.         b.append(':');
  138.         if (minutes < 10)
  139.             b.append('0');
  140.         b.append(minutes);
  141.         b.append(':');
  142.         if (seconds < 10)
  143.             b.append('0');
  144.         b.append(seconds);
  145.  
  146.         if (start) {
  147.             work = planks / (minutes + hours * 60 + seconds / 60f) * 60f;
  148.  
  149.             moneyMade = (planks * fullPrice) - (planks * emptyPrice);
  150.  
  151.             profitHour = (int) (moneyMade
  152.                     / (minutes + hours * 60 + seconds / 60f) * 60f);
  153.  
  154.             if (minutes == 30 && seconds == 1 || minutes == 0 && seconds == 30
  155.                     && game.isLoggedIn()) {
  156.                 String fS = File.separator;
  157.                 String path = null;
  158.                 File directory;
  159.                 try {
  160.                     path = new File(".").getCanonicalPath();
  161.                 } catch (IOException e) {
  162.                     // TODO Auto-generated catch block
  163.                     e.printStackTrace();
  164.                 }
  165.                 directory = new File(path + fS + getName() + " " + getVersion());
  166.                 if (!directory.exists()) {
  167.                     directory.mkdirs();
  168.                     log("Made the directory for proggies");
  169.                 }
  170.                 BufferedImage img = new BufferedImage(155, 140,
  171.                         BufferedImage.TYPE_INT_RGB);
  172.                 File file = new File(directory + fS + "MegaPlanker " + counter
  173.                         + ".gif");
  174.                 g = img.getGraphics();
  175.                 g.setColor(new Color(76, 67, 69));
  176.                 g.fill3DRect(0, 0, 155, 140, true);
  177.  
  178.                 int w = 0;
  179.                 int z = 0;
  180.                 g.setColor(new Color(80, 207, 58));
  181.                 g.drawString(getName() + " " + getVersion(), w, z += 20);
  182.                 g.drawString("Ran for: " + b.toString(), w, z += 25);
  183.                 g.drawString("Made " + planks + " " + pName + "s", w, z += 20);
  184.                 g.drawString("Filling: " + roundToTenth(work) + " per hour.",
  185.                         w, z += 20);
  186.                 g.drawString("Made: " + moneyMade + " profit", w, z += 20);
  187.                 g.drawString("Making: " + profitHour + " an hour", w, z += 20);
  188.                 try {
  189.                     ImageIO.write(img, "gif", file);
  190.                 } catch (IOException e) {
  191.                     // TODO Auto-generated catch block
  192.                     e.printStackTrace();
  193.                 }
  194.                 log("Sent a proggy image to the MegaPlanker folder in program files folder...");
  195.                 counter++;
  196.                 sleep(2000);
  197.             }
  198.         }
  199.  
  200.         if (game.isLoggedIn()) {
  201.             if (arrow != null) {
  202.                 g.drawImage(arrow, mouse.getLocation().x - 9, mouse.getLocation().y - 2, null);
  203.             }
  204.            
  205.             g.setColor(new Color(76, 67, 69, 185));
  206.             g.fill3DRect(360, 180, 158, 165, true);
  207.             int x = 365;
  208.             int y = 185;
  209.             g.setColor(new Color(80, 207, 58));
  210.             g.drawString(getName() + " " + getVersion(), x, y += 20);
  211.             g.drawString("Ran for: " + b.toString(), x, y += 25);
  212.             g.drawString("Made: " + planks + " planks", x, y += 20);
  213.             g.drawString("Making: " + roundToTenth(work) + " per hour.", x,
  214.                     y += 20);
  215.             g.drawString("Made: " + moneyMade + " proffit", x, y += 20);
  216.             g.drawString("Making: " + profitHour + " an hour", x, y += 20);
  217.             g.drawString("Status: " + status, x, y += 20);
  218.         }
  219.     }
  220.  
  221.     // Main method to run.. the methods.
  222.     @Override
  223.     public int loop() {
  224.         // Checks if we are logged in!
  225.         if (!game.isLoggedIn()) {
  226.             return 1000;
  227.         }
  228.         // Moves camera up if down
  229.         if (camera.getPitch() < 50) {
  230.             camera.setPitch(true);
  231.         }
  232.         if (getMyPlayer().getAnimation() == 5713
  233.                 || getMyPlayer().getAnimation() == 11786
  234.                 && walking.getEnergy() > 80) {
  235.             mouse.move(calc.tileToScreen(getMyPlayer().getLocation()));
  236.             mouse.click(true);
  237.         }
  238.         // Checks if energy is low
  239.         if (walking.getEnergy() < 10 && getMyPlayer().isIdle()) {
  240.             walking.rest();
  241.         }
  242.         // Checks if the run is off and the energy is above 75
  243.         if (!walking.isRunEnabled() && walking.getEnergy() > 75) {
  244.             // If run is off we should turn it on
  245.             walking.setRun(true);
  246.         }
  247.  
  248.         // Checks if inventory is full
  249.         if (inventory.isFull()) {
  250.             switch (stateFull()) {
  251.             case 1:
  252.                 walkToOperator();
  253.                 return 223;
  254.             case 2:
  255.                 makePlanks();
  256.                 return 243;
  257.             case 3:
  258.                 walkToBank();
  259.                 return 233;
  260.             case 4:
  261.                 depositPlanks();
  262.                 return 253;
  263.             case 0:
  264.                 return 1;
  265.             }
  266.         } else { // IF NOT FULL
  267.             RSTile bankerTile = new RSTile(3253, 3418);
  268.             // banker = npcs.getNearest("Banker"); // bank
  269.             if (calc.distanceTo(bankerTile) < 5) { // If close to bank
  270.                 if (bank.open()) {
  271.                     if (bank.withdraw(lID, 0)) {
  272.                         while (!inventory.isFull()) {
  273.                             sleep(100);
  274.                         }
  275.                         return random(33, 100);
  276.                     }
  277.                 } else {
  278.                     if (tiles.interact(bankerTile, "Bank Banker")) {
  279.                         sleep(random(33, 210));
  280.                     }
  281.                 }
  282.                 // if (banker.interact("Bank Banker")) {
  283.                 // return random(33, 210);
  284.                 // }
  285.                 return 50;
  286.             }
  287.             if (getMyPlayer().isMoving()) {
  288.                 return 50;
  289.             } else {
  290.                 if (walkToBank()) {
  291.                     // Walking back to bank!
  292.                     return 500;
  293.                 } else {
  294.                     // Something is wrong.
  295.                     return 100;
  296.                 }
  297.             }
  298.         }
  299.         return random(300, 500);
  300.     }
  301.  
  302.     // Other Methods!
  303.  
  304.     // The state we are in when inventory is full.
  305.     public int stateFull() {
  306.         RSTile f = new RSTile(3302, 3491);
  307.         if (calc.tileOnScreen(f)) {
  308.             fOnScreen = true;
  309.         } else {
  310.             fOnScreen = false;
  311.         }
  312.  
  313.         if (inventory.containsAll(lID) && !fOnScreen) {
  314.             status = "Walking to operator";
  315.             return 1;
  316.         }
  317.         if (inventory.containsAll(lID) && fOnScreen) {
  318.             status = "Making " + pName;
  319.             return 2;
  320.         }
  321.         // banker = npcs.getNearest(2718);
  322.         // if(banker == null) {
  323.         // walkToBank();
  324.         // return 0;
  325.         // }
  326.         RSTile bankerTile = new RSTile(3253, 3421);
  327.         if (inventory.containsAll(pID)
  328.                 && !calc.tileOnScreen(bankerTile)) {
  329.             status = "Walking to bank";
  330.             return 3;
  331.         }
  332.         if (inventory.containsAll(pID)
  333.                 && calc.tileOnScreen(bankerTile)) {
  334.             status = "Depositing";
  335.             return 4;
  336.         }
  337.  
  338.         return 0;
  339.     }
  340.  
  341.     // Walks to bank
  342.     public boolean walkToBank() {
  343.         RSTile bankTile = new RSTile(3253, 3421);
  344.         RSWeb walkWeb = web.getWeb(bankTile);
  345.         int counter = 0;
  346.         if (walkWeb.step()) {
  347.             while (calc.distanceTo(bankTile) > 7) {
  348.                 while (getMyPlayer().isMoving()) {
  349.                     while(calc.distanceTo(walking.getDestination()) > 5) {
  350.                         checkRest();
  351.                         sleep(500);
  352.                     }
  353.                     if(calc.distanceTo(walking.getDestination()) < 4) {
  354.                         walkWeb.update();
  355.                         walkWeb.step();
  356.                     }
  357.                 }
  358.                 if (!getMyPlayer().isMoving()) {
  359.                     counter++;
  360.                     if(counter > 3) {
  361.                         walkWeb.step();
  362.                         break;
  363.                     }
  364.                     checkRest();
  365.                 }
  366.             }
  367.         }
  368.         sleep(500);
  369.         return true;
  370.     }
  371.  
  372.     // Walks to operator
  373.     public boolean walkToOperator() {
  374.         RSTile fTile = new RSTile(3302, 3491);
  375.         RSWeb walkWeb = web.getWeb(fTile);
  376.         if (walkWeb.step()) {
  377.             while (calc.distanceTo(fTile) > 7) {
  378.                 while (getMyPlayer().isMoving()) {
  379.                     while(calc.distanceTo(walking.getDestination()) > 5) {
  380.                         checkRest();
  381.                         sleep(500);
  382.                     }
  383.                     if(calc.distanceTo(walking.getDestination()) < 4) {
  384.                         walkWeb.update();
  385.                         walkWeb.step();
  386.                     }
  387.                 }
  388.                 if (!getMyPlayer().isMoving()) {
  389.                     counter++;
  390.                     if(counter > 3) {
  391.                         walkWeb.step();
  392.                         break;
  393.                     }
  394.                     checkRest();
  395.                 }
  396.             }
  397.         }
  398.         sleep(500);
  399.         return true;
  400.     }
  401.    
  402.     public void checkRest() {
  403.         // Checks if energy is low
  404.         if (walking.getEnergy() < 10) {
  405.             walking.rest();
  406.             sleep(500);
  407.         }
  408.         if (getMyPlayer().getAnimation() == 5713
  409.                 || getMyPlayer().getAnimation() == 11786
  410.                 && walking.getEnergy() > 85) {
  411.         mouse.move(calc.tileToScreen(getMyPlayer().getLocation()));
  412.         mouse.click(true);
  413.         }
  414.         if (getMyPlayer().getAnimation() == 5713
  415.                 || getMyPlayer().getAnimation() == 11786) {
  416.             sleep(500);
  417.             while (walking.getEnergy() < 85) {
  418.                 sleep(500);
  419.             }
  420.            
  421.         }
  422.         // Checks if the run is off and the energy is above 55
  423.         if (!walking.isRunEnabled() && walking.getEnergy() > 85) {
  424.             // If run is off we should turn it on
  425.             walking.setRun(true);
  426.             return;
  427.         }
  428.     }
  429.  
  430.     // Fills planks
  431.     public boolean makePlanks() {
  432.         operator = npcs.getNearest("Sawmill operator");
  433.         int counter = 0;
  434.         if (operator.interact("Buy-plank Sawmill operator")) {
  435.             sleep(350);
  436.             while (!interfaces.get(403).isValid()) {
  437.                 sleep(500);
  438.                 counter++;
  439.                 if (counter > 3) {
  440.                     operator.interact("Buy-plank Sawmill operator");
  441.                     counter = 0;
  442.                 }
  443.             }
  444.             if (interfaces.get(403).isValid()) {
  445.                 if (interfaces.get(403).getComponent(iComponent).interact("Buy all " + pName)) {
  446.                     planks = planks + 28;
  447.                     sleep(350);
  448.                     while(inventory.containsAll(lID)) {
  449.                         sleep(500);
  450.                     }
  451.                 }
  452.             }
  453.             return true;
  454.         }
  455.         return false;
  456.     }
  457.  
  458.     // Deposits planks
  459.     public boolean depositPlanks() {
  460.         // banker = npcs.getNearest("Banker"); // bank
  461.         // if (banker.interact("Bank Banker")) {
  462.         // sleep(random(350, 500));
  463.         // }
  464.         int counter = 0;
  465.         RSTile bankerTile = new RSTile(3253, 3419);
  466.         if (tiles.interact(bankerTile, "Bank Bank Booth")) {
  467.             while (!bank.isOpen()) {
  468.                 sleep(500);
  469.                 counter++;
  470.                 if(counter > 5) {
  471.                     tiles.interact(bankerTile, "Bank Bank Booth");
  472.                     counter = 0;
  473.                 }
  474.             }
  475.         }
  476.         if (bank.isOpen()) {
  477.             if (bank.depositAllExcept(995)) {
  478.                 while (inventory.isFull()) {
  479.                     sleep(500);
  480.                 }
  481.             }
  482.         } else {
  483.             return false;
  484.         }
  485.         return true;
  486.     }
  487.  
  488.     public boolean clickTile(RSTile c, String action) {
  489.         try {
  490.             while (getMyPlayer().isMoving()) {
  491.                 sleep(750);
  492.             }
  493.             Point screenLoc = calc.tileToScreen(c);
  494.             mouse.move(screenLoc);
  495.             if (!mouse.getLocation().equals(screenLoc))
  496.                 return false;
  497.  
  498.             mouse.click(screenLoc, false);
  499.             return menu.doAction(action);
  500.  
  501.         } catch (NullPointerException e) {
  502.         }
  503.         return true;
  504.     }
  505.  
  506.     // Clicks tile accurately
  507.     public boolean clickTile2(RSTile c, String action) {
  508.         try {
  509.             Point screenLoc = null;
  510.             screenLoc = calc.tileToScreen(c);
  511.             if (c == null || !calc.pointOnScreen(screenLoc)) {
  512.                 System.out.println("Not on screen " + action);
  513.                 return false;
  514.             }
  515.  
  516.             mouse.move(screenLoc);
  517.             screenLoc = calc.tileToScreen(c);
  518.  
  519.             String[] items = menu.getItems();
  520.             if (items.length <= 1)
  521.                 return false;
  522.             if (items[0].toLowerCase().contains(action.toLowerCase())) {
  523.                 mouse.click(screenLoc, true);
  524.                 return true;
  525.             } else {
  526.                 mouse.click(screenLoc, false);
  527.                 return menu.doAction(action);
  528.             }
  529.  
  530.         } catch (NullPointerException e) {
  531.         }
  532.         return true;
  533.     }
  534.  
  535.     // Rounds a double to the nearest tenth
  536.     public double roundToTenth(double d) {
  537.         DecimalFormat twoDForm = new DecimalFormat("#.#");
  538.         twoDForm = new DecimalFormat("#.#");
  539.         return Double.valueOf(twoDForm.format(d));
  540.     }
  541.  
  542.     // Checks for the recent version
  543.     public double getOVersion() {
  544.         try {
  545.             URL url = new URL("http://megascripts.comyr.com/MegaPlanker/Version");
  546.             BufferedReader br = new BufferedReader(new InputStreamReader(
  547.                     new BufferedInputStream(url.openConnection()
  548.                             .getInputStream())));
  549.             double ver = Double.parseDouble(br.readLine().trim());
  550.             br.close();
  551.             return ver;
  552.         } catch (IOException e) {
  553.             throw new RuntimeException(e);
  554.         }
  555.     }
  556.  
  557.     // ANTI-BAN STUFF
  558.     public int antiBan() {
  559.         Point m;
  560.         int x = random(0, 750);
  561.         int y = random(0, 500);
  562.         int xx = random(710, 554);
  563.         int yy = random(444, 230);
  564.         int screenx = random(1, 510);
  565.         int screeny = random(1, 450);
  566.  
  567.         int gamble = random(0, 22);
  568.  
  569.         final long start = System.currentTimeMillis();
  570.         final RSPlayer myPlayer = getMyPlayer();
  571.  
  572.         int anim = -1;
  573.         while (System.currentTimeMillis() - start > 2000) {
  574.             if ((anim = myPlayer.getAnimation()) != -1) {
  575.                 break;
  576.             }
  577.             sleep(15);
  578.         }
  579.  
  580.         switch (gamble) {
  581.         case 1:
  582.  
  583.             sleep(random(1000, 2500));
  584.  
  585.             break;
  586.         case 2:
  587.             mouse.move(x, y);
  588.  
  589.             while (System.currentTimeMillis() - start > 2000) {
  590.  
  591.                 if ((anim = myPlayer.getAnimation()) != -1) {
  592.                     break;
  593.                 }
  594.                 sleep(random(15, 55));
  595.             }
  596.  
  597.             sleep(random(1000, 2500));
  598.             break;
  599.         case 3:
  600.             game.openTab(Tab.INVENTORY);
  601.             sleep(random(1000, 2500));
  602.             break;
  603.         case 4:
  604.             if (getMyPlayer().isMoving()) {
  605.                 sleep(random(1000, 2500));
  606.                 break;
  607.             }
  608.         case 5:
  609.             mouse.move(x, y);
  610.             int checkTime = 0;
  611.             long lastCheck = 0;
  612.             sleep(random(1000, 2500));
  613.             if (System.currentTimeMillis() - lastCheck >= checkTime) {
  614.                 lastCheck = System.currentTimeMillis();
  615.                 checkTime = random(60000, 180000);
  616.                 break;
  617.             }
  618.         case 6:
  619.             if (game.getTab() != Tab.STATS) {
  620.                 game.openTab(Tab.STATS);
  621.                 mouse.move(xx, yy);
  622.                 sleep(random(2000, 3500));
  623.                 game.openTab(Tab.INVENTORY);
  624.                 break;
  625.             }
  626.         case 7:
  627.             sleep(random(750, 1500));
  628.             break;
  629.         case 8:
  630.             mouse.move(screenx, screeny);
  631.             sleep(random(750, 1500));
  632.             break;
  633.         case 9:
  634.             mouse.move(screenx, screeny);
  635.             sleep(random(750, 1500));
  636.             break;
  637.         case 10:
  638.             game.openTab(game.getRandomTab());
  639.             sleep(random(750, 1500));
  640.             break;
  641.  
  642.         case 11:
  643.             mouse.move(x, y);
  644.             sleep(random(750, 1500));
  645.             break;
  646.         case 13:
  647.             mouse.move(x, y);
  648.             sleep(random(750, 1500));
  649.             break;
  650.         case 12:
  651.             mouse.move(x, y);
  652.             sleep(random(750, 1500));
  653.             break;
  654.         case 14:
  655.             m = mouse.getLocation();
  656.             sleep(random(300, 500));
  657.             mouse.move(m, 20, 20);
  658.             sleep(random(100, 200));
  659.             break;
  660.         case 15:
  661.             m = mouse.getLocation();
  662.             sleep(random(300, 500));
  663.             mouse.move(m, 20, 20);
  664.             sleep(random(100, 200));
  665.             break;
  666.         case 16:
  667.             m = mouse.getLocation();
  668.             sleep(random(300, 500));
  669.             mouse.move(m, 20, 20);
  670.             sleep(random(100, 200));
  671.             break;
  672.         case 17:
  673.             m = mouse.getLocation();
  674.             sleep(random(300, 500));
  675.             mouse.move(m, 20, 20);
  676.             sleep(random(100, 200));
  677.             break;
  678.         case 19:
  679.             mouse.move(x, y);
  680.             sleep(random(750, 1500));
  681.             break;
  682.         case 20:
  683.             mouse.move(x, y);
  684.             sleep(random(750, 1500));
  685.             break;
  686.         case 21:
  687.             mouse.move(x, y);
  688.             sleep(random(750, 1500));
  689.             break;
  690.  
  691.         }
  692.  
  693.         return 100;
  694.     }
  695.  
  696.     // Grand exchange price lookup
  697.     private int getPrice(int itemID) {
  698.         try {
  699.             URL url = new URL(GE_URL + String.valueOf(itemID));
  700.             BufferedReader x = new BufferedReader(new InputStreamReader(
  701.                     url.openStream()));
  702.             String inputLine;
  703.             while ((inputLine = x.readLine()) != null) {
  704.                 if (inputLine
  705.                         .contains("<th scope=\"row\">Current guide price:</th>")) {
  706.                     return (int) parsePrice(x.readLine());
  707.                 }
  708.             }
  709.             x.close();
  710.         } catch (MalformedURLException e) {
  711.             e.printStackTrace();
  712.         } catch (IOException e) {
  713.             e.printStackTrace();
  714.         }
  715.         return -1;
  716.     }
  717.  
  718.     private double parsePrice(String str) {
  719.         if (str != null && !str.isEmpty()) {
  720.             str = stripFormatting(str);
  721.             str = str.substring(str.indexOf(58) + 1, str.length());
  722.             str = str.replace(",", "");
  723.             str = str.trim();
  724.             if (!str.endsWith("%")) {
  725.                 if (!str.endsWith("k") && !str.endsWith("m")
  726.                         && !str.endsWith("b")) {
  727.                     return Double.parseDouble(str);
  728.                 }
  729.                 return Double.parseDouble(str.substring(0, str.length() - 1))
  730.                         * (str.endsWith("b") ? 1000000000
  731.                                 : str.endsWith("m") ? 1000000 : 1000);
  732.             }
  733.             final int k = str.startsWith("+") ? 1 : -1;
  734.             str = str.substring(0);
  735.             return Double.parseDouble(str.substring(0, str.length() - 1)) * k;
  736.         }
  737.         return -1D;
  738.     }
  739.  
  740.     private String stripFormatting(final String str) {
  741.         if (str != null && !str.isEmpty()) {
  742.             return str.replaceAll("(^[^<]+>|<[^>]+>|<[^>]+$)", "");
  743.         }
  744.         return "";
  745.     }
  746.  
  747.     // End Grand exchange price lookup
  748.  
  749.     JButton startButton;
  750.     JComboBox whereandwhat;
  751.     JLabel text;
  752.  
  753.     public class MegaGUI extends JFrame implements ActionListener {
  754.  
  755.         public MegaGUI() {
  756.             setTitle("MegaPlanker");
  757.  
  758.             startButton = new JButton("Start");
  759.             text = new JLabel("What plank to make?");
  760.             whereandwhat = new JComboBox(list);
  761.  
  762.             setLayout(null);
  763.             setResizable(false);
  764.             setSize(390, 255);
  765.             setLocationRelativeTo(null);
  766.  
  767.             text.setBounds(20, 20, 182, 21);
  768.             startButton.setBounds(135, 148, 83, 28);
  769.             startButton.addActionListener(this);
  770.             whereandwhat.setBounds(65, 71, 200, 22);
  771.  
  772.             add(text);
  773.             add(whereandwhat);
  774.             add(startButton);
  775.  
  776.             setVisible(true);
  777.         }
  778.  
  779.         @Override
  780.         public void actionPerformed(ActionEvent e) {
  781.             if (e.getActionCommand().contains("Start")) {
  782.                 if (whereandwhat.getSelectedItem().toString().equals("Wood plank")) {
  783.                     lID = 1511;
  784.                     pID = 960;
  785.                     iComponent = 12;
  786.                     pName = "Wood plank";
  787.                     log("Making wood planks");
  788.                 } else if (whereandwhat.getSelectedItem().toString()
  789.                         .equals("Oak plank")) {
  790.                     lID = 1521;
  791.                     pID = 8778;
  792.                     iComponent = 13;
  793.                     pName = "Oak plank";
  794.                     log("Making oak planks");
  795.                 } else if (whereandwhat.getSelectedItem().toString()
  796.                         .equals("Teak plank")) {
  797.                     lID = 6333;
  798.                     pID = 8780;
  799.                     iComponent = 14;
  800.                     pName = "Teak plank";
  801.                     log("Making teak planks");
  802.                 } else if (whereandwhat.getSelectedItem().toString()
  803.                         .equals("Mohagany plank")) {
  804.                     lID = 6332;
  805.                     pID = 8782;
  806.                     iComponent = 15;
  807.                     pName = "Mohagany Plank";
  808.                     log("Making mohagany planks");
  809.                 }
  810.                 dispose();
  811.                 setVisible(false);
  812.                 start = true;
  813.             }
  814.         }
  815.  
  816.     }
  817.  
  818.     JButton oB;
  819.     JButton gN;
  820.     JLabel oL;
  821.  
  822.     public class VersionGUI extends JFrame implements ActionListener {
  823.  
  824.         public VersionGUI() {
  825.             setTitle("OUTDATED");
  826.  
  827.             oB = new JButton("Okay");
  828.             oL = new JLabel("OUTDATED");
  829.             gN = new JButton("Get new version");
  830.  
  831.             setLayout(null);
  832.             setResizable(false);
  833.             setSize(150, 185);
  834.             setLocationRelativeTo(null);
  835.  
  836.             oB.setBounds(20, 35, 65, 25);
  837.             gN.setBounds(20, 85, 115, 25);
  838.             oB.addActionListener(this);
  839.             gN.addActionListener(this);
  840.             oL.setBounds(20, 5, 182, 21);
  841.  
  842.             add(oL);
  843.             add(gN);
  844.             add(oB);
  845.  
  846.             setVisible(true);
  847.         }
  848.  
  849.         public void getNewVersion() {
  850.             File directory = getCacheDirectory();
  851.              File newDirectory =
  852.                      new File(new File(new File(directory.getParent()).getParent()).getParent()
  853.                              + File.separator + "Scripts" + File.separator +
  854.                              "Sources" + File.separator + "MegaPlanker.java");
  855.              
  856.             BufferedInputStream in;
  857.             try {
  858.                 in = new BufferedInputStream(
  859.                         new URL("http://megascripts.comyr.com/MegaPlanker/MegaPlanker.java").openStream());
  860.             FileOutputStream fos = new FileOutputStream(newDirectory);
  861.             BufferedOutputStream bout = new BufferedOutputStream(fos,1024);
  862.             byte[] data = new byte[1024];
  863.             int x=0;
  864.             while((x=in.read(data,0,1024))>=0) {
  865.                 bout.write(data,0,x);
  866.             }
  867.             bout.close();
  868.             in.close();
  869.             } catch (MalformedURLException e) {
  870.                 // TODO Auto-generated catch block
  871.                 e.printStackTrace();
  872.             } catch (IOException e) {
  873.                 // TODO Auto-generated catch block
  874.                 e.printStackTrace();
  875.             }
  876.         }
  877.  
  878.         @Override
  879.         public void actionPerformed(ActionEvent e) {
  880.             if (e.getActionCommand().contains("Okay")) {
  881.                 dispose();
  882.                 setVisible(false);
  883.             }
  884.             if (e.getActionCommand().contains("Get new version")) {
  885.                 getNewVersion();
  886.                 sleep(1000);
  887.                 oL.setText("Recompile the script");
  888.                 repaint();
  889.                 stopScript();
  890.             }
  891.         }
  892.     }
  893. }
Advertisement
Add Comment
Please, Sign In to add comment