New Version Message

Discussion in 'Plugin Development' started by IcyRelic, Jul 17, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    IcyRelic

    Here is a quick tutorial on how to tell the admins there is a new update available for you plugin

    add this boolean to you main class
    Code:java
    1. public boolean updates = false;


    add this to the onEnable
    Code:java
    1. checkVersion("Version: " + getDescription().getVersion());


    Now Create the checkVersion Method
    Code:java
    1. public void checkVersion(String s){
    2.  
    3. try {
    4. URL url = new URL("[url]http://your-domain.com/your-file.html[/url]");
    5.  
    6. BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
    7. String str;
    8. while ((str = in.readLine()) != null) {
    9. if(str.equals(s)){
    10. updates = false;
    11. log.info("[your plugin] No Updates!");
    12. }else{
    13. updates = true;
    14. log.info("[your plugin] Newer version is Available! " + str);
    15. }
    16. }
    17.  
    18. in.close();
    19.  
    20.  
    21.  
    22. } catch (IOException e) {
    23. e.printStackTrace();
    24. }
    25.  
    26. }


    now to broadcast the message to the ops and admins create a PlayerJoinEvent
    Code:java
    1. @EventHandler()
    2. public void join(PlayerJoinEvent event){
    3. Player p = event.getPlayer();
    4. if(p.hasPermission("some.permission") || p.isOp()){
    5. if(updates == true){
    6. p.sendMessage("There is a newer version of <your plugin> available for download!");
    7. }else{
    8. p.sendMessage("<your plugin> is up to date!");
    9. }
    10. }
    11. }

    now to create the html file and upload it to your website

    Code:
    Version: 1.0

    Hope this helped!
     
  2. Offline

    Bauer

    Why is the String in your URL object wrapped in BBCode URL tags lol.

    Also, just a suggestion and nothing major. I'd recommend not storing the version in a format like "Version: 1.0", but rather something simple like "1.0". That allows you to easily perform inequality operations on it (after parseDoubling it of course) which is much better (imo) than just checking if it's not equal. Like i said, its a small detail but it can be useful.

    Nice resource.
     
  3. Offline

    IcyRelic

    they can change that its just that way i did it :D lol and i have no ide why its

    edit: the url tags wont go away
     
  4. is there an version that works whit bukkit dev whit this?
     
  5. ferrybig AutoUpdate not only uses bukitdev but also makes (semi)automated updates possible and has many other features like multithreading (no in-game lag cause of slow network I/O), updating all plugins (using it) with one command, ... ;)
     
  6. Offline

    bfgbfggf

    hyyym. this method still work?
    I have a error in console at
    checkVersion("Version: " + getDescription().getVersion());
    Null pointer exception.

    Hyyym. I find error and work. but I have many lines in console from:
    log.info("[your plugin] Newer version is Available! " + str);

    Maybe is from hosting? because is full of html staff. center blah blah

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 27, 2016
Thread Status:
Not open for further replies.

Share This Page