<commit_before>package com.gmail.stefvanschiedev.buildinggame.commands.subcommands;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;

import com.gmail.stefvanschiedev.buildinggame.commands.commandutils.CommandResult;
import com.gmail.stefvanschiedev.buildinggame.commands.commandutils.ConsoleCommand;
import com.gmail.stefvanschiedev.buildinggame.commands.commandutils.SubCommand;
import com.gmail.stefvanschiedev.buildinggame.commands.subcommands.settings.AllowFlyOutBounds;
import com.gmail.stefvanschiedev.buildinggame.commands.subcommands.settings.BlockedEntities;
import com.gmail.stefvanschiedev.buildinggame.commands.subcommands.settings.Blocks;
import com.gmail.stefvanschiedev.buildinggame.commands.subcommands.settings.BossBar;
import com.gmail.stefvanschiedev.buildinggame.commands.subcommands.settings.CleanFiles;
import com.gmail.stefvanschiedev.buildinggame.commands.subcommands.settings.CommandWhitelist;
import com.gmail.stefvanschiedev.buildinggame.commands.subcommands.settings.Commands;
import com.gmail.stefvanschiedev.buildinggame.commands.subcommands.settings.Debug;
import com.gmail.stefvanschiedev.buildinggame.commands.subcommands.settings.EnableSubjectVoting;
import com.gmail.stefvanschiedev.buildinggame.commands.subcommands.settings.Gui;
import com.gmail.stefvanschiedev.buildinggame.commands.subcommands.settings.Loading;
import com.gmail.stefvanschiedev.buildinggame.commands.subcommands.settings.MaxParticles;
import com.gmail.stefvanschiedev.buildinggame.commands.subcommands.settings.MaxVoteChange;
import com.gmail.stefvanschiedev.buildinggame.commands.subcommands.settings.Mobs;
import com.gmail.stefvanschiedev.buildinggame.commands.subcommands.settings.Money;
import com.gmail.stefvanschiedev.buildinggame.commands.subcommands.settings.NamesAfterVoting;
import com.gmail.stefvanschiedev.buildinggame.commands.subcommands.settings.RestorePlots;
import com.gmail.stefvanschiedev.buildinggame.commands.subcommands.settings.ScoreboardUpdateDelay;
import com.gmail.stefvanschiedev.buildinggame.commands.subcommands.settings.SubjectGui;
import com.gmail.stefvanschiedev.buildinggame.commands.subcommands.settings.Subjects;
import com.gmail.stefvanschiedev.buildinggame.commands.subcommands.settings.TeamSelection;
import com.gmail.stefvanschiedev.buildinggame.commands.subcommands.settings.Timer;
import com.gmail.stefvanschiedev.buildinggame.commands.subcommands.settings.Title;
import com.gmail.stefvanschiedev.buildinggame.commands.subcommands.settings.VoteTimer;
import com.gmail.stefvanschiedev.buildinggame.commands.subcommands.settings.Voting;
import com.gmail.stefvanschiedev.buildinggame.commands.subcommands.settings.WaitTimer;
import com.gmail.stefvanschiedev.buildinggame.commands.subcommands.settings.WinCommands;
import com.gmail.stefvanschiedev.buildinggame.commands.subcommands.settings.WinTimer;
import com.gmail.stefvanschiedev.buildinggame.managers.messages.MessageManager;

public class Setting extends ConsoleCommand {
	
	private final Collection<SubCommand> subCommands = new ArrayList<>();
	
	@Override
	public CommandResult onCommand(CommandSender sender, String[] args) {

		//add settings to list
		subCommands.add(new AllowFlyOutBounds());
		subCommands.add(new BlockedEntities());
		subCommands.add(new Blocks());
		subCommands.add(new BossBar());
		subCommands.add(new CleanFiles());
		subCommands.add(new Commands());
		subCommands.add(new CommandWhitelist());
		subCommands.add(new Debug());
		subCommands.add(new EnableSubjectVoting());
		subCommands.add(new Gui());
		subCommands.add(new Loading());
		subCommands.add(new MaxParticles());
		subCommands.add(new MaxVoteChange());
		subCommands.add(new Mobs());
		subCommands.add(new Money());
		subCommands.add(new NamesAfterVoting());
		subCommands.add(new RestorePlots());
		subCommands.add(new ScoreboardUpdateDelay());
		subCommands.add(new SubjectGui());
		subCommands.add(new Subjects());
		subCommands.add(new TeamSelection());
		subCommands.add(new Timer());
		subCommands.add(new Title());
		subCommands.add(new VoteTimer());
		subCommands.add(new Voting());
		subCommands.add(new WaitTimer());
		subCommands.add(new WinCommands());
		subCommands.add(new WinTimer());
		//test for right setting
		
		if (args.length == 0) {
			for (SubCommand sc : subCommands)
				MessageManager.getInstance().sendWithoutPrefix(sender, ChatColor.GREEN + "/bg setting " + sc.getName() + " - " + sc.getInfo());
			
			return CommandResult.ARGUMENTEXCEPTION;
		}
		
		for (SubCommand subCommand : subCommands) {
			if (subCommand.getName().equalsIgnoreCase(args[0])) {
				if (sender.hasPermission(subCommand.getPermission())) {
					//remove first argument
					
					List<String> arguments = new ArrayList<>(Arrays.asList(args));
                    arguments.remove(0);
					args = arguments.toArray(new String[arguments.size()]);

					return subCommand.onCommand(sender, args);
				}
			}
		}
		
		MessageManager.getInstance().send(sender, ChatColor.RED + "That's not a setting");
		return CommandResult.ERROR;
	}

	@Override
	public String getName() {
		return "setting";
	}

	@Override
	public String[] getAliases() {
		return null;
	}

	@Override
	public String getInfo() {
		return "Change the settings";<commit_msg>Fix settings commands<commit_after>package com.gmail.stefvanschiedev.buildinggame.commands.subcommands;

import java.util.List;

import com.gmail.stefvanschiedev.buildinggame.managers.files.SettingsManager;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;

import com.gmail.stefvanschiedev.buildinggame.commands.commandutils.CommandResult;
import com.gmail.stefvanschiedev.buildinggame.commands.commandutils.ConsoleCommand;
import com.gmail.stefvanschiedev.buildinggame.managers.messages.MessageManager;
import org.bukkit.configuration.file.YamlConfiguration;

public class Setting extends ConsoleCommand {
	
	@Override
	public CommandResult onCommand(CommandSender sender, String[] args) {
		YamlConfiguration config = SettingsManager.getInstance().getConfig();

	    if (args.length < 2) {
            MessageManager.getInstance().send(sender, ChatColor.RED + "Please specify a path and a value");
            return CommandResult.ARGUMENTEXCEPTION;
        }

        if (!config.contains(args[0])) {
            MessageManager.getInstance().send(sender, ChatColor.RED + "That setting doesn't exist");
            return CommandResult.ERROR;
        }

        if (config.isList(args[0])) {
	        if (args.length < 3) {
                MessageManager.getInstance().send(sender, ChatColor.RED +
                        "Please specify if you want to add or remove this value and the value");
                return CommandResult.ARGUMENTEXCEPTION;
            }

            if (args[1].equalsIgnoreCase("add")) {
	            //add the value
                List<String> list = config.getStringList(args[0]);
                list.add(args[2]);
                config.set(args[0], list);

                MessageManager.getInstance().send(sender, ChatColor.GREEN + "Value added to config");
            } else if (args[1].equalsIgnoreCase("remove")) {
                //remove the value
                List<String> list = config.getStringList(args[0]);
                list.remove(args[2]);
                config.set(args[0], list);

                MessageManager.getInstance().send(sender, ChatColor.GREEN + "Value removed from config");
            }

            SettingsManager.getInstance().save();
            return CommandResult.SUCCES;
        }

        //whole bunch of checking
        if (config.isBoolean(args[0]))
	        config.set(args[0], Boolean.parseBoolean(args[1]));
        else if (config.isDouble(args[0])) {
	        try {
	            config.set(args[0], Double.parseDouble(args[1]));
            } catch (NumberFormatException e) {
	            MessageManager.getInstance().send(sender, ChatColor.RED +
                        "Value type isn't the same as in the config, it should be a double");
	            return CommandResult.ERROR;
            }
        } else if (config.isInt(args[0])) {
            try {
                config.set(args[0], Integer.parseInt(args[1]));
            } catch (NumberFormatException e) {
                MessageManager.getInstance().send(sender, ChatColor.RED +
                        "Value type isn't the same as in the config, it should be an integer");
                return CommandResult.ERROR;
            }
        } else if (config.isLong(args[0])) {
            try {
                config.set(args[0], Long.parseLong(args[1]));
            } catch (NumberFormatException e) {
                MessageManager.getInstance().send(sender, ChatColor.RED +
                        "Value type isn't the same as in the config, it should be a long");
                return CommandResult.ERROR;
            }
        } else if (config.isString(args[0]))
	        config.set(args[0], args[1]);
        else {
	        MessageManager.getInstance().send(sender, ChatColor.YELLOW +
                    "Unable to change setting with commands, please change this setting by hand");
	        return CommandResult.ERROR;
        }

        MessageManager.getInstance().send(sender, ChatColor.GREEN + "Value changed in config");
        SettingsManager.getInstance().save();

		return CommandResult.SUCCES;
	}

	@Override
	public String getName() {
		return "setting";
	}

	@Override
	public String[] getAliases() {
		return null;
	}

	@Override
	public String getInfo() {
		return "Change the settings";
{'fraction_non_alphanumeric': 0.11146793742877861, 'fraction_numerical': 0.0031078421216202217, 'mean_word_length': 3.7277179236043096, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3527824', 'n_tokens_mistral': 2862, 'n_tokens_neox': 2759, 'n_words': 484}