How to create an Reload command?

Discussion in 'Plugin Development' started by xDjBomber, Feb 29, 2012.

Thread Status:
Not open for further replies.
  1. Hey, what is false with this code? look:
    I will make an reload function, for my plugin .. thanks :)
    Code:
      } else if (args.length == 1 && args[0].equalsIgnoreCase("Reload")) {
    if (player != null); 
    if (player.hasPermission("promotion.reload")) {
        this.reloadConfig();
        this.saveConfig();
        player.sendMessage(ChatColor.GREEN + "[AutoPromotion] Config reloaded!"); 
        System.out.println("[AutoPromotion] Config reloaded!");
        return true;
    }    
     
  2. Offline

    RROD

    Code:Java
    1. } else if (args.length == 1 && args[0].equalsIgnoreCase("Reload")) {
    2. if (!player instanceof Player) {
    3. // If player is not an instanceof Player, then it's the console sending the command.
    4. this.reloadConfig();
    5. this.saveConfig();
    6. Bukkit.getLogger().info("[AutoPromotion] Config Reloaded! ");
    7. // Returns true because the console can execute anything.
    8. return true;
    9. } else if (player.hasPermission("promotion.reload")) {
    10. // If it's not the console, then it's a player. Check their permission and execute if they have.
    11. this.reloadConfig();
    12. this.saveConfig();
    13. player.sendMessage(ChatColor.GREEN + "[AutoPromotion] Config reloaded!");
    14. System.out.println("[AutoPromotion] Config reloaded!");
    15. return true;
    16. // Return true if this plugin executed this command.
    17. } else {
    18. return false;
    19. // Returns false because the player didn't have permission, so it wasn't executed.
    20. }
    21. }
     
    xDjBomber likes this.
  3. THANKS

    Ahh, that doesn't really works, the console say Config reloaded, but it do nothing -_-

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 24, 2016
  4. Offline

    RROD

    Code:Java
    1.  
    2. } else if (args.length == 1 && args[0].equalsIgnoreCase("Reload")) {
    3. if (player instanceof Player) {
    4. if (player.hasPermission("promotion.reload")) {
    5. this.reloadConfig();
    6. this.saveConfig();
    7. player.sendMessage("[AutoPromotion] Config Reloaded! ");
    8. // Return true if this plugin executed this command.
    9. return true;
    10. }
    11. } else {
    12. this.reloadConfig();
    13. this.saveConfig();
    14. Bukkit.getLogger().info(ChatColor.GREEN + "[AutoPromotion] Config reloaded!");
    15. System.out.println("[AutoPromotion] Config reloaded!");
    16. return true;
    17. // Return true if this plugin executed this command.
    18. // Returns true because the console can execute anything.
    19. }
    20. return false;
    21. }


    Try that.
     
  5. Yes, it says config was reloaded, but it' does not save changes.
     
  6. did you make those chances to the confi after reloading, but before save?
     
  7. Yes, i changed what in the Config, but it doesnt work, you can try it with my Plugin, that doesn't work ... the /Promote Reload command ://
     
  8. Offline

    number1_Master

    I'm having the same issue. I have reloadconfig then saveconfig (just like above) but it doesn't seem to work. The config doesn't reload...
     
  9. Yes ... exactly, damn! xD It will not work -.- i've made a new command like /Promote Reload, with this.saveConfig & this.ReloadConfig(); xD but it doesn't work :/
     
  10. Offline

    RROD

    Try and get rid of the saveConfig() and just reload a config with changes.
     
  11. Offline

    Windwaker

    Save, then load

    Edit: idk what I was thinking, try reloading without saving
     
  12. Did you mean
    Code:
     this.saveConfig(); & this.loadConfig(); 
    ?
     
  13. yopu need to call "getConfig()" again after loading, are you guys doing that?
     
  14. Offline

    MrMag518

    Wait, do you want to reload the plugin file, or the config(s) ?
    If you want to reload the file itself(.jar) then this can be a sulution
    Code:java
    1. plugin.getPluginLoader().disablePlugin(plugin);
    2. plugin.getPluginLoader().enablePlugin(plugin);

    Or if it is the config(s), then
    Code:java
    1. plugin.reloadConfig();


    What I use for the file reload command:
    Code:java
    1. public class Reload implements CommandExecutor {
    2. public static pluginname plugin;
    3. public Reload(pluginname instance)
    4. {
    5. plugin = instance;
    6. }
    7.  
    8. @Override
    9. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
    10. if(cmd.getName().equalsIgnoreCase("reload-pluginname")) {
    11. if (args.length > 0) {
    12. sender.sendMessage(ChatColor.RED + "To many arguments.");
    13. return false;
    14. }
    15. if (sender instanceof Player) {
    16. Player player = (Player)sender;
    17. if (hasReload(player)) {
    18. plugin.getPluginLoader().disablePlugin(plugin);
    19. plugin.getPluginLoader().enablePlugin(plugin);
    20. sender.sendMessage(ChatColor.YELLOW + "Reloaded "+ ChatColor.GRAY + plugin.getDescription().getFullName());
    21. } else {
    22. sender.sendMessage(ChatColor.RED + "You do not have access to that.");
    23. }
    24. } else {
    25. plugin.getPluginLoader().disablePlugin(plugin);
    26. plugin.getPluginLoader().enablePlugin(plugin);
    27. sender.sendMessage(ChatColor.YELLOW + "Reloaded "+ ChatColor.GRAY + plugin.getDescription().getFullName());
    28. }
    29. return true;
    30. }
    31. return false;
    32. }
    33.  
    34. public boolean hasReload(Player player) {
    35. if (player.hasPermission("pluginname.reload")) {
    36. return true;
    37. } else if (player.hasPermission("pluginname.*")) {
    38. return true;
    39. }
    40. return false;
    41. }
    42. }


    What I use for the config reload:
    Code:java
    1. public class Reload implements CommandExecutor {
    2. public static pluginnameplugin;
    3. public Reload(pluginnameinstance)
    4. {
    5. plugin = instance;
    6. }
    7.  
    8. @Override
    9. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
    10. if(cmd.getName().equalsIgnoreCase("reload-pluginname")){
    11. if (args.length > 0) {
    12. sender.sendMessage(ChatColor.RED + "Too many arguments!");
    13. return false;
    14. }
    15. PluginDescriptionFile pdffile = plugin.getDescription();
    16. if (sender instanceof Player) {
    17. Player player = (Player)sender;
    18. if (hasReload(player)) {
    19. plugin.reloadConfig();
    20. sender.sendMessage(ChatColor.AQUA + pdffile.getFullName() + ChatColor.GRAY + " reloaded files succesfully");
    21. System.out.println("[pluginname] "+ (sender.getName() + " reloaded" + (pdffile.getFullName())));
    22. } else {
    23. sender.sendMessage(ChatColor.RED + "You do not have access to that." );
    24. }
    25. } else {
    26. plugin.reloadConfig();
    27. plugin.log.info("[pluginname] " + pdffile.getName() + " was succesfully reloaded");
    28. }
    29. return true;
    30. }
    31. public boolean hasReload(Player player) {
    32. if (player.hasPermission("pluginname.reload")) {
    33. return true;
    34. } else if (player.hasPermission("pluginname.*")) {
    35. return true;
    36. }
    37. return false;
    38. }
     
  15. Thanks! will try that now :-P
     
Thread Status:
Not open for further replies.

Share This Page