Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Version 1.4
- /**
- * Add Musician support!!! Tell me if its the most efficient as possible.
- * Fixed the paint. I didn't figure in the cost to make the planks.
- * Should show correct profits
- */
- //Version 1.3
- /**
- * Fixed updating problem
- * Made the walking better. I did a test to see if resting helped
- * it didnt, so for now until I give an option i turned resting off
- */
- //Version 1.2
- /**
- * Fixed paint, I must have been sleeping when I did the math...
- * Made even more failsafes, script should run "more" efficient
- */
- //Version 1.1
- /**
- * Made failsafes for my methods so the script doesnt just sit there.
- * Made the running method as efficient as I could think it.
- */
- import java.awt.*;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.awt.event.KeyEvent;
- import java.awt.image.BufferedImage;
- import java.io.BufferedInputStream;
- import java.io.BufferedOutputStream;
- import java.io.BufferedReader;
- import java.io.File;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.net.MalformedURLException;
- import java.net.URL;
- import java.text.DecimalFormat;
- import javax.imageio.ImageIO;
- import javax.swing.*;
- import com.rarebot.script.Script;
- import com.rarebot.event.events.MessageEvent;
- import com.rarebot.event.listeners.*;
- import com.rarebot.script.ScriptManifest;
- import com.rarebot.script.methods.Game.Tab;
- import com.rarebot.script.wrappers.*;
- // Script Info
- @ScriptManifest(authors = { "MegaAlgos" }, version = 1.4, keywords = ("Money Making"), description = "Makes planks at Varrock East", name = "MegaPlanker")
- public class MegaPlanker extends Script implements PaintListener,
- MessageListener {
- // Script Info for paint and proggies...
- public double getVersion() {
- return (1.4);
- }
- public String getName() {
- return ("MegaPlanker");
- }
- public String getAuthor() {
- return ("MegaAlgos");
- }
- // Script Variables
- RSNPC banker, operator;
- int gePrice = 0, moneyMade, profitHour, planks, counter, fullPrice,
- emptyPrice, restSetCount = 0;
- int pID, lID, iComponent, makePrice;
- String status, pName, fName;
- String[] list = { "Wood plank", "Oak plank", "Teak plank", "Mahogany plank" };
- private static final String GE_URL = "http://services.runescape.com/m=itemdb_rs/g=runescape/viewitem.ws?obj=";
- long startTime, checkForFilling;
- double work = 0;
- boolean start = false, fOnScreen = false,
- startUP = false, filled = false,
- rest = false;
- int vP;
- int jP;
- int buP;
- int boP;
- Image arrow = null;
- RSTile[] tO = { new RSTile(3267, 3428), new RSTile(3278, 3436),
- new RSTile(3285, 3449), new RSTile(3290, 3463),
- new RSTile(3299, 3476), new RSTile(3302, 3490) },
- tB = { new RSTile(3293, 3478), new RSTile(3286, 3460),
- new RSTile(3282, 3444), new RSTile(3276, 3429),
- new RSTile(3263, 3429), new RSTile(3253, 3420) };
- // What it does on the start of the script
- public boolean onStart() {
- mouse.setSpeed(7);
- startTime = System.currentTimeMillis();
- log("MegaPlanker! Aimed to make you planks... hours on end");
- java.awt.EventQueue.invokeLater(new Runnable() {
- @Override
- public void run() {
- new MegaGUI().setVisible(true);
- }
- });
- if (getOVersion() != getVersion()) {
- java.awt.EventQueue.invokeLater(new Runnable() {
- @Override
- public void run() {
- new VersionGUI().setVisible(true);
- }
- });
- }
- while (!start) {
- sleep(1000);
- }
- try {
- arrow = ImageIO.read(new URL("http://megascripts.comyr.com/Arrow.png").openStream());
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- fullPrice = getPrice(pID);
- emptyPrice = getPrice(lID);
- log("" + whereandwhat.getSelectedItem().toString() + " price: "
- + fullPrice);
- return true;
- }
- // Sees the messages in game
- @Override
- public void messageReceived(MessageEvent arg0) {
- if (arg0.getMessage().contains("You fill")) {
- }
- }
- // Script's graphics
- public void onRepaint(Graphics g) {
- long runTime = System.currentTimeMillis() - startTime;
- long TotalSecs = runTime / 1000;
- long TotalMins = TotalSecs / 60;
- long TotalHours = TotalMins / 60;
- int seconds = (int) TotalSecs % 60;
- int minutes = (int) TotalMins % 60;
- int hours = (int) TotalHours % 60;
- StringBuilder b = new StringBuilder();
- if (hours < 10)
- b.append('0');
- b.append(hours);
- b.append(':');
- if (minutes < 10)
- b.append('0');
- b.append(minutes);
- b.append(':');
- if (seconds < 10)
- b.append('0');
- b.append(seconds);
- if (start) {
- work = planks / (minutes + hours * 60 + seconds / 60f) * 60f;
- moneyMade = (planks * fullPrice) - (planks * (emptyPrice + makePrice));
- profitHour = (int) (moneyMade
- / (minutes + hours * 60 + seconds / 60f) * 60f);
- if (minutes == 30 && seconds == 1 || minutes == 0 && seconds == 30
- && game.isLoggedIn()) {
- String fS = File.separator;
- String path = null;
- File directory;
- try {
- path = new File(".").getCanonicalPath();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- directory = new File(path + fS + getName() + " " + getVersion());
- if (!directory.exists()) {
- directory.mkdirs();
- log("Made the directory for proggies");
- }
- BufferedImage img = new BufferedImage(155, 140,
- BufferedImage.TYPE_INT_RGB);
- File file = new File(directory + fS + "MegaPlanker " + counter
- + ".gif");
- g = img.getGraphics();
- g.setColor(new Color(76, 67, 69));
- g.fill3DRect(0, 0, 155, 140, true);
- int w = 0;
- int z = 0;
- g.setColor(new Color(80, 207, 58));
- g.drawString(getName() + " " + getVersion(), w, z += 20);
- g.drawString("Ran for: " + b.toString(), w, z += 25);
- g.drawString("Made " + planks + " " + pName + "s", w, z += 20);
- g.drawString("Making: " + roundToTenth(work) + pName +" per hour.",
- w, z += 20);
- g.drawString("Made: " + addCommas(moneyMade, true) + " profit", w, z += 20);
- g.drawString("Making: " + addCommas(profitHour, true) + " an hour", w, z += 20);
- try {
- ImageIO.write(img, "gif", file);
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- log("Sent a proggy image to the MegaPlanker folder in program files folder...");
- counter++;
- sleep(2000);
- }
- }
- if (game.isLoggedIn()) {
- if (arrow != null) {
- g.drawImage(arrow, mouse.getLocation().x - 9, mouse.getLocation().y - 2, null);
- }
- g.setColor(new Color(76, 67, 69, 185));
- g.fill3DRect(360, 180, 158, 165, true);
- int x = 365;
- int y = 185;
- g.setColor(new Color(80, 207, 58));
- g.drawString(getName() + " " + getVersion(), x, y += 20);
- g.drawString("Ran for: " + b.toString(), x, y += 25);
- g.drawString("Made: " + planks + " planks", x, y += 20);
- g.drawString("Making: " + roundToTenth(work) + " " + pName +"/hour.", x,
- y += 20);
- g.drawString("Made: " + addCommas(moneyMade, true) + " proffit", x, y += 20);
- g.drawString("Making: " + addCommas(profitHour, true) + " an hour", x, y += 20);
- g.drawString("Status: " + status, x, y += 20);
- }
- }
- // Main method to run.. the methods.
- @Override
- public int loop() {
- // Checks if we are logged in!
- if (!game.isLoggedIn()) {
- return 1000;
- }
- // Moves camera up if down
- if (camera.getPitch() < 50) {
- camera.setPitch(true);
- }
- // Checks if the run is off and the energy is above 75
- if (!walking.isRunEnabled() && walking.getEnergy() > 75) {
- // If run is off we should turn it on
- walking.setRun(true);
- }
- // Checks if inventory is full
- if (inventory.isFull()) {
- switch (stateFull()) {
- case 1:
- if (restSetCount == 0) {
- checkRest();
- restSetCount++;
- }
- if (rest) {
- if (resting() && walking.getEnergy() > 65) {
- mouse.move(calc.tileToScreen(getMyPlayer().getLocation()));
- mouse.click(true);
- rest = false;
- return 500;
- }
- if (resting() && walking.getEnergy() < 80) {
- return 500;
- }
- if (nearMusician()) {
- restMusician();
- sleep(1000);
- } else {
- walkToMusician();
- }
- return 345;
- }
- walkToOperator();
- return 223;
- case 2:
- makePlanks();
- return 243;
- case 3:
- if (restSetCount == 0) {
- checkRest();
- restSetCount++;
- }
- if (rest) {
- if (resting() && walking.getEnergy() > 80) {
- mouse.move(calc.tileToScreen(getMyPlayer().getLocation()));
- mouse.click(true);
- rest = false;
- return 500;
- }
- if (resting() && walking.getEnergy() < 80) {
- return 500;
- }
- if (nearMusician()) {
- restMusician();
- sleep(1000);
- } else {
- walkToMusician();
- }
- return 345;
- }
- walkToBank();
- return 233;
- case 4:
- depositPlanks();
- return 253;
- case 0:
- return 1;
- }
- } else { // IF NOT FULL
- RSTile bankerTile = new RSTile(3253, 3418);
- if (calc.distanceTo(bankerTile) < 5) { // If close to bank
- if (bank.isOpen()) {
- if (bank.withdraw(lID, 0)) {
- sleep(750);
- }
- } else {
- if (bank.open()) {
- sleep(random(33, 210));
- }
- }
- return 50;
- }
- if (getMyPlayer().isMoving()) {
- return 50;
- } else {
- if (walkToBank()) {
- // Walking back to bank!
- return 500;
- } else {
- // Something is wrong.
- return 100;
- }
- }
- }
- return random(300, 500);
- }
- // Other Methods!
- // The state we are in when inventory is full.
- public int stateFull() {
- RSTile f = new RSTile(3302, 3491);
- if (calc.tileOnScreen(f)) {
- fOnScreen = true;
- } else {
- fOnScreen = false;
- }
- if (inventory.containsAll(lID) && !fOnScreen) {
- status = "Walking to operator";
- return 1;
- }
- if (inventory.containsAll(lID) && fOnScreen) {
- status = "Making " + pName;
- return 2;
- }
- // banker = npcs.getNearest(2718);
- // if(banker == null) {
- // walkToBank();
- // return 0;
- // }
- RSTile bankerTile = new RSTile(3253, 3421);
- if (inventory.containsAll(pID)
- && !calc.tileOnScreen(bankerTile)) {
- status = "Walking to bank";
- return 3;
- }
- if (inventory.containsAll(pID)
- && calc.tileOnScreen(bankerTile)) {
- status = "Depositing";
- return 4;
- }
- return 0;
- }
- // Walks to bank
- public boolean walkToBank() {
- RSTile bankTile = new RSTile(3253, 3421);
- RSWeb walkWeb = web.getWeb(bankTile);
- if (walkWeb != null) {
- if (getMyPlayer().isMoving()) {
- if (calc.distanceTo(walking.getDestination()) < 7) {
- walkWeb.step();
- return true;
- } else {
- sleep(250);
- return true;
- }
- }
- walkWeb.step();
- }
- return true;
- }
- // Walks to musician
- public boolean walkToMusician() {
- RSTile mTile = new RSTile(3290, 3455);
- RSWeb walkWeb = web.getWeb(mTile);
- if (walkWeb != null) {
- if (getMyPlayer().isMoving()) {
- if (calc.distanceTo(walking.getDestination()) < 10) {
- walkWeb.step();
- return true;
- } else {
- sleep(250);
- return true;
- }
- }
- walkWeb.step();
- }
- return true;
- }
- // Checks if we are near musician
- public boolean nearMusician() {
- RSTile mTile = new RSTile(3290, 3455);
- if (calc.tileOnScreen(mTile)) {
- return true;
- }
- return false;
- }
- // Rests at musician
- public void restMusician() {
- RSNPC m = npcs.getNearest(8700);
- if (m != null) {
- clickNPC(m, "Listen-to");
- sleep(500);
- }
- }
- // Walks to operator
- public boolean walkToOperator() {
- RSTile fTile = new RSTile(3302, 3491);
- RSWeb walkWeb = web.getWeb(fTile);
- if (walkWeb != null) {
- if (getMyPlayer().isMoving()) {
- if (calc.distanceTo(walking.getDestination()) < 10) {
- walkWeb.step();
- return true;
- } else {
- sleep(250);
- return true;
- }
- }
- walkWeb.step();
- }
- return true;
- }
- public void checkRest() {
- if(walking.getEnergy() < 75) {
- rest = true;
- } else {
- rest = false;
- }
- }
- // Fills planks
- public boolean makePlanks() {
- if (interfaces.get(403).isValid()) {
- if (interfaces.get(403).getComponent(iComponent).interact("Buy all " + pName)) {
- planks = planks + 28;
- sleep(500);
- while(inventory.containsAll(lID)) {
- sleep(500);
- counter++;
- if(counter > 3) {
- counter = 0;
- break;
- }
- }
- }
- }
- operator = npcs.getNearest("Sawmill operator");
- int counter = 0;
- if(operator == null) {
- return false;
- }
- if (operator.interact("Buy-plank Sawmill operator")) {
- sleep(350);
- while (!interfaces.get(403).isValid()) {
- sleep(500);
- counter++;
- if (counter > 3) {
- operator.interact("Buy-plank Sawmill operator");
- counter = 0;
- }
- }
- if (interfaces.get(403).isValid()) {
- if (interfaces.get(403).getComponent(iComponent).interact("Buy all " + pName)) {
- planks = planks + 28;
- sleep(500);
- while(inventory.containsAll(lID)) {
- sleep(500);
- counter++;
- if(counter > 5) {
- counter = 0;
- break;
- }
- }
- }
- }
- }
- restSetCount = 0;
- rest = true;
- return true;
- }
- // Deposits planks
- public boolean depositPlanks() {
- // banker = npcs.getNearest("Banker"); // bank
- // if (banker.interact("Bank Banker")) {
- // sleep(random(350, 500));
- // }
- int counter = 0;
- RSTile bankerTile = new RSTile(3253, 3419);
- if (clickTile(bankerTile, "Bank Bank Booth")) {
- while (!bank.isOpen()) {
- sleep(500);
- counter++;
- if(counter > 5) {
- clickTile(bankerTile, "Bank Bank Booth");
- counter = 0;
- }
- }
- }
- if (bank.isOpen()) {
- if (bank.depositAllExcept(995)) {
- while (inventory.isFull()) {
- sleep(500);
- }
- rest = true;
- restSetCount = 0;
- }
- } else {
- return false;
- }
- return true;
- }
- public boolean clickTile(RSTile c, String action) {
- try {
- while (getMyPlayer().isMoving()) {
- sleep(50);
- }
- Point screenLoc = calc.tileToScreen(c);
- mouse.move(screenLoc);
- String[] items = menu.getActions();
- if (items.length <= 1) {
- return false;
- }
- if (items[0].toLowerCase().contains(action.toLowerCase())) {
- mouse.click(screenLoc, true);
- return true;
- } else {
- mouse.click(screenLoc, false);
- return menu.doAction(action);
- }
- } catch (NullPointerException e) {
- }
- return true;
- }
- public boolean clickNPC(RSNPC c, String action) {
- try {
- while (getMyPlayer().isMoving()) {
- sleep(50);
- }
- Point screenLoc = calc.tileToScreen(c.getLocation());
- mouse.move(screenLoc, 5, 5);
- String[] items = menu.getActions();
- if (items.length <= 1) {
- return false;
- }
- if (items[0].toLowerCase().contains(action.toLowerCase())) {
- mouse.click(true);
- return true;
- } else {
- mouse.click(false);
- return menu.doAction(action);
- }
- } catch (NullPointerException e) {
- }
- return true;
- }
- // Clicks tile accurately
- public boolean clickTile2(RSTile c, String action) {
- try {
- Point screenLoc = null;
- screenLoc = calc.tileToScreen(c);
- if (c == null || !calc.pointOnScreen(screenLoc)) {
- System.out.println("Not on screen " + action);
- return false;
- }
- mouse.move(screenLoc);
- screenLoc = calc.tileToScreen(c);
- String[] items = menu.getItems();
- if (items.length <= 1)
- return false;
- if (items[0].toLowerCase().contains(action.toLowerCase())) {
- mouse.click(screenLoc, true);
- return true;
- } else {
- mouse.click(screenLoc, false);
- return menu.doAction(action);
- }
- } catch (NullPointerException e) {
- }
- return true;
- }
- // Rounds a double to the nearest tenth
- public double roundToTenth(double d) {
- DecimalFormat twoDForm = new DecimalFormat("#.#");
- twoDForm = new DecimalFormat("#.#");
- return Double.valueOf(twoDForm.format(d));
- }
- public String addCommas(int d, boolean money) {
- DecimalFormat twoDForm = new DecimalFormat("###,###");
- if(money) {
- twoDForm = new DecimalFormat("$###,###");
- return twoDForm.format(d);
- }
- return twoDForm.format(d);
- }
- // Checks for the recent version
- public double getOVersion() {
- try {
- URL url = new URL("http://megascripts.comyr.com/MegaPlanker/Version");
- BufferedReader br = new BufferedReader(new InputStreamReader(
- new BufferedInputStream(url.openConnection()
- .getInputStream())));
- double ver = Double.parseDouble(br.readLine().trim());
- br.close();
- return ver;
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
- // Checks if we are resting
- public boolean resting() {
- if(getMyPlayer().getAnimation() == 5713) {
- return true;
- }
- if(getMyPlayer().getAnimation() == 11786) {
- return true;
- }
- return false;
- }
- // ANTI-BAN STUFF
- public int antiBan() {
- Point m;
- int x = random(0, 750);
- int y = random(0, 500);
- int xx = random(710, 554);
- int yy = random(444, 230);
- int screenx = random(1, 510);
- int screeny = random(1, 450);
- int gamble = random(0, 22);
- final long start = System.currentTimeMillis();
- final RSPlayer myPlayer = getMyPlayer();
- int anim = -1;
- while (System.currentTimeMillis() - start > 2000) {
- if ((anim = myPlayer.getAnimation()) != -1) {
- break;
- }
- sleep(15);
- }
- switch (gamble) {
- case 1:
- sleep(random(1000, 2500));
- break;
- case 2:
- mouse.move(x, y);
- while (System.currentTimeMillis() - start > 2000) {
- if ((anim = myPlayer.getAnimation()) != -1) {
- break;
- }
- sleep(random(15, 55));
- }
- sleep(random(1000, 2500));
- break;
- case 3:
- game.openTab(Tab.INVENTORY);
- sleep(random(1000, 2500));
- break;
- case 4:
- if (getMyPlayer().isMoving()) {
- sleep(random(1000, 2500));
- break;
- }
- case 5:
- mouse.move(x, y);
- int checkTime = 0;
- long lastCheck = 0;
- sleep(random(1000, 2500));
- if (System.currentTimeMillis() - lastCheck >= checkTime) {
- lastCheck = System.currentTimeMillis();
- checkTime = random(60000, 180000);
- break;
- }
- case 6:
- if (game.getTab() != Tab.STATS) {
- game.openTab(Tab.STATS);
- mouse.move(xx, yy);
- sleep(random(2000, 3500));
- game.openTab(Tab.INVENTORY);
- break;
- }
- case 7:
- sleep(random(750, 1500));
- break;
- case 8:
- mouse.move(screenx, screeny);
- sleep(random(750, 1500));
- break;
- case 9:
- mouse.move(screenx, screeny);
- sleep(random(750, 1500));
- break;
- case 10:
- game.openTab(game.getRandomTab());
- sleep(random(750, 1500));
- break;
- case 11:
- mouse.move(x, y);
- sleep(random(750, 1500));
- break;
- case 13:
- mouse.move(x, y);
- sleep(random(750, 1500));
- break;
- case 12:
- mouse.move(x, y);
- sleep(random(750, 1500));
- break;
- case 14:
- m = mouse.getLocation();
- sleep(random(300, 500));
- mouse.move(m, 20, 20);
- sleep(random(100, 200));
- break;
- case 15:
- m = mouse.getLocation();
- sleep(random(300, 500));
- mouse.move(m, 20, 20);
- sleep(random(100, 200));
- break;
- case 16:
- m = mouse.getLocation();
- sleep(random(300, 500));
- mouse.move(m, 20, 20);
- sleep(random(100, 200));
- break;
- case 17:
- m = mouse.getLocation();
- sleep(random(300, 500));
- mouse.move(m, 20, 20);
- sleep(random(100, 200));
- break;
- case 19:
- mouse.move(x, y);
- sleep(random(750, 1500));
- break;
- case 20:
- mouse.move(x, y);
- sleep(random(750, 1500));
- break;
- case 21:
- mouse.move(x, y);
- sleep(random(750, 1500));
- break;
- }
- return 100;
- }
- // Grand exchange price lookup
- private int getPrice(int itemID) {
- try {
- URL url = new URL(GE_URL + String.valueOf(itemID));
- BufferedReader x = new BufferedReader(new InputStreamReader(
- url.openStream()));
- String inputLine;
- while ((inputLine = x.readLine()) != null) {
- if (inputLine
- .contains("<th scope=\"row\">Current guide price:</th>")) {
- return (int) parsePrice(x.readLine());
- }
- }
- x.close();
- } catch (MalformedURLException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- return -1;
- }
- private double parsePrice(String str) {
- if (str != null && !str.isEmpty()) {
- str = stripFormatting(str);
- str = str.substring(str.indexOf(58) + 1, str.length());
- str = str.replace(",", "");
- str = str.trim();
- if (!str.endsWith("%")) {
- if (!str.endsWith("k") && !str.endsWith("m")
- && !str.endsWith("b")) {
- return Double.parseDouble(str);
- }
- return Double.parseDouble(str.substring(0, str.length() - 1))
- * (str.endsWith("b") ? 1000000000
- : str.endsWith("m") ? 1000000 : 1000);
- }
- final int k = str.startsWith("+") ? 1 : -1;
- str = str.substring(0);
- return Double.parseDouble(str.substring(0, str.length() - 1)) * k;
- }
- return -1D;
- }
- private String stripFormatting(final String str) {
- if (str != null && !str.isEmpty()) {
- return str.replaceAll("(^[^<]+>|<[^>]+>|<[^>]+$)", "");
- }
- return "";
- }
- // End Grand exchange price lookup
- JButton startButton;
- JComboBox whereandwhat;
- JLabel text;
- public class MegaGUI extends JFrame implements ActionListener {
- public MegaGUI() {
- setTitle("MegaPlanker");
- startButton = new JButton("Start");
- text = new JLabel("What plank to make?");
- whereandwhat = new JComboBox(list);
- setLayout(null);
- setResizable(false);
- setSize(390, 255);
- setLocationRelativeTo(null);
- text.setBounds(20, 20, 182, 21);
- startButton.setBounds(135, 148, 83, 28);
- startButton.addActionListener(this);
- whereandwhat.setBounds(65, 71, 200, 22);
- add(text);
- add(whereandwhat);
- add(startButton);
- setVisible(true);
- }
- @Override
- public void actionPerformed(ActionEvent e) {
- if (e.getActionCommand().contains("Start")) {
- if (whereandwhat.getSelectedItem().toString().equals("Wood plank")) {
- lID = 1511;
- pID = 960;
- makePrice = 100;
- iComponent = 12;
- pName = "Wood plank";
- log("Making wood planks");
- } else if (whereandwhat.getSelectedItem().toString()
- .equals("Oak plank")) {
- lID = 1521;
- pID = 8778;
- makePrice = 250;
- iComponent = 13;
- pName = "Oak plank";
- log("Making oak planks");
- } else if (whereandwhat.getSelectedItem().toString()
- .equals("Teak plank")) {
- lID = 6333;
- pID = 8780;
- makePrice = 500;
- iComponent = 14;
- pName = "Teak plank";
- log("Making teak planks");
- } else if (whereandwhat.getSelectedItem().toString()
- .equals("Mahogany plank")) {
- lID = 6332;
- pID = 8782;
- iComponent = 15;
- makePrice = 1500;
- pName = "Mahogany plank";
- log("Making mahogany planks");
- }
- dispose();
- setVisible(false);
- start = true;
- }
- }
- }
- JButton oB;
- JButton gN;
- JLabel oL;
- public class VersionGUI extends JFrame implements ActionListener {
- public VersionGUI() {
- setTitle("OUTDATED");
- oB = new JButton("Okay");
- oL = new JLabel("OUTDATED");
- gN = new JButton("Get new version");
- setLayout(null);
- setResizable(false);
- setSize(150, 185);
- setLocationRelativeTo(null);
- oB.setBounds(20, 35, 65, 25);
- gN.setBounds(20, 85, 115, 25);
- oB.addActionListener(this);
- gN.addActionListener(this);
- oL.setBounds(20, 5, 182, 21);
- add(oL);
- add(gN);
- add(oB);
- setVisible(true);
- }
- public void getNewVersion() {
- File directory = getCacheDirectory();
- File newDirectory =
- new File(new File(new File(directory.getParent()).getParent()).getParent()
- + File.separator + "Scripts" + File.separator +
- "Sources" + File.separator + "MegaPlanker.java");
- BufferedInputStream in;
- try {
- in = new BufferedInputStream(
- new URL("http://megascripts.comyr.com/MegaPlanker/MegaPlanker.java").openStream());
- FileOutputStream fos = new FileOutputStream(newDirectory);
- BufferedOutputStream bout = new BufferedOutputStream(fos,1024);
- byte[] data = new byte[1024];
- int x=0;
- while((x=in.read(data,0,1024))>=0) {
- bout.write(data,0,x);
- }
- bout.close();
- in.close();
- } catch (MalformedURLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- @Override
- public void actionPerformed(ActionEvent e) {
- if (e.getActionCommand().contains("Okay")) {
- dispose();
- setVisible(false);
- }
- if (e.getActionCommand().contains("Get new version")) {
- getNewVersion();
- sleep(1000);
- oL.setText("Recompile the script");
- repaint();
- stopScript();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment