Jump to content

How to make an update notification for your script


Diclonius

Recommended Posts

First up I'm not a java expert so there maybe be bad java practice in this tutorial. It would help if you could point out things I have done wrong smile.png. Also I'm pretty tired when making this so there is bound to be at lease one mistake. I hope you guys appreciate the time it took to take, crop and upload all these damn pictures.

 

So first up your script should look something like this (But hopefully you can spell your own username correctly).


 

Now the first thing we are going to do is create a new variable of type long called lastCheck. This is going to hold the time that we last checked for an update. We also want to set this variable to the current time which we do by setting it to System.currentTimeMillis() in the onstart method. Finally we are going to create a new method, checkForUpdate()


 

So we want to make the script check for an update every 10 minutes so if the last time we checked, plus 600000 milliseconds is less than the current time in milliseconds, we want to check for an update.


 

Ok so how are we actually going to check for an update? Well we are going to create a paste on the website http://pastebin.com/ . Browse to this website and click sign up (Unless you already have an account).


 

Now you should fill in the details and do what you need to do to create an account. After this is done sign in and create a new paste.


 

Next we want to fill in the version of your script and also name it at the bottom.


 

Then click on raw


 

This will open up a new page which will only contain our script version. We want to copy the URL of this page.


 

Now we need to have this URL in a way the script can actually use it so we create a new URL object. Change the URL to your URL and import URL.


 

Add a try/catch


 

Now we want to change the exception type because we are going to be doing some other stuff aswell


 

Now we need to read what is at the URL so we create a scanner that scans the URL and then we store the first line of text that the scanner gets in the variable latestVersion. Finally we close the scanner (Very important).


 

Then we can get the version of our script and convert it into a string too so that they are both the same type. Also we print out the two versions and also an error message in the catch section which is ran if there was an error.


 

Now let's be a cool kid and check if the two versions are the same


 

So we want something to actually happen if the script is out of date right? So we right click our package and go to new --> other


 

Select Jframe under Windowbuilder --> Swing Designer


 

Give this beast a sensible name


 

Click design which is at the bottom


 

Now it should look like this


 

To make editing the window easy we need to set it to absolute layout. We do this by selecting absolute layout by clicking it, then clicking our window on the right. It should get highlighted in green.


 

Now we want to add a message to the window so click JTextPane and then click on the window. You can then move and resize the object much like you would in Microsoft word.


 

Resize the box to however you want and then select it and press text to add a message.


 

Enter your message in this box


 

Click JButton and click your window on the right to place it. You should resize it too.


 

Click text again and change the text if you want


 

Now the window looks correct we need to make it do stuff, so click source


 

It should now look like this


 

We can remove public static void main because it is only used if this was it's own stand-alone program.


 

Now we want to something to happen when we click the button so we type this and import ActionListener


 

Then add unimplimented methods


 

And it should look like this:


 

Now similarly to what we did before, we create a URI (Different to URL) and import it. The link should be one to your thread or download page.


 

Surround it with a try/catch


 

Now to make the script open this webpage we need to create a desktop instance and import it like so:


 

Then we can use the browse method to open the web page. Remember to add a try/catch:


 

We are nearly done! Just scroll to the top and edit this line to say DISPOSE and not EXIT. This will stop the whole client from closing when this window is closed.


 

Now we need to make our script open the window so we need to create a new global instance of it. Just place it inside the class but outside of any methods:


 

Now we want to make the window visible when an update is detected.


 

And to update the version, all you have to do is edit the version in the script here:


and on pastebin by signing in and editing the paste.

Edited by Diclonius
  • Like 3
Link to comment
Share on other sites

Wow, you've definitely put time in this, thank you for such a very nice guide, I've learned quite a good bit by going through this guide! biggrin.png.

On another note, is it somehow possible to make the script download the new version itself and run it, I don't think the client supports this though? - Atleast I've noticed I have to hit the "Refresh" button each time I edit my script (I like to edit a part, run the script to see that part, etc).

Thanks again

 

Link to comment
Share on other sites

Wow, you've definitely put time in this, thank you for such a very nice guide, I've learned quite a good bit by going through this guide! biggrin.png.

On another note, is it somehow possible to make the script download the new version itself and run it, I don't think the client supports this though? - Atleast I've noticed I have to hit the "Refresh" button each time I edit my script (I like to edit a part, run the script to see that part, etc).

Thanks again

You could make your script just a downloader then make it download the latest script from a server every time it is ran. It's not too difficult at all but it is a bit more complex than this.

Edited by Diclonius
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...