<commit_before><?php
namespace PiggyAuth;

use PiggyAuth\Tasks\TimeoutTask;

use pocketmine\entity\Effect;
use pocketmine\entity\Entity;
use pocketmine\event\block\BlockBreakEvent;
use pocketmine\event\block\BlockPlaceEvent;
use pocketmine\event\entity\EntityDamageEvent;
use pocketmine\event\entity\EntityDamageByEntityEvent;
use pocketmine\event\entity\EntityRegainHealthEvent;
use pocketmine\event\inventory\InventoryPickupArrowEvent;
use pocketmine\event\inventory\InventoryPickupItemEvent;
use pocketmine\event\player\PlayerChatEvent;
use pocketmine\event\player\PlayerCommandPreprocessEvent;
use pocketmine\event\player\PlayerDropItemEvent;
use pocketmine\event\player\PlayerExhaustEvent;
use pocketmine\event\player\PlayerExperienceChangeEvent;
use pocketmine\event\player\PlayerInteractEvent;
use pocketmine\event\player\PlayerItemConsumeEvent;
use pocketmine\event\player\PlayerJoinEvent;
use pocketmine\event\player\PlayerMoveEvent;
use pocketmine\event\player\PlayerPreLoginEvent;
use pocketmine\event\player\PlayerQuitEvent;
use pocketmine\event\server\DataPacketReceiveEvent;
use pocketmine\event\server\DataPacketSendEvent;
use pocketmine\event\Listener;
use pocketmine\item\Item;
use pocketmine\network\protocol\ContainerSetSlotPacket;
use pocketmine\network\protocol\MobEffectPacket;
use pocketmine\Player;

class EventListener implements Listener {
    public function __construct($plugin) {
        $this->plugin = $plugin;
    }

    public function onBreak(BlockBreakEvent $event) {
        $player = $event->getPlayer();
        if(!$this->plugin->isAuthenticated($player)) {
            if(!$this->plugin->getConfig()->get("allow-block-break")) {
                $event->setCancelled();
            }
        }
    }

    public function onPlace(BlockPlaceEvent $event) {
        $player = $event->getPlayer();
        if(!$this->plugin->isAuthenticated($player)) {
            if(!$this->plugin->getConfig()->get("allow-block-place")) {
                $event->setCancelled();
            }
        }
    }

    public function onDamage(EntityDamageEvent $event) {
        $entity = $event->getEntity();
        if($entity instanceof Player && !$this->plugin->isAuthenticated($entity)) {
            if(!$this->plugin->getConfig()->get("allow-damage")) {
                $event->setCancelled();
            }
        }
        if($event instanceof EntityDamageByEntityEvent) {
            $damager = $event->getDamager();
            if($damager instanceof Player && !$this->plugin->isAuthenticated($damager)) {
                if(!$this->plugin->getConfig()->get("allow-damage-others")) {
                    $event->setCancelled();
                }
            }
        }
    }

    public function onHeal(EntityRegainHealthEvent $event) {
        $entity = $event->getEntity();
        if($entity instanceof Player && !$this->plugin->isAuthenticated($entity)) {
            if(!$this->plugin->getConfig()->get("allow-heal")) {
                $event->setCancelled();
            }
        }
    }

    public function onPickupArrow(InventoryPickupArrowEvent $event) {
        $player = $event->getInventory()->getHolder();
        if($player instanceof Player && !$this->plugin->isAuthenticated($player)) {
            if(!$this->plugin->getConfig()->get("allow-arrow-pickup")) {
                $event->setCancelled();
            }
        }
    }

    public function onPickupItem(InventoryPickupItemEvent $event) {
        $player = $event->getInventory()->getHolder();
        if($player instanceof Player && !$this->plugin->isAuthenticated($player)) {
            if(!$this->plugin->getConfig()->get("allow-item-pickup")) {
                $event->setCancelled();
            }
        }
    }

    public function onChat(PlayerChatEvent $event) {
        $player = $event->getPlayer();
        $message = $event->getMessage();
        $recipients = array();
        if(!$this->plugin->isAuthenticated($player)) {
            if($this->plugin->getConfig("chat-login")) {
                if($this->plugin->isRegistered($player->getName())) {
                    $this->plugin->login($player, $message, 0);
                } else {
                    if(!isset($this->plugin->confirmPassword[strtolower($player->getName())])) {
                        if(!isset($this->plugin->confirmedPassword[strtolower($player->getName())])) {
                            $this->plugin->confirmPassword[strtolower($player->getName())] = $message;
                            $player->sendMessage($this->plugin->getMessage("confirm-password"));
                        }
                    } else {
                        if($this->plugin->confirmPassword[strtolower($player->getName())] == $message) {
                            unset($this->plugin->confirmPassword[strtolower($player->getName())]);
                            $this->plugin->confirmedPassword[strtolower($player->getName())] = $message;
                            $this->plugin->giveEmail[strtolower($player->getName())] = true;
                            $player->sendMessage($this->plugin->getMessage("email"));
                            $event->setCancelled();
                            return true; //Stop the Invalid email message
                        } else {
                            $player->sendMessage($this->plugin->getMessage("password-not-match"));
                            unset($this->plugin->confirmPassword[strtolower($player->getName())]);
                        }
                    }
                    if(isset($this->plugin->giveEmail[strtolower($player->getName())])) {
                        if(strtolower($message) !== "none" && !filter_var($message, FILTER_VALIDATE_EMAIL)) {
                            $player->sendMessage($this->plugin->getMessage("invalid-email"));
                        } else {
                            $this->plugin->register($player, $this->plugin->confirmedPassword[strtolower($player->getName())], $this->plugin->confirmedPassword[strtolower($player->getName())], $message);
                            $this->plugin->database->updatePlayer($player->getName(), $this->plugin->database->getPassword($player->getName()), $message, $this->plugin->database->getPin($player->getName()), $player->getUniqueId()->toString(), $this->plugin->database->getUUID($player->getName()));
                            unset($this->plugin->giveEmail[strtolower($player->getName())]);
                            unset($this->plugin->confirmedPassword[strtolower($player->getName())]);
                        }
                    }
                }
            }
            $event->setCancelled();
        } else {
            if($this->plugin->isCorrectPassword($player, $message)) {
                $player->sendMessage($this->plugin->getMessage("dont-say-password"));
                $event->setCancelled();
            }
        }
        if(!$this->plugin->getConfig()->get("see-messages")) {
            foreach($event->getRecipients() as $recipient) {
                if(!$recipient instanceof Player || $this->plugin->isAuthenticated($recipient)) {
                    array_push($recipients, $recipient);
                }
            }
            $event->setRecipients($recipients);
        }
    }

    public function onCommandPreprocess(PlayerCommandPreprocessEvent $event) {
        $player = $event->getPlayer();
        $message = strtolower($event->getMessage());
        $args = explode(" ", $message);
        $forgotpasswordaliases = array(
            "/forgotpassword",
            "/forgetpassword",
            "/forgotpw",
            "/forgetpw",
            "/forgotpwd",
            "/forgetpwd",
            "/fpw",
            "/fpwd");
        if(!$this->plugin->isAuthenticated($player)) {
            if($message[0] == "/" || $message[0] == "./") {
                if(!in_array($args[0], $forgotpasswordaliases) && $args[0] !== "/login" && $args[0] !== "/register" && $args[0] !== "/sendpin") {
                    if(!$this->plugin->getConfig()->get("allow-commands")) {
                        $event->setCancelled();
                    }
                }
            }
        }
    }

    public function onDrop(PlayerDropItemEvent $event) {
        $player = $event->getPlayer();
        if(!$this->plugin->isAuthenticated($player)) {
            if(!$this->plugin->getConfig()->get("allow-item-drop")) {
                $event->setCancelled();
            }
        }
    }

    public function onExhaust(PlayerExhaustEvent $event) {
        $player = $event->getPlayer();
        if($player instanceof Player && !$this->plugin->isAuthenticated($player)) {
            if(!$this->plugin->getConfig()->get("allow-hunger")) {
                $event->setCancelled();
            }
        }
    }

    public function onXPChange(PlayerExperienceChangeEvent $event) {
        $player = $event->getPlayer();
        if($player instanceof Player && !$this->plugin->isAuthenticated($player)) {
            if(!$this->plugin->getConfig()->get("allow-xp-change")) {<commit_msg>Actuially fixed.<commit_after><?php
namespace PiggyAuth;

use PiggyAuth\Tasks\TimeoutTask;

use pocketmine\entity\Effect;
use pocketmine\entity\Entity;
use pocketmine\event\block\BlockBreakEvent;
use pocketmine\event\block\BlockPlaceEvent;
use pocketmine\event\entity\EntityDamageEvent;
use pocketmine\event\entity\EntityDamageByEntityEvent;
use pocketmine\event\entity\EntityRegainHealthEvent;
use pocketmine\event\inventory\InventoryPickupArrowEvent;
use pocketmine\event\inventory\InventoryPickupItemEvent;
use pocketmine\event\player\PlayerChatEvent;
use pocketmine\event\player\PlayerCommandPreprocessEvent;
use pocketmine\event\player\PlayerDropItemEvent;
use pocketmine\event\player\PlayerExhaustEvent;
use pocketmine\event\player\PlayerExperienceChangeEvent;
use pocketmine\event\player\PlayerInteractEvent;
use pocketmine\event\player\PlayerItemConsumeEvent;
use pocketmine\event\player\PlayerJoinEvent;
use pocketmine\event\player\PlayerMoveEvent;
use pocketmine\event\player\PlayerPreLoginEvent;
use pocketmine\event\player\PlayerQuitEvent;
use pocketmine\event\server\DataPacketReceiveEvent;
use pocketmine\event\server\DataPacketSendEvent;
use pocketmine\event\Listener;
use pocketmine\item\Item;
use pocketmine\network\protocol\ContainerSetSlotPacket;
use pocketmine\network\protocol\MobEffectPacket;
use pocketmine\Player;

class EventListener implements Listener {
    public function __construct($plugin) {
        $this->plugin = $plugin;
    }

    public function onBreak(BlockBreakEvent $event) {
        $player = $event->getPlayer();
        if(!$this->plugin->isAuthenticated($player)) {
            if(!$this->plugin->getConfig()->get("allow-block-break")) {
                $event->setCancelled();
            }
        }
    }

    public function onPlace(BlockPlaceEvent $event) {
        $player = $event->getPlayer();
        if(!$this->plugin->isAuthenticated($player)) {
            if(!$this->plugin->getConfig()->get("allow-block-place")) {
                $event->setCancelled();
            }
        }
    }

    public function onDamage(EntityDamageEvent $event) {
        $entity = $event->getEntity();
        if($entity instanceof Player && !$this->plugin->isAuthenticated($entity)) {
            if(!$this->plugin->getConfig()->get("allow-damage")) {
                $event->setCancelled();
            }
        }
        if($event instanceof EntityDamageByEntityEvent) {
            $damager = $event->getDamager();
            if($damager instanceof Player && !$this->plugin->isAuthenticated($damager)) {
                if(!$this->plugin->getConfig()->get("allow-damage-others")) {
                    $event->setCancelled();
                }
            }
        }
    }

    public function onHeal(EntityRegainHealthEvent $event) {
        $entity = $event->getEntity();
        if($entity instanceof Player && !$this->plugin->isAuthenticated($entity)) {
            if(!$this->plugin->getConfig()->get("allow-heal")) {
                $event->setCancelled();
            }
        }
    }

    public function onPickupArrow(InventoryPickupArrowEvent $event) {
        $player = $event->getInventory()->getHolder();
        if($player instanceof Player && !$this->plugin->isAuthenticated($player)) {
            if(!$this->plugin->getConfig()->get("allow-arrow-pickup")) {
                $event->setCancelled();
            }
        }
    }

    public function onPickupItem(InventoryPickupItemEvent $event) {
        $player = $event->getInventory()->getHolder();
        if($player instanceof Player && !$this->plugin->isAuthenticated($player)) {
            if(!$this->plugin->getConfig()->get("allow-item-pickup")) {
                $event->setCancelled();
            }
        }
    }

    public function onChat(PlayerChatEvent $event) {
        $player = $event->getPlayer();
        $message = $event->getMessage();
        $recipients = array();
        if(!$this->plugin->isAuthenticated($player)) {
            if($this->plugin->getConfig("chat-login")) {
                if($this->plugin->isRegistered($player->getName())) {
                    $this->plugin->login($player, $message, 0);
                } else {
                    if(!isset($this->plugin->confirmPassword[strtolower($player->getName())])) {
                        if(!isset($this->plugin->confirmedPassword[strtolower($player->getName())])) {
                            $this->plugin->confirmPassword[strtolower($player->getName())] = $message;
                            $player->sendMessage($this->plugin->getMessage("confirm-password"));
                        }
                    } else {
                        if($this->plugin->confirmPassword[strtolower($player->getName())] == $message) {
                            unset($this->plugin->confirmPassword[strtolower($player->getName())]);
                            $this->plugin->confirmedPassword[strtolower($player->getName())] = $message;
                            $this->plugin->giveEmail[strtolower($player->getName())] = true;
                            $player->sendMessage($this->plugin->getMessage("email"));
                            $event->setCancelled();
                            return true; //Stop the Invalid email message
                        } else {
                            $player->sendMessage($this->plugin->getMessage("password-not-match"));
                            unset($this->plugin->confirmPassword[strtolower($player->getName())]);
                        }
                    }
                    if(isset($this->plugin->giveEmail[strtolower($player->getName())])) {
                        if(strtolower($message) !== "none" && !filter_var($message, FILTER_VALIDATE_EMAIL)) {
                            $player->sendMessage($this->plugin->getMessage("invalid-email"));
                        } else {
                            $this->plugin->register($player, $this->plugin->confirmedPassword[strtolower($player->getName())], $this->plugin->confirmedPassword[strtolower($player->getName())], $message);
                            $this->plugin->database->updatePlayer($player->getName(), $this->plugin->database->getPassword($player->getName()), $message, $this->plugin->database->getPin($player->getName()), $player->getUniqueId()->toString(), $this->plugin->database->getUUID($player->getName()));
                            unset($this->plugin->giveEmail[strtolower($player->getName())]);
                            unset($this->plugin->confirmedPassword[strtolower($player->getName())]);
                        }
                    }
                }
            }
            $event->setCancelled();
        } else {
            if($this->plugin->isCorrectPassword($player, $message)) {
                $player->sendMessage($this->plugin->getMessage("dont-say-password"));
                $event->setCancelled();
            }
        }
        if(!$this->plugin->getConfig()->get("see-messages")) {
            foreach($event->getRecipients() as $recipient) {
                if(!$recipient instanceof Player || $this->plugin->isAuthenticated($recipient)) {
                    array_push($recipients, $recipient);
                }
            }
            $event->setRecipients($recipients);
        }
    }

    public function onCommandPreprocess(PlayerCommandPreprocessEvent $event) {
        $player = $event->getPlayer();
        $message = strtolower($event->getMessage());
        $args = explode(" ", $message);
        $forgotpasswordaliases = array(
            "/forgotpassword",
            "/forgetpassword",
            "/forgotpw",
            "/forgetpw",
            "/forgotpwd",
            "/forgetpwd",
            "/fpw",
            "/fpwd");
        if(!$this->plugin->isAuthenticated($player)) {
            if($message[0] == "/" || ($message[0] == "." && $message[1] == "/")) {
                if(!in_array($args[0], $forgotpasswordaliases) && $args[0] !== "/login" && $args[0] !== "/register" && $args[0] !== "/sendpin") {
                    if(!$this->plugin->getConfig()->get("allow-commands")) {
                        $event->setCancelled();
                    }
                }
            }
        }
    }

    public function onDrop(PlayerDropItemEvent $event) {
        $player = $event->getPlayer();
        if(!$this->plugin->isAuthenticated($player)) {
            if(!$this->plugin->getConfig()->get("allow-item-drop")) {
                $event->setCancelled();
            }
        }
    }

    public function onExhaust(PlayerExhaustEvent $event) {
        $player = $event->getPlayer();
        if($player instanceof Player && !$this->plugin->isAuthenticated($player)) {
            if(!$this->plugin->getConfig()->get("allow-hunger")) {
                $event->setCancelled();
            }
        }
    }

    public function onXPChange(PlayerExperienceChangeEvent $event) {
        $player = $event->getPlayer();
        if($player instanceof Player && !$this->plugin->isAuthenticated($player)) {
            if(!$this->plugin->getConfig()->get("allow-xp-change")) {
{'fraction_non_alphanumeric': 0.15843984133979727, 'fraction_numerical': 0.0008263552225650067, 'mean_word_length': 2.260822705227232, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 357, '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': '2952848', 'n_tokens_mistral': 4883, 'n_tokens_neox': 4755, 'n_words': 580}