megaalgos

MegaPlanker 1.0

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