megaalgos

MegaPlanker 1.3

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