<commit_before><?php
/**
 * Created by PhpStorm.
 * User: RTG
 * Date: 14/10/2017
 * Time: 4:25 PM
 */

namespace RTG\BountyHunter;

use pocketmine\command\Command;
use pocketmine\command\CommandSender;
use pocketmine\plugin\PluginBase;

class Loader extends PluginBase {

    public $db_file = "saves.db";
    public $db;
    const prefix = '[BountyHunter]';

    public function onEnable() {

        if (!is_dir($this->getDataFolder())) {
            mkdir($this->getDataFolder());
        }

        if (!is_file($this->getDataFolder() . $this->db_file)) {
            $this->db = new \SQLite3($this->getDataFolder() . $this->db_file);
            $this->db->exec("CREATE TABLE IF NOT EXISTS `list` (`id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, `name` TEXT NOT NULL, `bounty` INTEGER NOT NULL);");
        } else {
            $this->getLogger()->warning(self::prefix . " Database has been loaded under the name of $this->db_file");
        }

    }

    /**
     * @return bool
     */
    public function checkConfig(): bool {
        $json = json_decode(file_get_contents($this->getDataFolder() . "config.json"));
        if ($json['enabled'] === true) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * @return \SQLite3
     */
    public function getDatabase() {
        $this->db = new \SQLite3($this->getDataFolder() . $this->db_file);
        return $this->db;
    }

    // Bounty API

    /**
     * @param $name
     * @return int
     */
    public function getBounty($name): int {
        $statement = "SELECT * FROM `list` WHERE `name` = '$name'";
        $res = $this->getDatabase()->query($statement);
        if ($row = $res->fetchArray(1)) {
            return $row['bounty'];
        } else {
            return 0;
        }
    }

    /**
     * @param $name
     * @return bool
     */
    public function hasBounty($name): bool {
        $statement = "SELECT * FROM `list` WHERE `name` = '$name'";
        $res = $this->getDatabase()->query($statement);
        if ($row = $res->fetchArray(1)) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * @param $name
     * @param int $integer
     * @return bool
     */
    public function setBounty($name, int $integer): bool {
        if (!$this->hasBounty($name)) {
            $statement = "SELECT * FROM `list` WHERE `name` = '$name'";
            $res = $this->getDatabase()->query($statement);
            if ($row = $res->fetchArray(1)) {
                return false;
            } else {
                return true;
            }
        } else {
            return false;
        }
    }

    /**
     * @param $name
     * @param int $integer
     * @return bool
     */
    public function increaseBounty($name, int $integer): bool {
        if ($this->hasBounty($name) === true) {
            $old = $this->getBounty($name);
            $inc = $old + $integer;
            $statement = "UPDATE `list` SET `bounty` = '$inc' WHERE `name` = '$name'";
            $res = $this->getDatabase()->query($statement);
                if ($row = $res->fetchArray(1)) {
                    return true;
                } else {
                    return false;
                }
        }
    }

    /**
     * @param $name
     * @param int $integer
     * @return bool
     */
    public function reduceBounty($name, int $integer): bool {
        if ($this->hasBounty($name) === true) {
            $old = $this->getBounty($name);
            $inc = $old - $integer;
            $statement = "UPDATE `list` SET `bounty` = '$inc' WHERE `name` = '$name'";
            $res = $this->getDatabase()->query($statement);
            if ($row = $res->fetchArray(1)) {
                return true;
            } else {
                return false;
            }
        }
    }

    public function getAll(CommandSender $sender) {
        $statement = "SELECT * FROM `list`";
        $res = $this->getDatabase()->query($statement);
        $sender->sendMessage("Total affected Players: ");
        while ($row = $res->fetchArray(1)) {
            $sender->sendMessage($row['name']);
        }
    }

    // ----------------- COMMANDS -------------------

    public function onCommand(CommandSender $sender, Command $command, string $commandLabel, array $args): bool {

        if ($sender->hasPermission("bounty.command")) {
            switch ($command->getName()) {
                case "bh":

                    if (isset($args[0])) {
                        switch ($args[0]) {
                            case "list":
                                $this->getAll($sender);
                                return true;
                            break;
                            case "set":
                                if (isset($args[1])) {
                                    if (isset($args[2])) {
                                        if ($args[1] instanceof Player) {
                                            if (empty($args[2])) {
                                                $int = 100;
                                            } else {
                                                if (is_int($args[2])) {
                                                    $int = $args[2];
                                                }
                                            }
                                            $this->setBounty($args[1], $int);
                                        } else {
                                            $sender->sendMessage("$args[1] is not a valid Player!");
                                        }
                                    }
                                }
                                return true;
                            break;
                        }
                    } else {
                        $sender->sendMessage("[Usage] /bh list");<commit_msg>Added a new command.<commit_after><?php
/**
 * Created by PhpStorm.
 * User: RTG
 * Date: 14/10/2017
 * Time: 4:25 PM
 */

namespace RTG\BountyHunter;

use pocketmine\command\Command;
use pocketmine\command\CommandSender;
use pocketmine\plugin\PluginBase;

class Loader extends PluginBase {

    public $db_file = "saves.db";
    public $db;
    const prefix = '[BountyHunter]';

    public function onEnable() {

        if (!is_dir($this->getDataFolder())) {
            mkdir($this->getDataFolder());
        }

        if (!is_file($this->getDataFolder() . $this->db_file)) {
            $this->db = new \SQLite3($this->getDataFolder() . $this->db_file);
            $this->db->exec("CREATE TABLE IF NOT EXISTS `list` (`id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, `name` TEXT NOT NULL, `bounty` INTEGER NOT NULL);");
        } else {
            $this->getLogger()->warning(self::prefix . " Database has been loaded under the name of $this->db_file");
        }

    }

    /**
     * @return bool
     */
    public function checkConfig(): bool {
        $json = json_decode(file_get_contents($this->getDataFolder() . "config.json"));
        if ($json['enabled'] === true) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * @return \SQLite3
     */
    public function getDatabase() {
        $this->db = new \SQLite3($this->getDataFolder() . $this->db_file);
        return $this->db;
    }

    // Bounty API

    /**
     * @param $name
     * @return int
     */
    public function getBounty($name): int {
        $statement = "SELECT * FROM `list` WHERE `name` = '$name'";
        $res = $this->getDatabase()->query($statement);
        if ($row = $res->fetchArray(1)) {
            return $row['bounty'];
        } else {
            return 0;
        }
    }

    /**
     * @param $name
     * @return bool
     */
    public function hasBounty($name): bool {
        $statement = "SELECT * FROM `list` WHERE `name` = '$name'";
        $res = $this->getDatabase()->query($statement);
        if ($row = $res->fetchArray(1)) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * @param $name
     * @param int $integer
     * @return bool
     */
    public function setBounty($name, int $integer): bool {
        if (!$this->hasBounty($name)) {
            $statement = "SELECT * FROM `list` WHERE `name` = '$name'";
            $res = $this->getDatabase()->query($statement);
            if ($row = $res->fetchArray(1)) {
                return false;
            } else {
                return true;
            }
        } else {
            return false;
        }
    }

    /**
     * @param $name
     * @param int $integer
     * @return bool
     */
    public function increaseBounty($name, int $integer): bool {
        if ($this->hasBounty($name) === true) {
            $old = $this->getBounty($name);
            $inc = $old + $integer;
            $statement = "UPDATE `list` SET `bounty` = '$inc' WHERE `name` = '$name'";
            $res = $this->getDatabase()->query($statement);
                if ($row = $res->fetchArray(1)) {
                    return true;
                } else {
                    return false;
                }
        }
    }

    /**
     * @param $name
     * @param int $integer
     * @return bool
     */
    public function reduceBounty($name, int $integer): bool {
        if ($this->hasBounty($name) === true) {
            $old = $this->getBounty($name);
            $inc = $old - $integer;
            $statement = "UPDATE `list` SET `bounty` = '$inc' WHERE `name` = '$name'";
            $res = $this->getDatabase()->query($statement);
            if ($row = $res->fetchArray(1)) {
                return true;
            } else {
                return false;
            }
        }
    }

    public function getAll(CommandSender $sender) {
        $statement = "SELECT * FROM `list`";
        $res = $this->getDatabase()->query($statement);
        $sender->sendMessage("Total affected Players: ");
        while ($row = $res->fetchArray(1)) {
            $sender->sendMessage($row['name']);
        }
    }

    // ----------------- COMMANDS -------------------

    public function onCommand(CommandSender $sender, Command $command, string $commandLabel, array $args): bool {

        if ($sender->hasPermission("bounty.command")) {
            switch ($command->getName()) {
                case "bh":

                    if (isset($args[0])) {
                        switch ($args[0]) {
                            case "list":
                                $this->getAll($sender);
                                return true;
                            break;
                            case "set":
                                if (isset($args[1])) {
                                    if (isset($args[2])) {
                                        if ($args[1] instanceof Player) {
                                            if (empty($args[2])) {
                                                $int = 100;
                                            } else {
                                                if (is_int($args[2])) {
                                                    $int = $args[2];
                                                } else {
                                                    $int = 100;
                                                }
                                            }
                                            $this->setBounty($args[1], $int);
                                        } else {
                                            $sender->sendMessage("$args[1] is not a valid Player!");
                                        }
                                    }
                                } else {
                                    $sender->sendMessage("[Usage] /bh set {name} {bounty}");
                                }
                                return true;
                            break;
                            case "inbounty":
                                if (isset($args[1]) && isset($args[2])) {
                                    if ($args[1] instanceof Player) {
                                        if (empty($args[2])) {
                                            $sender->sendMessage("[Usage] /bh addbounty {name} {bounty:int}");
                                            return true;
                                        } else {
                                            if (is_int($args[2])) {
                                                $this->increaseBounty($args[1], $args[2]);
                                                $sender->sendMessage("Done");
                                            } else {
                                                $sender->sendMessage("Bounty has to be in a form of Integer!");
                                            }
                                        }
                                    } else {
                                        $sender->sendMessage("$args[1] is not a Player!");
                                    }
                                } else {
                                    $sender->sendMessage("[Usage] /bh inbounty {name} {bounty:int}");
                                }
                                return true;
                            break;
                        }
                    } else {
                        $cmd = array(
                            "/bh list",
                            "/bh setbounty",
                            "/bh inbounty"
                        );
                        foreach ($cmd as $c) {
                            $sender->sendMessage($c);
                        }
{'fraction_non_alphanumeric': 0.1383967470229451, 'fraction_numerical': 0.005736276503049666, 'mean_word_length': 1.0578216046615867, 'pattern_counts': {'":': 7, '<': 5, '<?xml version=': 0, '>': 106, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 86, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7565962', 'n_tokens_mistral': 3490, 'n_tokens_neox': 3319, 'n_words': 772}