<commit_before>/**
 * WeronicaMC - Plugin for fantasy and creative server.
 * Copyright (c) 2015, <NAME> <http://www.github.com/dobrakmato>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice, this
 * list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 * this list of conditions and the following disclaimer in the documentation and/or
 * other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package eu.matejkormuth.weronicamc.caches.commands;

import eu.matejkormuth.weronicamc.caches.*;
import eu.matejkormuth.weronicamc.caches.listeners.CreateCacheInteractListener;
import eu.matejkormuth.weronicamc.translations.TranslationPack;
import net.milkbowl.vault.permission.Permission;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.block.Block;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

public class KeskaCommandExecutor implements CommandExecutor {

    private static final Logger log = LoggerFactory.getLogger(KeskaCommandExecutor.class);

    private final Permission permissions;

    private final CacheStorage cacheStorage;
    private final CachePlayerStorage cachePlayerStorage;
    private final CreateCacheInteractListener createCacheInteractListener;
    private final TranslationPack translations;
    private final ScoreboardManager scoreboardManager;

    public KeskaCommandExecutor(Permission permissions, CacheStorage cacheStorage,
                                CachePlayerStorage cachePlayerStorage,
                                CreateCacheInteractListener createCacheInteractListener,
                                TranslationPack translations, ScoreboardManager scoreboardManager) {
        this.permissions = permissions;
        this.cacheStorage = cacheStorage;
        this.cachePlayerStorage = cachePlayerStorage;
        this.createCacheInteractListener = createCacheInteractListener;
        this.translations = translations;
        this.scoreboardManager = scoreboardManager;
    }

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        // Command parsing logic is here, actual command implementation is in custom
        // methods below this.

        try {

            if (args.length >= 1) {
                String subCommand = args[0];

                switch (subCommand) {
                    // Admin commands.
                    case "create":
                        if (sender instanceof Player) {
                            if (args.length != 2) {
                                throw new IllegalArgumentException("You must specify monetary amount as reward!");
                            }

                            String rewardStr = args[1];
                            double reward = Double.valueOf(rewardStr);

                            commandCreate((Player) sender, reward);
                        } else {
                            sender.sendMessage("Sorry this command is only for Players.");
                        }
                        break;
                    case "edit":
                        if (sender instanceof Player) {
                            if (args.length != 2) {
                                throw new IllegalArgumentException("Must specify on or off.");
                            }

                            commandEdit((Player) sender, args[1].equalsIgnoreCase("on"));
                        } else {
                            sender.sendMessage("Sorry this command is only for Players.");
                        }
                        break;
                    case "info":
                        if (sender instanceof Player) {
                            commandInfo((Player) sender);
                        } else {
                            sender.sendMessage("Sorry this command is only for Players.");
                        }
                        break;
                    case "previousID":
                        if (args.length != 3) {
                            throw new IllegalArgumentException("Not enough arguments!");
                        }
                        int cacheId = Integer.valueOf(args[1]);
                        int previous = Integer.valueOf(args[2]);
                        commandPreviousId(sender, cacheId, previous);
                        break;
                    case "list":
                        int page = 0;
                        if (args.length == 2) {
                            page = Integer.valueOf(args[1]) - 1;
                        }
                        commandList(sender, page);
                        break;
                    case "stats":
                        if (args.length != 2) {
                            throw new IllegalArgumentException("Cache ID must be specified!");
                        }
                        int cacheId2 = Integer.valueOf(args[1]);
                        commandStats(sender, cacheId2);
                        break;
                    case "count":
                        if (args.length != 2) {
                            throw new IllegalArgumentException("Player name must be specified!");
                        }
                        String playerName = args[1];
                        OfflinePlayer candidate = Bukkit.getPlayer(playerName);
                        if (candidate == null) {
                            candidate = Bukkit.getOfflinePlayer(playerName);
                        }
                        if (candidate == null) {
                            throw new IllegalArgumentException("Can't find player " + playerName);
                        }
                        commandCount(sender, candidate.getUniqueId());
                        break;
                    case "remove":
                        if (args.length < 2) {
                            throw new IllegalArgumentException("Not enough arguments!");
                        }
                        // Special IDs.
                        if (args[1].equalsIgnoreCase("all")) {
                            commandRemoveAll(sender);
                            break;
                        } else if (args[1].equalsIgnoreCase("count")) {
                            if (args.length != 3) {
                                throw new IllegalArgumentException("Player name must be specified!");
                            }
                            String playerName2 = args[2];
                            OfflinePlayer candidate2 = Bukkit.getPlayer(playerName2);
                            if (candidate2 == null) {
                                candidate2 = Bukkit.getOfflinePlayer(playerName2);
                            }
                            if (candidate2 == null) {
                                throw new IllegalArgumentException("Can't find player " + playerName2);
                            }
                            commandRemoveCount(sender, candidate2.getUniqueId());
                        } else if (args[1].equalsIgnoreCase("stats")) {
                            commandRemoveStats(sender);
                            break;
                        } else {
                            if (args.length != 2) {
                                throw new IllegalArgumentException("Cache ID must be specified!");
                            }
                            int cacheId3 = Integer.valueOf(args[2]);
                            commandRemove(sender, cacheId3);
                            break;
                        }
                    case "reload":
                        if (sender instanceof Player) {<commit_msg>fixed off by one typo<commit_after>/**
 * WeronicaMC - Plugin for fantasy and creative server.
 * Copyright (c) 2015, <NAME> <http://www.github.com/dobrakmato>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice, this
 * list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 * this list of conditions and the following disclaimer in the documentation and/or
 * other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package eu.matejkormuth.weronicamc.caches.commands;

import eu.matejkormuth.weronicamc.caches.*;
import eu.matejkormuth.weronicamc.caches.listeners.CreateCacheInteractListener;
import eu.matejkormuth.weronicamc.translations.TranslationPack;
import net.milkbowl.vault.permission.Permission;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.block.Block;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

public class KeskaCommandExecutor implements CommandExecutor {

    private static final Logger log = LoggerFactory.getLogger(KeskaCommandExecutor.class);

    private final Permission permissions;

    private final CacheStorage cacheStorage;
    private final CachePlayerStorage cachePlayerStorage;
    private final CreateCacheInteractListener createCacheInteractListener;
    private final TranslationPack translations;
    private final ScoreboardManager scoreboardManager;

    public KeskaCommandExecutor(Permission permissions, CacheStorage cacheStorage,
                                CachePlayerStorage cachePlayerStorage,
                                CreateCacheInteractListener createCacheInteractListener,
                                TranslationPack translations, ScoreboardManager scoreboardManager) {
        this.permissions = permissions;
        this.cacheStorage = cacheStorage;
        this.cachePlayerStorage = cachePlayerStorage;
        this.createCacheInteractListener = createCacheInteractListener;
        this.translations = translations;
        this.scoreboardManager = scoreboardManager;
    }

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        // Command parsing logic is here, actual command implementation is in custom
        // methods below this.

        try {

            if (args.length >= 1) {
                String subCommand = args[0];

                switch (subCommand) {
                    // Admin commands.
                    case "create":
                        if (sender instanceof Player) {
                            if (args.length != 2) {
                                throw new IllegalArgumentException("You must specify monetary amount as reward!");
                            }

                            String rewardStr = args[1];
                            double reward = Double.valueOf(rewardStr);

                            commandCreate((Player) sender, reward);
                        } else {
                            sender.sendMessage("Sorry this command is only for Players.");
                        }
                        break;
                    case "edit":
                        if (sender instanceof Player) {
                            if (args.length != 2) {
                                throw new IllegalArgumentException("Must specify on or off.");
                            }

                            commandEdit((Player) sender, args[1].equalsIgnoreCase("on"));
                        } else {
                            sender.sendMessage("Sorry this command is only for Players.");
                        }
                        break;
                    case "info":
                        if (sender instanceof Player) {
                            commandInfo((Player) sender);
                        } else {
                            sender.sendMessage("Sorry this command is only for Players.");
                        }
                        break;
                    case "previousID":
                        if (args.length != 3) {
                            throw new IllegalArgumentException("Not enough arguments!");
                        }
                        int cacheId = Integer.valueOf(args[1]);
                        int previous = Integer.valueOf(args[2]);
                        commandPreviousId(sender, cacheId, previous);
                        break;
                    case "list":
                        int page = 0;
                        if (args.length == 2) {
                            page = Integer.valueOf(args[1]) - 1;
                        }
                        commandList(sender, page);
                        break;
                    case "stats":
                        if (args.length != 2) {
                            throw new IllegalArgumentException("Cache ID must be specified!");
                        }
                        int cacheId2 = Integer.valueOf(args[1]);
                        commandStats(sender, cacheId2);
                        break;
                    case "count":
                        if (args.length != 2) {
                            throw new IllegalArgumentException("Player name must be specified!");
                        }
                        String playerName = args[1];
                        OfflinePlayer candidate = Bukkit.getPlayer(playerName);
                        if (candidate == null) {
                            candidate = Bukkit.getOfflinePlayer(playerName);
                        }
                        if (candidate == null) {
                            throw new IllegalArgumentException("Can't find player " + playerName);
                        }
                        commandCount(sender, candidate.getUniqueId());
                        break;
                    case "remove":
                        if (args.length < 2) {
                            throw new IllegalArgumentException("Not enough arguments!");
                        }
                        // Special IDs.
                        if (args[1].equalsIgnoreCase("all")) {
                            commandRemoveAll(sender);
                            break;
                        } else if (args[1].equalsIgnoreCase("count")) {
                            if (args.length != 3) {
                                throw new IllegalArgumentException("Player name must be specified!");
                            }
                            String playerName2 = args[2];
                            OfflinePlayer candidate2 = Bukkit.getPlayer(playerName2);
                            if (candidate2 == null) {
                                candidate2 = Bukkit.getOfflinePlayer(playerName2);
                            }
                            if (candidate2 == null) {
                                throw new IllegalArgumentException("Can't find player " + playerName2);
                            }
                            commandRemoveCount(sender, candidate2.getUniqueId());
                        } else if (args[1].equalsIgnoreCase("stats")) {
                            commandRemoveStats(sender);
                            break;
                        } else {
                            if (args.length != 2) {
                                throw new IllegalArgumentException("Cache ID must be specified!");
                            }
                            int cacheId3 = Integer.valueOf(args[1]);
                            commandRemove(sender, cacheId3);
                            break;
                        }
                    case "reload":
                        if (sender instanceof Player) {
{'fraction_non_alphanumeric': 0.07019294743845642, 'fraction_numerical': 0.005100909292526059, 'mean_word_length': 1.447686253222961, 'pattern_counts': {'":': 18, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1922508', 'n_tokens_mistral': 4010, 'n_tokens_neox': 3679, 'n_words': 1168}