Reload command using the new Config API

Discussion in 'Plugin Development' started by thehutch, Oct 19, 2011.

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

    thehutch

    Could anyone help with make a reload command using the new config this is what I had before and it worked:
    Code:java
    1. @Override
    2. public boolean onCommand(CommandSender cs, Command cmd, String alias, String[] args) {
    3. if ((cmd.getName().equalsIgnoreCase("mcreload")) && (cs.hasPermission("mchardcore.reload") || cs.isOp())) {
    4. log.info("initiating plugin reload...");
    5. config = this.getConfig();
    6. try {
    7. config.load(new File(this.getDataFolder() + File.separator + "config.yml"));
    8. } catch (Exception ex){
    9. ex.printStackTrace();
    10. }
    11. Player[] pl = getServer().getOnlinePlayers();
    12.  
    13. for(int i=0; i < pl.length; i++) {
    14.  
    15. SpoutPlayer sp = (SpoutPlayer)pl[i];
    16. if(!sp.isSpoutCraftEnabled()) {
    17. continue;
    18. }
    19. Event ev = new SpoutCraftEnableEvent(sp);
    20. getServer().getPluginManager().callEvent(ev); //Calls this event
    21. }
    22. log.info("reload successful");
    23. cs.sendMessage(ChatColor.DARK_RED + "[" + ChatColor.GREEN+"MCHardcore"+ChatColor.DARK_RED+"] has been reloaded");
    24. return true;
    25. } else {
    26. cs.sendMessage(ChatColor.RED+"You do not have permission!");
    27. }
    28. return false;
    29. }[/i]

    Mainly I think its just the config = getConfig() and the load part aswell
    Any help is appreciated
     
  2. Offline

    Sagacious_Zed Bukkit Docs

    @thehutch
    you're doing it wrong, all you need to do to reload a config is call reloadConfig();
    This
    Code:
                    config = this.getConfig();
                try {
                    config.load(new File(this.getDataFolder() + File.separator + "config.yml"));
                } catch (Exception ex){
                    ex.printStackTrace();
                }  
    becomes this
    Code:
    this.reloadConfig()
     
  3. Offline

    thehutch

    Thank you and btw that was what I had but thanks
     
  4. What the heck are you doing with that command anyway :confused:
     
    thehutch likes this.
  5. Offline

    thehutch

    I was trying to reload my plugin and call an event so my plugin updates everything automatically for the player, rather than having to do /reload
    Yes now instead of that I have updated to a single method but now for some reason my plugin wont update automatically
     
  6. Why are you firing SpoutCraftEnable events?
     
  7. Offline

    thehutch

    Because that was what I used so when a player who is using spoutcraft joined the server they would automatically do what was in my method :)
     
  8. Offline

    Windwaker

    Would it be a bad idea to reload the config whenever you save it? ex:
    Code:java
    1. public void configSave(){
    2. saveConfig();
    3. reloadConfig();
    And just use that whenever you want to save?
     
  9. Offline

    Sagacious_Zed Bukkit Docs

    Yes, bad idea, completely not necessary. It's like saving a word document and then closing word, to open word and your document again.
     
    Zaros likes this.
Thread Status:
Not open for further replies.

Share This Page