How to save arguments to yml file

Discussion in 'Plugin Development' started by ZeyNet, Dec 30, 2021.

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

    ZeyNet

    Please help))
    There is a command / feedback <text>. How to save <text> to feedbacks.yml file
     
  2. Offline

    timtower Administrator Administrator Moderator

    @ZeyNet Turn the text into a single string, get a string list from the file, add the line, set the list to the file, save file.
     
  3. Offline

    ZeyNet

    I am learning to create plugins. And I just can't find a solution. I tried to do something using the code of similar plugins and so on. This is what I have now

    CODE (open)
    PHP:
    package review.review;

    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.configuration.file.YamlConfiguration;

    import java.io.File;
    import java.io.IOException;
    import java.util.ArrayList;
    import java.util.List;

    public class 
    CommandReview implements CommandExecutor {
        private 
    Review plugin;

        public 
    CommandReview (Review plugin) {
            
    this.plugin plugin;
        }

        @
    Override
        
    public boolean onCommand(CommandSender senderCommand cmdString labelString[] args) {

            
    File review = new File("plugins/Review/review.yml");
            
    FileConfiguration players YamlConfiguration.loadConfiguration(review);


            List<
    String> list = players.getStringList("Review");

            if(list.
    isEmpty()) list = new ArrayList<String>();

            if(
    args.length <= 0){
                
    sender.sendMessage("use: /review <t/t>");
                return 
    false;
            }
            else {

                list.
    add(args[0]);

                
    players.set("review", list);

                try {
                    
    players.save(review);
                } catch (
    IOException e1) {
                    
    e1.printStackTrace();
                }

                return 
    true;

            }
        }

    }

    In review.yml only adds / review save don't save

    And on the next attempt, a new record is not added to review.yml, but replaces the previous one.
     
  4. Offline

    timtower Administrator Administrator Moderator

    @ZeyNet Do note that you have 2 different paths that you are using.
     
Thread Status:
Not open for further replies.

Share This Page