Problem with reloadConfig();

Discussion in 'Spigot Plugin Development' started by JuanDouCore_, May 26, 2017.

  1. So I'm creating a plugin that with the command /censurar palabra [Arg], I'll add that word to a stringlist that I have in the config, because I add it, then execute /censurar recargar it, which would be to reload the config as well The change of the config.yml in the chat, but it does not work and if the word comes to the config.yml but the change does not result in the server
    Here I leave the code of what I am doing so find the problem:
    Code (Text):
        if ((command.getName().equalsIgnoreCase("censurar")) &&
        (sender instanceof Player))
            Player p = (Player)sender;
            if (args.length == 0)
                p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&dCensura &8» &bDebes especificar la palabra que censuraras EJ: /censurar mediacraft"));
            } else if (args[0].equalsIgnoreCase("palabra"))
                if (args.length == 2)
                    List<String> l = new ArrayList();
                    if (getConfig().getStringList("Palabras") != null)
                        l = getConfig().getStringList("Palabras");
                    getConfig().set("Palabras", l);
                    p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&dCensura &8» has censurado la palabra&c")+ args[1]);
            } else if (args[0].equalsIgnoreCase("recargar"))
  2. The problem might not be on the command itself, show us how you're managing the list on the chat listener class.
    I recommend you, adding words to a Set of Strings, instead of checking your config file every time someone sends a message, specially because it can get slower the more words you add to it. Save that Set when server disables, and load them all when server boots.
  3. I had this similar problem in a plugin I made called randomspawn. Luckily, the amazing @Gianluca came to the rescue and solved my dilema. We made a "loadConfig" and put the FileConfiguration stuff in it. We then call loadConfig in onEnable. The source code is on my github, look at the main and commands class (/rsreload section).
  4. I'm not sure if this is solved or not, but once you reload the config you also need to re-initialize your variables