saveDefaultConfig(); $this->getServer()->getPluginManager()->registerEvents($this, $this); //Database setup $this->db = new DataBase($this->getDatafolder() . "base.db"); if($this->db->query("PRAGMA table_info(Games);")->num_rows == 0) { $this->db->exec(<<gamemanager = new GameManager(); } /* Called when one of the defined commands of the plugin has been called @param $sender \pocketmine\command\CommandSender @param $cmd \pocketmine\command\Command @param $label mixed @param $args array return bool */ public function onCommand(\pocketmine\command\CommandSender $sender, \pocketmine\command\Command $cmd, $label, array $args): bool { switch($cmd->getName()) { case "hideandseek": if(isset($args[0])) { $game = $this->getGameManager()->getGameByLevel($sender->getLevel()); switch(strtolower($args[0])) { case "creategame": case "addgame": if($sender->getLevel()->getName() == $this->getLobbyWorld()->getName()) { $sender->sendMessage(self::PREFIX . "§cCould not create game ! You're in the lobby level."); return true; } elseif(!is_null($this->getGameManager()->getGameByLevel($sender->getLevel()))) { $sender->sendMessage(self::PREFIX . "§cThis level is already an hide and seek game."); return true; } else { $this->getGameManager()->hey = new Game($sender->getLevel()); // Doesn't care 'bout the name set. It customùly sets it. $sender->sendMessage(self::PREFIX . "§cSuccefully created hide and seek game in level {$sender->getLevel()->getName()}."); return true; } break; case "deletegame": case "delgame": if(!is_null($game)) { unset($this->getGameManager()->{$sender->getLevel()->getName()}); $sender->sendMessage(self::PREFIX . "§cSuccefully deleted hide and seek game in level {$sender->getLevel()->getName()}."); return true; } else { $sender->sendMessage(self::PREFIX . "§cYou're not in an hide and seek game world."); } break; case "setmaxplayers": case "smp": if(!is_null($game)) { if(isset($args[1]) && is_int($args[1]) && $args[1] > 1) { $game->setMaxPlayers($args[1]); $sender->sendMessage(self::PREFIX . "§cSuccefully set maximum amount of players of hide and seek game in level {$sender->getLevel()->getName()} to {$args[1]}."); } else { $sender->sendMessage("§cUsage: /hideandseek setmaxplayers "); } return true; } else { $sender->sendMessage(self::PREFIX . "§cYou're not in an hide and seek game world."); } break; case "setseekerspercentage": case "ssp": if(!is_null($game)) { if(isset($args[1]) && is_int($args[1]) && $args[1] > 0 && $args[1] < 100) { $game->setSeekersPercentage($args[1]); $sender->sendMessage(self::PREFIX . "§cSuccefully set seekers percentage of hide and seek game in level {$sender->getLevel()->getName()} to {$args[1]}."); } else { $sender->sendMessage("§cUsage: /hideandseek setseekerspercentage "); } return true; } else { $sender->sendMessage(self::PREFIX . "§cYou're not in an hide and seek game world."); } break; case "setwaitingtime": case "setwaittime": case "swt": if(!is_null($game)) { if(isset($args[1]) && is_int($args[1]) && $args[1] > 0) { $game->setWaitTime($args[1]); $sender->sendMessage(self::PREFIX . "§cSuccefully set waiting time of hide and seek game in level {$sender->getLevel()->getName()} to {$args[1]}."); } else { $sender->sendMessage("§cUsage: /hideandseek setwaittime "); } return true; } else { $sender->sendMessage(self::PREFIX . "§cYou're not in an hide and seek game world."); } break; case "setseektime": case "sst": if(!is_null($game)) { if(isset($args[1]) && is_int($args[1]) && $args[1] > 0) { $game->setSeekTime($args[1]); $sender->sendMessage(self::PREFIX . "§cSuccefully set seeking time of hide and seek game in level {$sender->getLevel()->getName()} to {$args[1]}."); } else { $sender->sendMessage("§cUsage: /hideandseek setseektime "); } return true; } else { $sender->sendMessage(self::PREFIX . "§cYou're not in an hide and seek game world."); } break; case "setspawn": case "ss": $pos = new \pocketmine\math\Vector3($sender->x, $sender->y, $sender->z); if(!is_null($game)) { $game->setSpawn($pos); $sender->sendMessage(self::PREFIX . "§cSuccefully set spawn of hide and seek game in level {$sender->getLevel()->getName()} to x: $pos->x, y: $pos->y, z: $pos->z."); return true; } else { $sender->sendMessage(self::PREFIX . "§cYou're not in an hide and seek game world."); } break; case "setseekersspawn": case "sss": $pos = new \pocketmine\math\Vector3($sender->x, $sender->y, $sender->z); if(!is_null($game)) { $game->setSeekersSpawn($pos); $sender->sendMessage(self::PREFIX . "§cSuccefully set seekers spawn of hide and seek game in level {$sender->getLevel()->getName()} to x: $pos->x, y: $pos->y, z: $pos->z."); return true; } else { $sender->sendMessage(self::PREFIX . "§cYou're not in an hide and seek game world."); } break; case "editmode": //TODO: Mode to edit the map (doesn't let players joining exept if they have a permission & enables block placing and breaking) break; case "start": if(!is_null($game)) { if(count($game->getPlayers()) > 1) { $game->start(); foreach(array_merge($game->getPlayers(), $game->getSpectators()) as $p) { $p->sendMessage(Main::PREFIX . "§aGame started ! There is $this->seekersCount seekers and $this->hidersLeft hiders."); if($p->HideAndSeekRole == self::ROLE_SEEK) { $p->teleport($game->getSeekerSpawn()); } elseif($p->HideAndSeekRole == self::ROLE_HIDE) { $p->teleport($game->getSpawn()); $p->sendPopup("§lHider: You have 1 minute to hide yourself so seekers won't find you ! Don't get caught for " . $this->getSeekTime() . " minutes to win !"); } } } else { $sender->sendMessage(self::PREFIX . "§cThere must be atleast 2 players in your game to force start it."); } return true; } else { $sender->sendMessage(self::PREFIX . "§cYou're not in an hide and seek game world."); } break; case "stop": if(!is_null($game)) { $sender->sendMessage(self::PREFIX . "§aStoping game...."); return true; } else { $sender->sendMessage(self::PREFIX . "§cYou're not in an hide and seek game world."); } default: $sender->sendMessage(str_ireplace(PHP_EOL, PHP_EOL . self::PREFIX,self::PREFIX. "§cSub-command {$args[0]} not found ! Possible subcommands: - creategame (or addgame): Creates a hide and seek - deletegame (or delgame): Deletes the hide and seek - setmaxplayers (or smp): Sets the maximum number of players - setseekerspercentage (or ssp): Sets the percentage of players that will be seekers - setwaittime (or swt): Sets the waiting time of players when 75 percents of the maximum players joined and the game starts - setseektime (or sst): Sets the time seekers have to find all hiders before hiders wins - setspawn(or ss): Sets the spawn of the place players will wait, hide, and seek - setseekersspawn(or sss): Sets the place where players will be tped to while hiders are hiding - start: Force start the game - stop: Force stop the game Please note that all those subcommands are relative to the world where you execute the command in.")); break; } return true; } else { return false; } break; } } # _____ _____ # /\ | __ \ |_ _| # / \ | |__) | | | # / /\ \ | ___/ | | # / ____ \ | | _| |_ # /_/ \_\ |_| |_____| /* Returns the db. @return \Ad5001\HideAndSeek\Database */ public function getDatabase() : Database { return $this->db; } /* Returns the game manager. @param @return GameManager */ public function getGameManager() : GameManager { return $this->gamemanager; } /* Returns the max players in a game. @return int */ public function getMaxPlayers() : int { return (int) $this->getConfig()->get("Max players"); } /* Returns the time to wait between 75% of max players joined and the game start (ending filling if needed) @return int */ public function getWaitTime() : int { return (int) $this->getConfig()->get("Waiting time"); } /* Returns the time that the seekers have to find all hiders (used to balance with the max players) @return int */ public function getSeekTime() : int { return (int) $this->getConfig()->get("Seeking time"); } /* Returns the world players should be tped to when game ends @return \pocketmine\level\Level */ public function getLobbyWorld() : \pocketmine\level\Level { return $this->getServer()->getLevelByName($this->getConfig()->get("Lobby world")) ?? $this->getServer()->getDefaultLevel(); } /* Returns the percentage of the players that should be hunters. @return int */ public function getSeekersPercentage() : int { return (int) $this->getConfig()->get("Seekers percentage"); } # ______ _ # | ____| | | # | |__ __ __ ___ _ __ | |_ ___ # | __| \ \ / / / _ \ | '_ \ | __| / __| # | |____ \ V / | __/ | | | | | |_ \__ \ # |______| \_/ \___| |_| |_| \__| |___/ # # /* Check when a level loads to check if it's a game and then add it @param $event \pocketmine\event\level\LevelLoadEvent */ public function onLevelLoad(\pocketmine\event\level\LevelLoadEvent $event) { $this->getGameManager()->refreshRegisterGames($this->getDatabase()); } }