Solved Help with AutoUpdater?

Discussion in 'Plugin Development' started by 22vortex22, Apr 12, 2014.

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

    22vortex22

    Hey, guys I recently added the auto updater to my plugin and I wish I didn't because it has caused so many problems.

    [​IMG]

    Could you guys help me fix this please as I don't know how?
    Here is my main:
    Code:java
    1. package com.gmail.codervortex;
    2.  
    3.  
    4. import java.io.File;
    5. import java.util.ArrayList;
    6.  
    7. import org.bukkit.event.Listener;
    8. import org.bukkit.plugin.PluginManager;
    9. import org.bukkit.plugin.java.JavaPlugin;
    10.  
    11. import com.gmail.codervortex.Updater.ReleaseType;
    12.  
    13.  
    14. public class Main extends JavaPlugin implements Listener
    15. {
    16. private static Main plugin;
    17. private Events events = new Events(this);
    18. private com.gmail.codervortex.GuiListener GUI = new GuiListener(this);
    19. private com.gmail.codervortex.Updater updater;
    20. public ArrayList<String> kits = new ArrayList<String>();
    21. public ArrayList<String> AssassinCooldown = new ArrayList<String>();
    22. public ArrayList<String> Assassin = new ArrayList<String>();
    23.  
    24.  
    25. public static boolean update = false;
    26. public static String name = "";
    27. public static ReleaseType type = null;
    28. public static String version = "";
    29. public static String link = "";
    30.  
    31.  
    32.  
    33. @Override
    34. public void onEnable() {
    35. plugin = this;
    36. getServer().getPluginManager().registerEvents(this, this);
    37. getLogger().info("Easy Pvp Kits v.1.1.2 is now Enabled.");
    38. getCommands();
    39. PluginManager pm = getServer().getPluginManager();
    40. pm.registerEvents(events, this);
    41. pm.registerEvents(GUI, this);
    42. getConfig().options().copyDefaults(true);
    43. saveConfig();
    44. saveResource("config.yml", true);
    45.  
    46.  
    47.  
    48.  
    49.  
    50. updater = new Updater(this, 66838, this.getFile(), Updater.UpdateType.NO_DOWNLOAD, false); // Start Updater but just do a version check
    51. update = updater.getResult() == Updater.UpdateResult.UPDATE_AVAILABLE; // Determine if there is an update ready for us
    52. name = updater.getLatestName(); // Get the latest name
    53. version = updater.getLatestGameVersion(); // Get the latest game version
    54. type = updater.getLatestType(); // Get the latest file's type
    55. link = updater.getLatestFileLink(); // Get the latest link
    56. }
    57.  
    58. @Override
    59. public void onDisable(){
    60. getLogger().info("Easy Pvp Kits is now Disabled. - Made by Vortex");
    61. }
    62.  
    63.  
    64. public static Main getPlugin() {
    65. return plugin;
    66. }
    67.  
    68. public File getPluginFile() {
    69. return this.getFile();
    70. }
    71.  
    72.  
    73. public void getCommands(){
    74. getCommand("Kits").setExecutor(new com.gmail.codervortex.Commands.kits(this));
    75. getCommand("Reset").setExecutor(new com.gmail.codervortex.Commands.Reset(this));
    76. getCommand("Archer").setExecutor(new com.gmail.codervortex.Kits.Archer(this));
    77. getCommand("Assassin").setExecutor(new com.gmail.codervortex.Kits.Assassin(this));
    78. getCommand("Heavy").setExecutor(new com.gmail.codervortex.Kits.Heavy(this));
    79. getCommand("Pyro").setExecutor(new com.gmail.codervortex.Kits.Pryo(this));
    80. getCommand("Pvp").setExecutor(new com.gmail.codervortex.Kits.Pvp(this));
    81. getCommand("Update").setExecutor(new com.gmail.codervortex.Commands.update(this));
    82. }
    83. }
    84.  


    Here is the auto updater class:
    http://pastebin.com/29D8cVLH

    Thank you for looking into this
     
  2. Offline

    Trevor1134

    Not sure what you issue is, as you didn't really elaborate on that, but if the issue is that the config is getting reset every server start, it is because the saveResource() paramaters are: (File, boolean replaceExisting). Meaning right now you are resetting the config.yml to the current setup.
     
  3. Offline

    22vortex22

    How would I fix that. Also BUMP
     
  4. Offline

    Trevor1134

    22vortex22 replace the saveResource() method from true to false. On line: 44
    Code:
    saveResource("config.yml", false);
    
    Why aren't you just using the simple this.saveConfig();
     
  5. Offline

    skyrimfan1

    To auto-download a update (provided you have encased in some form of a permissions check) use:
    Code:
    updater = new Updater(this, 66838, this.getFile(), Updater.UpdateType.NO_VERSION_CHECK, true);
    That's the only thing I can say. I don't really know what your error is since you haven't provided any context.
    Now he has both. :p
    Just do saveConfig(). It's much easier than saveResource() and less liable to break.
     
  6. Offline

    22vortex22

    I know how to start the download/check, the guy in the picture is telling me how to toggle it fully and would saveConfig create a file?
     
  7. Offline

    skyrimfan1

    If you know how to use the updater which you've even explicitly stated ...
    Then, why did you create this thread? There's been too much general ambiguity regarding what your problem is. Is it the config? The updater?

    If you look here, you can see that getConfig() simply calls save on the actual config file. So yes, it would create a file if one is not present already.
     
  8. Offline

    22vortex22

    I know that, I'm asking on help on what the bukkit mod said.... He said to make an if statement around something, but I don't know what and I don't know how to make the config not reset on startup.
     
  9. Offline

    MrInspector

    I actually didn't read this thread other than the post you just said, but you can use the save default config method to not reset on start up.
     
  10. Offline

    AoH_Ruthless

    22vortex22
    CaptainBern kind of spelled it all out there for you in his helpful message. Anyone with a basic understanding of Java should have the capabilities of reading and understanding his message to you.

    When you declare your updater variable by assigning it to your project, you need to place that in an if statement so it can actually be toggled in the config.

    Code:java
    1. if (getConfig().getBoolean("path.to.string")) {
    2. // DEFINE UPDATER
    3. }
     
  11. Offline

    22vortex22


    Okay I get that, but do I just put it around the whole class? (I know that sounds super stupid.) Where do I put the if statement? I know what to do I just don't know where. And I'm still confused on what I use for the config.

    Basically i'm asking what do you mean by define updater?

    Updater.java?

    or

    Code:java
    1. updater = new Updater(this, 66838, this.getFile(), Updater.UpdateType.NO_DOWNLOAD, false); // Start Updater but just do a version check
    2. update = updater.getResult() == Updater.UpdateResult.UPDATE_AVAILABLE; // Determine if there is an update ready for us
    3. name = updater.getLatestName(); // Get the latest name
    4. version = updater.getLatestGameVersion(); // Get the latest game version
    5. type = updater.getLatestType(); // Get the latest file's type
    6. link = updater.getLatestFileLink(); // Get the latest link


    or what? I think it was the second one right?

    So I got everything else fixed but if I just use saveConfig() and getConfig() it doesn't create a file to be edited? Help I'ts my last thing.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  12. Offline

    Garris0n

    I'd explain something but you have a perfectly good explanation of exactly what's wrong by CaptainBern in your post.
     
  13. Offline

    AoH_Ruthless


    Again, that's basic Java ... how on earth can you place an if statement around a whole class?

    22vortex22
    saving and getting doesn't create a new config. You have to use saveDefaultConfig() to load it. If you use saveDefaultConfig(), you need your config.yml as an embedded resource.
     
  14. Offline

    22vortex22


    >.> I know basic java I just didn't know where to put the if statement... anyways I found that and here is my main onEnable and for some reason the config resets on start up? Help?


    Code:java
    1. @Override
    2. public void onEnable() {
    3. plugin = this;
    4. getServer().getPluginManager().registerEvents(this, this);
    5. getLogger().info("Easy Pvp Kits v.1.1.2 is now Enabled.");
    6. getCommands();
    7. PluginManager pm = getServer().getPluginManager();
    8. pm.registerEvents(events, this);
    9. pm.registerEvents(GUI, this);
    10.  
    11. File file = new File("plugins" + File.separator + "EasyPvpKits" + File.separator + "config.yml");
    12. if(file.exists()){
    13. return;
    14. }
    15. else{
    16. saveResource("config.yml", true);
    17. getConfig();
    18. }
    19. if(plugin.getConfig().getBoolean("options.auto-update")){
    20. updater = new Updater(this, 66838, this.getFile(), Updater.UpdateType.NO_DOWNLOAD, false); // Start Updater but just do a version check
    21. update = updater.getResult() == Updater.UpdateResult.UPDATE_AVAILABLE; // Determine if there is an update ready for us
    22. name = updater.getLatestName(); // Get the latest name
    23. version = updater.getLatestGameVersion(); // Get the latest game version
    24. type = updater.getLatestType(); // Get the latest file's type
    25. link = updater.getLatestFileLink(); // Get the latest link
    26. }
    27. getLogger().info("EasyPvpKits's Auto Update Function is disabled. You can reactivate it in the config.");
    28. }
     
  15. Offline

    AoH_Ruthless

    22vortex22
    File file = new File(this.getDataFolder(), "config.yml"); is an easier way of doing it.

    And if the file doesn't exist, shouldn't you be creating it? I don't know what your saveResource method entails so please paste that.
     
  16. Offline

    22vortex22



    Its not a custom Method.
     
  17. Offline

    AoH_Ruthless

    22vortex22
    I had a massive brain leak, sorry.

    saveResource only works for embedded files; is your config embedded? If so, then you don't even need to define it as a file and check if it exists or not because it will always exist.

    Therefore since it exists, your onEnable is returning and it loads a blank file..
     
Thread Status:
Not open for further replies.

Share This Page