Config not saving

Discussion in 'Plugin Development' started by RedstoneGamer54, Aug 13, 2018.

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

    RedstoneGamer54

    I am new at making plugins and i was trying to make it so I can add my discord link by doing /link (discord link) and having people do /discord to find my discord link. This is what i have but it wont work:
    Code:
    package me.RedstoneGamer54;
    
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class DiscordPlugin extends JavaPlugin{
      
        @Override
        public void onEnable() {
        }
      
        @Override
        public void onDisable() {
          
        }
      
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
          
    Player player = (Player) sender;
          
            FileConfiguration config = this.getConfig();
          
            //Gives OP player the ability to change link
            if (cmd.getName().equalsIgnoreCase("link") && sender instanceof Player) {
              
                if (player.isOp())
                  
                    if (args.length >= 0) {
                      
                        String disMessage = "";
                  
                        for (String arg : args) {
                            disMessage = disMessage + arg;
                            saveConfig();
                          
                        }
                      
                        }
              
                return true;
              
            }
          
            //Tells The Player The Discord Link
            if (cmd.getName().equalsIgnoreCase("discord") && sender instanceof Player) {
              
                for (String key : config.getKeys(false)) {
                    player.sendMessage(ChatColor.DARK_BLUE + key + config.getString(key) + "");
                }
              
                return true;
            }
          
            return false;
        }
          
    }
    Heres my plugin.yml:
    Code:
    name: DiscordPlugin
    main: me.RedstoneGamer54.DiscordPlugin
    version: 1.0
    commands:
        link:
            description: Change Your Discord Link Or Message. Ex. /discordlink Join Our Discord At (discord link)
            usage: /<command>
        discord:
            description: See What The Server's Discord Is
            usage: /<command>
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Aug 13, 2018
  2. Online

    timtower Administrator Administrator Moderator

  3. Offline

    johnny boy

    as timtower said, all
    Code:Java
    1.  
    2. disMessage = disMessage + arg;
    3. saveConfig();

    is doing is assigning disMessage to whatever and saving your (empty) config.

    you have to get the config with getConfig() and then set whatever to whatever using getConfig().set(path, string), then save it.
     
  4. Offline

    RedstoneGamer54

    I may sound like an idiot but what do i put for the path and string
     
    Last edited: Aug 14, 2018
  5. Offline

    RedstoneGamer54

    I figured out the string but what do i use for the path?
    Its been 20 days since my original post and I still don't know how
     
    Last edited: Aug 23, 2018
  6. Offline

    ewrs

    Hey. I'm using reloadConfig ()
     
  7. Online

    timtower Administrator Administrator Moderator

    Path is where you load the value from and where you save it.
     
  8. Offline

    RedstoneGamer54

    So would the path be config?
     
  9. Online

    timtower Administrator Administrator Moderator

    Depends on where you want to store the values in the config.
    link and discord seems logical paths in your case as you want to work with those.
     
  10. Offline

    RedstoneGamer54

    Would it be like this or did i do it wrong?
    Code:
    for (String arg : args) {
                            disMessage = disMessage + arg;
                            getConfig().set("link", disMessage);
                            saveConfig();
    
     
  11. Online

    timtower Administrator Administrator Moderator

    @RedstoneGamer54 Did you try it?
    And set the config after the complete loop.
     
  12. Offline

    RedstoneGamer54

    I restarted my server and when i did /plugins it wasn't there
     
  13. Online

    timtower Administrator Administrator Moderator

  14. Offline

    RedstoneGamer54

    So the latest server log in the log folder?
     
  15. Online

    timtower Administrator Administrator Moderator

  16. Offline

    RedstoneGamer54

    Do I just post the link to it?
     
  17. Online

    timtower Administrator Administrator Moderator

  18. Offline

    RedstoneGamer54

  19. Online

    timtower Administrator Administrator Moderator

    Locked
    Protocol hacks are not supported by Bukkit (ViaVersion+ViaBackwards)
     
Thread Status:
Not open for further replies.

Share This Page