package io.github.thatsmusic99.headsplus.api.rewards;

import io.github.thatsmusic99.configurationmaster.api.ConfigSection;
import io.github.thatsmusic99.headsplus.api.Challenge;
import io.github.thatsmusic99.headsplus.api.Reward;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

import java.util.List;

public class RunCommandReward extends Reward {

    private List<String> commands;

    public RunCommandReward(int xp, List<String> commands) {
        super(xp);
        this.commands = commands;
    }

    public static RunCommandReward fromConfigSection(String id, ConfigSection section) {
        return null;
    }

    @Override
    public void rewardPlayer(Challenge challenge, Player player) {
        super.rewardPlayer(challenge, player);
        for (String command : commands) {
            if (command.startsWith("player>")) {
                Bukkit.dispatchCommand(player, command.substring(8).replaceAll("\\{player}", player.getName()));
                return;
            }
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command.replaceAll("\\{player}", player.getName()));
        }
    }

    @Override
    public String getDefaultRewardString(Player player) {
        return null;
    }
}

@@ -368,16 +368,22 @@
 private 
+final 
 List%3CStr
@@ -397,16 +397,16 @@
 mmands;%0A
-
 %0A    pub
@@ -612,35 +612,372 @@
 ) %7B%0A        
-return null
+if (!section.contains(%22base-value%22) && !section.contains(%22reward-value%22))%0A            throw new IllegalStateException(%22Reward type RUN_COMMAND for reward %22 + id + %22 must have a base-value option!%22);%0A        return new RunCommandReward(section.getInteger(%22base-xp%22, 0),%0A                section.getList(%22base-value%22, section.getList(%22reward-value%22)))
 ;%0A    %7D%0A%0A   

Implement RUN_COMMAND reward