├── icon.png ├── resources ├── icon.png ├── config.yml ├── README.txt ├── kor.ini └── eng.ini ├── src └── minigameapi │ ├── command │ ├── README.txt │ ├── QuitCommand.php │ └── MiniGameApiCommand.php │ ├── event │ ├── MiniGameStartEvent.php │ ├── MiniGamePlayerRemoveEvent.php │ ├── MiniGameEvent.php │ ├── MiniGamePlayerJoinEvent.php │ └── MiniGamePlayerQuitEvent.php │ ├── task │ └── GameManagerUpdateTask.php │ ├── listener │ ├── PlayerQuitEventListener.php │ ├── PlayerJoinEventListener.php │ ├── PlayerRespawnEventListener.php │ └── PlayerCommandPreprocessEventListener.php │ ├── Time.php │ ├── PlayerData.php │ ├── GameManager.php │ ├── Team.php │ ├── MiniGameApi.php │ └── Game.php ├── .poggit.yml ├── README.md ├── plugin.yml └── LICENSE /icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JustD01t/MiniGameAPI/HEAD/icon.png -------------------------------------------------------------------------------- /resources/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JustD01t/MiniGameAPI/HEAD/resources/icon.png -------------------------------------------------------------------------------- /resources/config.yml: -------------------------------------------------------------------------------- 1 | --- 2 | language: auto 3 | ticks-per-update-cycle: 20 4 | show-left-time: 10 -------------------------------------------------------------------------------- /resources/README.txt: -------------------------------------------------------------------------------- 1 | I'm Korean 2 | So..... I'm not good at English 3 | Please submit pull request if you found an error -------------------------------------------------------------------------------- /src/minigameapi/command/README.txt: -------------------------------------------------------------------------------- 1 | we won't add many commands to "MiniGameAPI" . but, we will make some plugins to manage "MiniGameAPI" with more commands soon 2 | -------------------------------------------------------------------------------- /.poggit.yml: -------------------------------------------------------------------------------- 1 | --- # Poggit-CI Manifest. Open the CI at https://poggit.pmmp.io/ci/MiniGameAPI-PM/MiniGameAPI 2 | branches: 3 | - master 4 | projects: 5 | MiniGameAPI: 6 | path: "/" 7 | ... 8 | -------------------------------------------------------------------------------- /src/minigameapi/event/MiniGameStartEvent.php: -------------------------------------------------------------------------------- 1 | player = $player; 11 | parent::__construct($game); 12 | } 13 | public function getPlayer() { 14 | return $this->player; 15 | } 16 | } -------------------------------------------------------------------------------- /src/minigameapi/event/MiniGameEvent.php: -------------------------------------------------------------------------------- 1 | getMiniGameApi()); 11 | $this->game = $game; 12 | } 13 | public function getGame() : Game { 14 | return $this->game; 15 | } 16 | } -------------------------------------------------------------------------------- /src/minigameapi/event/MiniGamePlayerJoinEvent.php: -------------------------------------------------------------------------------- 1 | player = $player; 12 | } 13 | public function getPlayer() : Player { 14 | return $this->player; 15 | } 16 | } -------------------------------------------------------------------------------- /src/minigameapi/event/MiniGamePlayerQuitEvent.php: -------------------------------------------------------------------------------- 1 | player = $player; 12 | } 13 | public function getPlayer() : Player { 14 | return $this->player; 15 | } 16 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MiniGameAPI 2 | donate bitcoins `16KuLte2UDCjQWHpehGCiUYtPMiMHdR9q3`... 3 | 4 | [![poggit-ci](https://poggit.pmmp.io/ci.badge/MiniGameAPI-PM/MiniGameAPI/MiniGameAPI)](https://poggit.pmmp.io/ci/MiniGameAPI-PM/MiniGameAPI/MiniGameAPI) 5 | 6 | you can get an example plugin [here](https://github.com/MiniGameAPI-PM/MGARace) 7 | 8 | it isn't a minigame it's api and manager for minigames 9 | 10 | **TODO:** 11 | 12 | 1.Organize functions in alphabetical order [ ] 13 | 14 | 2.Support more languages. 15 | -------------------------------------------------------------------------------- /src/minigameapi/task/GameManagerUpdateTask.php: -------------------------------------------------------------------------------- 1 | gameManager = $gameManager; 12 | $this->updateCycle = $updateCycle; 13 | } 14 | public function onRun(int $currentTick) { 15 | $this->gameManager->update($this->updateCycle); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/minigameapi/listener/PlayerQuitEventListener.php: -------------------------------------------------------------------------------- 1 | gameManager = $gameManager; 11 | } 12 | public function onPlayerQuit(PlayerQuitEvent $playerQuitEvent) { 13 | $this->gameManager->removePlayer($playerQuitEvent->getPlayer()); 14 | } 15 | } -------------------------------------------------------------------------------- /plugin.yml: -------------------------------------------------------------------------------- 1 | name: MiniGameAPI 2 | main: minigameapi\MiniGameApi 3 | version: 2.4.3 4 | api: [4.0.0] 5 | author: MiniGameAPI-PM Team 6 | #it's not a team yet hahah 7 | description: The plugin that helps to managing minigame plugins 8 | website: https://github.com/MiniGameAPI-PM 9 | load: POSTWORLD 10 | permissions: 11 | minigameapi: 12 | description: "control all functions of minigameapi" 13 | default: op 14 | children: 15 | minigameapi.join: 16 | default: true 17 | minigameapi.quit: 18 | default: true 19 | minigameapi.list: 20 | default: true 21 | minigameapi.kill: 22 | default: op 23 | -------------------------------------------------------------------------------- /src/minigameapi/listener/PlayerJoinEventListener.php: -------------------------------------------------------------------------------- 1 | miniGameApi = $miniGameApi; 11 | } 12 | public function onPlayerJoin(PlayerJoinEvent $event) { 13 | $data = $this->miniGameApi->getPlayerData($event->getPlayer()->getName()); 14 | if(is_null($data)) return; 15 | $data->restore($event->getPlayer()); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/minigameapi/command/QuitCommand.php: -------------------------------------------------------------------------------- 1 | miniGameApiCommand = new MiniGameApiCommand($miniGameApi); 11 | parent::__construct('quitgame',$miniGameApi); 12 | $this->setAliases([$miniGameApi->getLanguage()->translateString('command.quit')]); 13 | $this->setUsage($miniGameApi->getLanguage()->translateString('command.quit.usage')); 14 | $this->setDescription($miniGameApi->getLanguage()->translateString('command.quit.description')); 15 | $this->setPermission('minigameapi.quit'); 16 | } 17 | public function execute(CommandSender $sender, string $commandLabel, array $args) { 18 | return $this->miniGameApiCommand->execute($sender,$commandLabel,[$this->miniGameApiCommand->getMiniGameApi()->getLanguage()->translateString('command.miniGameApi.quit')]); 19 | } 20 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 MiniGameAPI-PM 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/minigameapi/Time.php: -------------------------------------------------------------------------------- 1 | setTime($tick, $sec, $min, $hour); 8 | } 9 | public function setTime(int $tick = 0,float $sec = 0, float $min = 0, float $hour = 0) : Time{ 10 | $min += $hour * 60; 11 | $sec += $min * 60; 12 | $tick += $sec * 20; 13 | $this->tick = $tick; 14 | return $this; 15 | } 16 | public function addTime(int $tick = 0,float $sec = 0, float $min = 0, float $hour = 0) : Time{ 17 | $min += $hour * 60; 18 | $sec += $min * 60; 19 | $tick += $sec * 20; 20 | $this->tick += $tick; 21 | return $this; 22 | } 23 | public function reduceTime(int $tick = 0,float $sec = 0, float $min = 0, float $hour = 0) : Time{ 24 | $min += $hour * 60; 25 | $sec += $min * 60; 26 | $tick += $sec * 20; 27 | $this->tick -= $tick; 28 | return $this; 29 | } 30 | public function asSec() : float { 31 | return $this->tick / 20; 32 | } 33 | public function asMin() : float { 34 | return $this->asSec() / 60; 35 | } 36 | public function asHour() : float { 37 | return $this->asMin() / 60; 38 | } 39 | public function asTick() : int { 40 | return intval($this->tick); 41 | } 42 | public function format() : array { 43 | return explode(':',gmdate('H:i:s',$this->asSec())); 44 | //array(0 => hour,1 => min, 2 => sec) 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/minigameapi/listener/PlayerRespawnEventListener.php: -------------------------------------------------------------------------------- 1 | miniGameApi = $miniGameApi; 16 | } 17 | public function onPlayerRespawn(PlayerRespawnEvent $event) { 18 | if (!is_null($this->miniGameApi->getGameManager()->getJoinedGame($event->getPlayer()))) return; 19 | $this->miniGameApi->getScheduler()->scheduleDelayedTask(new class($this->miniGameApi, $event->getPlayer()) extends Task { 20 | public $miniGameApi; 21 | public $player; 22 | public function __construct(MiniGameApi $miniGameApi, Player $player) { 23 | $this->miniGameApi = $miniGameApi; 24 | $this->player = $player; 25 | } 26 | public function onRun(int $currentTick) { 27 | $data = $this->miniGameApi->getPlayerData($this->player->getName()); 28 | if (!is_null($data)) $data->restore($this->player); 29 | } 30 | }, 5); //TODO rewrite 31 | } 32 | } -------------------------------------------------------------------------------- /src/minigameapi/PlayerData.php: -------------------------------------------------------------------------------- 1 | location['level'] = $player->getLevel()->getFolderName(); 19 | $this->location['x'] = $player->getX(); 20 | $this->location['y'] = $player->getY(); 21 | $this->location['z'] = $player->getZ(); 22 | $this->nameTag = $player->getNameTag(); 23 | $this->items = $player->getInventory()->getContents(true); 24 | $this->armors = $player->getArmorInventory()->getContents(true); 25 | $this->health = $player->getHealth(); 26 | $this->gamemode = $player->getGamemode(); 27 | $this->score = $player->getScoreTag(); 28 | } 29 | public function restore(Player $player) { 30 | $player->teleport(new Position($this->location['x'],$this->location['y'],$this->location['z'],Server::getInstance()->getLevelByName($this->location['level']))); 31 | $player->setNameTag($this->nameTag); 32 | $player->getInventory()->setContents($this->items,true); 33 | $player->getArmorInventory()->setContents($this->armors,true); 34 | $player->setHealth($this->health); 35 | $player->setGamemode($this->gamemode); 36 | $player->setScoreTag(is_null($this->score) ? '' : $this->score); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/minigameapi/listener/PlayerCommandPreprocessEventListener.php: -------------------------------------------------------------------------------- 1 | gameManager = $gameManager; 11 | } 12 | public function onPlayerCommandPreprocess(PlayerCommandPreprocessEvent $event) { 13 | if($event->isCancelled()) return; 14 | $game = $this->gameManager->getJoinedGame($event->getPlayer()); 15 | if(is_null($game)) return; 16 | if (substr($event->getMessage(),0,1) !== '/') return; 17 | $event->setCancelled(!$game->isAllowedCommand(substr(implode('.', array_map("stripslashes", str_getcsv($event->getMessage(), " "))),1))); 18 | if($event->isCancelled()) { 19 | $event->getPlayer()->sendMessage($game->getPrefix() . $this->gameManager->getMiniGameApi()->getLanguage()->translateString('commandMessage.commandNotAllowedInGame')); 20 | $event->getPlayer()->sendMessage($this->gameManager->getMiniGameApi()->getLanguage()->translateString('commandMessage.quitFirst', [$this->gameManager->getMiniGameApi()->getBaseLang()->translateString('command.quit.usage',[$this->gameManager->getMiniGameApi()->getLanguage()->translateString('command.quit')]), $this->gameManager->getMiniGameApi()->getBaseLang()->translateString('command.miniGameApi.quit.usage',[$this->gameManager->getMiniGameApi()->getBaseLang()->translateString('command.miniGameApi'), $this->gameManager->getMiniGameApi()->getBaseLang()->translateString('command.miniGameApi.quit')])])); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /resources/kor.ini: -------------------------------------------------------------------------------- 1 | prefix=[미니게임] 2 | command.quit = 나가기 3 | command.quit.usage=/{%0} 4 | ;%0 = command.quit 5 | command.quit.description=게임에서 나갑니다. 6 | command.miniGameApi=미니게임 7 | command.miniGameApi.description=미니게임API명령어. 8 | command.miniGameApi.join=참여 9 | command.miniGameApi.join.usage=/{%0} {%1} 10 | ;%0 = command.miniGameApi 11 | ;%1 = command.miniGameApi.join 12 | command.miniGameApi.join.description=게임에 참여합니다. 13 | command.miniGameApi.quit=나가기 14 | command.miniGameApi.quit.usage=/{%0} {%1} 15 | ;%0 = command.miniGameApi 16 | ;%1 = command.miniGameApi.quit 17 | command.miniGameApi.quit.description=게임에서 나갑니다. 18 | command.miniGameApi.list=목록 19 | command.miniGameApi.list.usage=/{%0} {%1} 20 | ;%0 = command.miniGameApi 21 | ;%1 = command.miniGameApi.list 22 | command.miniGameApi.list.description=게임 목록을 표시합니다. 23 | command.miniGameApi.kill=종료 24 | command.miniGameApi.kill.usage=/{%0} {%1} 25 | ;%0 = command.miniGameApi 26 | ;%1 = command.miniGameApi.kill 27 | command.miniGameApi.kill.description=게임을 강제종료합니다. 28 | commandMessage.onlyPlayers=플레이어만 이 명령어를 실행할 수 있습니다. 29 | commandMessage.commandNotAllowedInGame=이 게임에서 이 명령어는 허용되지 않았습니다. 30 | commandMessage.quitFirst=먼저, 게임에서 나가시려면 {%0} 나 {%1} 을 입력해주세요. 31 | ;%0 = command.quit.usage 32 | ;%1 = command.miniGameApi.quit.usage 33 | join.failed.alreadyStarted=게임이 이미 시작되었습니다. 34 | join.failed.alreadyInAnotherGame=이미 다른 게임에 접속해 있습니다. 35 | join.failed.notExistingGame=존재하지 않는 게임입니다. 36 | join.failed.fullGame=게임이 꽉찼습니다. 37 | join.success="{%0}" 에 참여했습니다. 38 | quit.failed.notPlaying=당신은 지금 게임을 플레이하고 있지 않습니다. 39 | quit.success=게임에서 퇴장했습니다. 40 | list.message=게임 목록: 41 | kill.failed.notExistingGame=존재하지 않는 게임입니다. 42 | kill.success="{%0}"을 강제종료하였습니다. 43 | exception.assigningPlayers=플레이어가 완전히 분배되지 않았습니다. 44 | exception.invalidIconImagePath="{%0}" 은 이미지 경로가 아닙니다. 45 | exception.invalidIconItem=공기를 아이콘 아이템으로 사용할 수 없습니다. 46 | left.time={%0} 초 남음. 47 | left.players=플레이어: (필요: {%0} / 현재: {%1} / 최대: {%2}) 48 | end.normal={%0} 게임이 끝났습니다. 49 | end.won={%0}가 {%1}에서 승리하였습니다!! 50 | start.started=게임이 시작되었습니다. -------------------------------------------------------------------------------- /resources/eng.ini: -------------------------------------------------------------------------------- 1 | prefix=[MiniGameAPI] 2 | command.quit = quit 3 | command.quit.usage=/{%0} 4 | ;%0 = command.quit 5 | command.quit.description=Quit the game. 6 | command.miniGameApi=minigame 7 | command.miniGameApi.description=Command of MiniGameApi. 8 | command.miniGameApi.join=join 9 | command.miniGameApi.join.usage=/{%0} {%1} 10 | ;%0 = command.miniGameApi 11 | ;%1 = command.miniGameApi.join 12 | command.miniGameApi.join.description=Join to the game. 13 | command.miniGameApi.quit=quit 14 | command.miniGameApi.quit.usage=/{%0} {%1} 15 | ;%0 = command.miniGameApi 16 | ;%1 = command.miniGameApi.quit 17 | command.miniGameApi.quit.description=Quit the game. 18 | command.miniGameApi.list=list 19 | command.miniGameApi.list.usage=/{%0} {%1} 20 | ;%0 = command.miniGameApi 21 | ;%1 = command.miniGameApi.list 22 | command.miniGameApi.list.description=Get list of Games. 23 | command.miniGameApi.kill=kill 24 | command.miniGameApi.kill.usage=/{%0} {%1} 25 | ;%0 = command.miniGameApi 26 | ;%1 = command.miniGameApi.kill 27 | command.miniGameApi.kill.description=Kill the game. 28 | commandMessage.onlyPlayers=Only players can run this command. 29 | commandMessage.commandNotAllowedInGame=This command is not enabled in this game. 30 | commandMessage.quitFirst=Type {%0} or {%1} to quit first. 31 | ;%0 = command.quit.usage 32 | ;%1 = command.miniGameApi.quit.usage 33 | join.failed.alreadyStarted=Game is already started. 34 | join.failed.alreadyInAnotherGame=You are already in another game. 35 | join.failed.notExistingGame=Game is not Existing. 36 | join.failed.fullGame=Game is full. 37 | join.success=You Joined to "{%0}" 38 | quit.failed.notPlaying=You are not playing a game. 39 | quit.success=You quited the game. 40 | list.message=List of games: 41 | kill.failed.notExistingGame=Game is not Existing. 42 | kill.success=You killed game "{%0}" 43 | exception.assigningPlayers=Players are not completely assigned. 44 | exception.invalidIconImagePath="{%0}" is not an image path. 45 | exception.invalidIconItem=Air is not able to use as iconItem. 46 | left.time={%0} seconds left. 47 | left.players=Players: (need: {%0} / now: {%1} / max: {%2}) 48 | end.won={%0} won in {%1}!! 49 | end.normal={%0} is end. 50 | start.started=Game has started. -------------------------------------------------------------------------------- /src/minigameapi/GameManager.php: -------------------------------------------------------------------------------- 1 | miniGameApi = $miniGameApi; 13 | } 14 | public function broadcastMessageToGames(string $message){ 15 | foreach($this->getGames() as $game) { 16 | $game->broadcastMessage($message); 17 | } 18 | } 19 | public function getMiniGameApi() : MiniGameApi { 20 | return $this->miniGameApi; 21 | } 22 | public function submitGame(Game $game) : bool { 23 | if(!is_null($this->getGame($game->getName()))) return false; 24 | $this->games[] = $game; 25 | return true; 26 | } 27 | public function removeGame(string $gameName) { 28 | foreach($this->getGames() as $key => $game){ 29 | if($game->getName() == $gameName) { 30 | if($game->isRunning()) $game->end(Game::END_KILLED_GAME); 31 | unset($this->games[$key]); 32 | } 33 | } 34 | $this->games = array_values($this->games); 35 | } 36 | public function getGames() : array{ 37 | return $this->games; 38 | } 39 | public function getGame(string $gameName) : ?Game{ 40 | foreach($this->getGames() as $game) { 41 | if($game->getName() == $gameName) return $game; 42 | } 43 | return null; 44 | } 45 | public function getTeams() : array { 46 | $result = []; 47 | foreach($this->getGames() as $game) { 48 | $result = array_merge($result,$game->getTeams()); 49 | } 50 | return $result; 51 | } 52 | public function getPlayers() : array{ 53 | $result = []; 54 | foreach($this->getGames() as $game){ 55 | $result = array_merge($result,$game->getPlayers()); 56 | } 57 | return $result; 58 | } 59 | public function removePlayer(Player $player) : bool{ 60 | foreach($this->getGames() as $game) { 61 | if($game->removePlayer($player)) return true; 62 | } 63 | return false; 64 | } 65 | public function quitPlayer(Player $player) : bool{ 66 | foreach($this->getGames() as $game) { 67 | if($game->quitPlayer($player)) return true; 68 | } 69 | return false; 70 | } 71 | public function getJoinedGame(Player $player) : ?Game { 72 | foreach ($this->getGames() as $game) { 73 | if ($game->isInGame($player)) return $game; 74 | } 75 | return null; 76 | } 77 | public function update(int $updateCycle) { 78 | foreach($this->getGames() as $game) { 79 | $game->update($updateCycle); 80 | } 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/minigameapi/Team.php: -------------------------------------------------------------------------------- 1 | game = $game; 17 | $this->name = $teamName; 18 | $this->setMinPlayers($minPlayers); 19 | $this->setSpawn($spawn); 20 | } 21 | public function getPoints() : float { 22 | return $this->points; 23 | } 24 | public function setPoints(float $points) : void { 25 | $this->points = $points; 26 | } 27 | public function addPoints(float $points) : void { 28 | $this->points += $points; 29 | } 30 | public function reducePoints(float $points) : void { 31 | $this->points -= $points; 32 | } 33 | public function getName() : string { 34 | return $this->name; 35 | } 36 | public function getGame() : ?Game{ 37 | return $this->game; 38 | } 39 | public function getMinPlayers() : int{ 40 | return $this->minPlayers; 41 | } 42 | public function setMinPlayers(int $minPlayers) { 43 | $this->minPlayers = $minPlayers; 44 | return; 45 | } 46 | public function getSpawn() : ?Position{ 47 | return $this->spawn; 48 | } 49 | public function setSpawn(?Position $spawn) { 50 | $this->spawn = $spawn; 51 | } 52 | public function addPlayer(Player $player) : bool{ 53 | if (!$this->getGame()->isInGame($player)) return false; 54 | $this->getGame()->removePlayer($player); 55 | $this->players[] = $player; 56 | return true; 57 | } 58 | public function getPlayers() : array { 59 | return $this->players; 60 | } 61 | public function removePlayer(Player $player) : bool { 62 | foreach ($this->players as $key => $pl) { 63 | if($player->getName() == $pl->getName()) { 64 | $ev = new MiniGamePlayerRemoveEvent($this->getGame(),$player); 65 | $this->getGame()->getMiniGameApi()->getServer()->getPluginManager()->callEvent($ev); 66 | unset($this->players[$key]); 67 | $this->players = array_values($this->players); 68 | if(count($this->getPlayers()) == 0) $this->getGame()->removeTeam($this->getName()); 69 | return true; 70 | } 71 | } 72 | return false; 73 | } 74 | public function broadcastMessage(string $message) { 75 | foreach($this->getPlayers() as $player) { 76 | //$player instanceof Player; 77 | $player->sendMessage($message); 78 | } 79 | return; 80 | } 81 | public function teleport(Position $position){ 82 | foreach($this->getPlayers() as $player) { 83 | $player->teleport($position); 84 | } 85 | } 86 | public function spawn(){ 87 | if(!is_null($this->getSpawn())) $this->teleport($this->getSpawn()); 88 | } 89 | public function isInTeam(Player $player) : bool { 90 | foreach ($this->getPlayers() as $pl) { 91 | if($pl->getName() == $player->getName()) return true; 92 | } 93 | return false; 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /src/minigameapi/MiniGameApi.php: -------------------------------------------------------------------------------- 1 | gameManager = new GameManager($this); 23 | } 24 | public static function getInstance() : MiniGameApi{ 25 | return self::$instance; 26 | } 27 | public function onEnable() : void{ 28 | @mkdir($this->getDataFolder()); 29 | @mkdir($this->getDataFolder() . 'playerData'); 30 | @mkdir($this->getDataFolder() . 'lang'); 31 | $this->saveDefaultConfig(); 32 | foreach ($this->getResources() as $resource) { 33 | if(substr($resource->getFilename(),-3) == 'ini') file_put_contents($this->getDataFolder() . 'lang' . DIRECTORY_SEPARATOR . $resource->getFilename(),file_get_contents($resource->getPathname())); 34 | if(substr($resource->getFilename(),-3) == 'png') file_put_contents($this->getDataFolder() . 'icon.png', file_get_contents($resource->getPathname())); 35 | } 36 | 37 | $this->getScheduler()->scheduleRepeatingTask(new GameManagerUpdateTask($this->getGameManager(),$this->getConfig()->get('ticks-per-update-cycle', 20)), $this->getConfig()->get('ticks-per-update-cycle', 20)); 38 | $this->getServer()->getPluginManager()->registerEvents(new PlayerQuitEventListener($this->getGameManager()), $this); 39 | $this->getServer()->getPluginManager()->registerEvents(new PlayerCommandPreprocessEventListener($this->getGameManager()), $this); 40 | $this->getServer()->getPluginManager()->registerEvents(new PlayerJoinEventListener($this),$this); 41 | $this->getServer()->getPluginManager()->registerEvents(new PlayerRespawnEventListener($this), $this); 42 | $this->baseLang = new Language($this->getConfig()->get('language', 'auto') == 'auto' ? $this->getServer()->getProperty("settings.language") : $this->getConfig()->get('language'),$this->getDataFolder() . 'lang' . DIRECTORY_SEPARATOR); 43 | $this->getServer()->getCommandMap()->register('minigameapi', new MiniGameApiCommand($this)); 44 | $this->getServer()->getCommandMap()->register('quit', new QuitCommand($this)); 45 | } 46 | public function getLanguage() : Language{ 47 | return $this->baseLang; 48 | } 49 | public function getLogoImagePath() : string { 50 | return $this->getDataFolder() . 'logo.png'; 51 | } 52 | public function getGameManager() : GameManager{ 53 | return $this->gameManager; 54 | } 55 | public function setPlayerData(string $playerName, PlayerData $playerData) { 56 | file_put_contents($this->getDataFolder() . strtolower($playerName) . '.dat', serialize($playerData)); 57 | } 58 | public function getPlayerData(string $playerName, bool $delete = true) : ?PlayerData { 59 | if(!file_exists($this->getDataFolder() . strtolower($playerName) . '.dat')) return null; 60 | $return = unserialize(file_get_contents($this->getDataFolder() . strtolower($playerName) . '.dat')); 61 | if($delete) unlink($this->getDataFolder() . strtolower($playerName) . '.dat'); 62 | return $return; 63 | } 64 | public function getPrefix() : string { 65 | return TextFormat::GREEN . $this->getLanguage()->translateString('prefix') . ' ' . TextFormat::YELLOW; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/minigameapi/command/MiniGameApiCommand.php: -------------------------------------------------------------------------------- 1 | miniGameApi = $miniGameApi; 16 | parent::__construct('minigameapi', $miniGameApi); 17 | $this->setAliases([$this->getLanguage()->translateString('command.miniGameApi')]); 18 | $this->setUsage(TextFormat::EOL . 19 | $this->getPrefix() . 'MiniGameAPI-' . $this->getMiniGameApi()->getDescription()->getVersion() . ' by djdisodo(왕고슴도치)' . TextFormat::RESET . TextFormat::EOL . 20 | $this->getLanguage()->translateString('command.miniGameApi.join.usage',[$this->getLanguage()->translateString('command.miniGameApi'), $this->getLanguage()->translateString('command.miniGameApi.join')]) . TextFormat::GREEN . ' : ' . TextFormat::RESET . $this->getLanguage()->translateString('command.miniGameApi.join.description') . TextFormat::EOL . 21 | $this->getLanguage()->translateString('command.miniGameApi.quit.usage',[$this->getLanguage()->translateString('command.miniGameApi'), $this->getLanguage()->translateString('command.miniGameApi.quit')]) . TextFormat::GREEN . ' : ' . TextFormat::RESET . $this->getLanguage()->translateString('command.miniGameApi.quit.description') . TextFormat::EOL . 22 | $this->getLanguage()->translateString('command.miniGameApi.list.usage',[$this->getLanguage()->translateString('command.miniGameApi'), $this->getLanguage()->translateString('command.miniGameApi.list')]) . TextFormat::GREEN . ' : ' . TextFormat::RESET . $this->getLanguage()->translateString('command.miniGameApi.list.description') . TextFormat::EOL . 23 | $this->getLanguage()->translateString('command.miniGameApi.kill.usage',[$this->getLanguage()->translateString('command.miniGameApi'), $this->getLanguage()->translateString('command.miniGameApi.kill')]) . TextFormat::GREEN . ' : ' . TextFormat::RESET . $this->getLanguage()->translateString('command.miniGameApi.kill.description') . TextFormat::EOL 24 | ); 25 | $this->setDescription($this->getLanguage()->translateString('command.miniGameApi.description')); 26 | } 27 | public function execute(CommandSender $sender, string $commandLabel, array $args) { 28 | if(!isset($args[0])) { 29 | $sender->sendMessage($this->getMiniGameApi()->getServer()->getLanguage()->translateString('commands.generic.usage',[$this->getUsage()])); 30 | return; 31 | } 32 | switch ($args[0]) { 33 | case $this->getLanguage()->translateString('command.miniGameApi.join'): 34 | if (!$sender->hasPermission('minigameapi.join')) { 35 | $sender->sendMessage($this->getMiniGameApi()->getServer()->getLanguage()->translateString('commands.generic.permission')); 36 | break; 37 | } 38 | if (!$sender instanceof Player) { 39 | $sender->sendMessage($this->getPrefix() . $this->getLanguage()->translateString('commandMessage.onlyPlayers')); 40 | break; 41 | } 42 | if (!isset($args[1])) { 43 | $sender->sendMessage($this->getMiniGameApi()->getServer()->getLanguage()->translateString('commands.generic.usage',[$this->getLanguage()->translateString('command.miniGameApi.join.usage',[$this->getLanguage()->translateString('command.miniGameApi'), $this->getLanguage()->translateString('command.miniGameApi.join')]) . TextFormat::RED])); 44 | break; 45 | } 46 | if (!is_null($this->getMiniGameApi()->getGameManager()->getJoinedGame($sender))) { 47 | $sender->sendMessage($this->getPrefix() . $this->getLanguage()->translateString('join.failed.alreadyInAnotherGame')); 48 | $sender->sendMessage($this->getPrefix() . $this->getLanguage()->translateString('commandMessage.quitFirst', [$this->getLanguage()->translateString('command.quit.usage',[$this->getLanguage()->translateString('command.quit')]), $this->getLanguage()->translateString('command.miniGameApi.quit.usage',[$this->getLanguage()->translateString('command.miniGameApi'), $this->getLanguage()->translateString('command.miniGameApi.quit')])])); 49 | break; 50 | } 51 | $game = $this->getMiniGameApi()->getGameManager()->getGame($args[1]); 52 | if(is_null($game)) { 53 | $sender->sendMessage($this->getPrefix() . $this->getLanguage()->translateString('join.failed.notExistingGame')); 54 | break; 55 | } 56 | if ($game->isRunning()) { 57 | $sender->sendMessage($this->getPrefix() . $this->getLanguage()->translateString('join.failed.alreadyStarted')); 58 | break; 59 | } 60 | if ($game->getMaxPlayers() == count($game->getPlayers())) { 61 | $sender->sendMessage($this->getPrefix() . $this->getLanguage()->translateString('join.failed.fullGame')); 62 | break; 63 | } 64 | if ($game->addWaitingPlayer($sender)) { 65 | $sender->sendMessage($this->getPrefix() . $this->getLanguage()->translateString('join.success',[$game->getName()])); 66 | } 67 | break; 68 | case $this->getLanguage()->translateString('command.miniGameApi.quit'): 69 | if (!$sender->hasPermission('minigameapi.quit')) { 70 | $sender->sendMessage($this->getMiniGameApi()->getServer()->getLanguage()->translateString('commands.generic.permission')); 71 | break; 72 | } 73 | if (!$sender instanceof Player) { 74 | $sender->sendMessage($this->getPrefix() . $this->getLanguage()->translateString('commandMessage.onlyPlayers')); 75 | break; 76 | } 77 | if($this->getMiniGameApi()->getGameManager()->quitPlayer($sender)) { 78 | $sender->sendMessage($this->getPrefix() . $this->getMiniGameApi()->getLanguage()->translateString('quit.success')); 79 | break; 80 | } 81 | $sender->sendMessage($this->getPrefix() . $this->getLanguage()->translateString('quit.failed.notPlaying')); 82 | break; 83 | case $this->getLanguage()->translateString('command.miniGameApi.list'): 84 | if (!$sender->hasPermission('minigameapi.list')) { 85 | $sender->sendMessage($this->getMiniGameApi()->getServer()->getLanguage()->translateString('commands.generic.permission')); 86 | break; 87 | } 88 | $list = []; 89 | foreach ($this->getMiniGameApi()->getGameManager()->getGames() as $game) { 90 | $list[] = $game->getName(); 91 | } 92 | $sender->sendMessage($this->getPrefix() . $this->getLanguage()->translateString('list.message')); 93 | $sender->sendMessage(TextFormat::YELLOW . implode(', ', $list)); 94 | break; 95 | case $this->getLanguage()->translateString('command.miniGameApi.kill'): 96 | if (!$sender->hasPermission('minigameapi.kill')) { 97 | $sender->sendMessage($this->getMiniGameApi()->getServer()->getLanguage()->translateString('commands.generic.permission')); 98 | break; 99 | } 100 | if (!isset($args[1])) { 101 | $sender->sendMessage($this->getMiniGameApi()->getServer()->getLanguage()->translateString('commands.generic.usage',[$this->getLanguage()->translateString('command.miniGameApi.kill.usage',[$this->getLanguage()->translateString('command.miniGameApi'), $this->getLanguage()->translateString('command.miniGameApi.kill')]) . TextFormat::GREEN . ' : ' . TextFormat::RESET . $this->getLanguage()->translateString('command.miniGameApi.kill.description') . TextFormat::EOL])); 102 | break; 103 | } 104 | $game = $this->getMiniGameApi()->getGameManager()->getGame($args[1]); 105 | if(is_null($game)) { 106 | $sender->sendMessage($this->getPrefix() . $this->getLanguage()->translateString('kill.failed.notExistingGame')); 107 | break; 108 | } 109 | $game->end(Game::END_KILLED_GAME); 110 | $sender->sendMessage($this->getPrefix() . $this->getLanguage()->translateString('kill.success', [$game->getName()])); 111 | break; 112 | default: 113 | $sender->sendMessage($this->getMiniGameApi()->getServer()->getLanguage()->translateString('commands.generic.usage',[$this->getUsage()])); 114 | return; 115 | } 116 | return; 117 | } 118 | 119 | public function getMiniGameApi() : MiniGameApi { 120 | return $this->miniGameApi; 121 | } 122 | public function getPrefix() : string { 123 | return $this->getMiniGameApi()->getPrefix(); 124 | } 125 | public function getLanguage() : Language { 126 | return $this->getMiniGameApi()->getLanguage(); 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /src/minigameapi/Game.php: -------------------------------------------------------------------------------- 1 | plugin = $plugin; 41 | $this->name = $name; 42 | $this->setPrefix('[' . $name . ']'); 43 | $this->neededPlayers = $neededPlayers; 44 | $this->maxPlayers = $maxPlayers; 45 | $this->runningTime = is_null($runningTime) ? new Time(0,0,5) : $runningTime; 46 | $this->waitingRoom = $waitingRoom; 47 | $this->waitingTime = is_null($waitingTime) ? new Time(0,30) : $waitingTime; 48 | } 49 | final public function addAllowedCommand(string $command) { 50 | $this->allowedCommands[] = $command; 51 | } 52 | final public function addAllowedCommands(array $commands) { 53 | $this->allowedCommands = array_merge($this->allowedCommands, $commands); 54 | } 55 | final public function addWaitingPlayer(Player $player) : bool{ 56 | if($this->isRunning()) return false; 57 | if($this->getMaxPlayers() == count($this->getPlayers())) return false; 58 | $ev = new MiniGamePlayerJoinEvent($this, $player); 59 | $this->getMiniGameApi()->getServer()->getPluginManager()->callEvent($ev); 60 | if($ev->isCancelled()) return false; 61 | $this->getMiniGameApi()->setPlayerData($player->getName(), new PlayerData($player)); 62 | if($this->onJoin()) { 63 | $this->getGameManager()->removePlayer($player); 64 | $this->waitingPlayers[] = $player; 65 | if(!is_null($this->getWaitingRoom())) $player->teleport($this->getWaitingRoom()); 66 | $player->getInventory()->clearAll(); 67 | $player->getArmorInventory()->clearAll(); 68 | $player->setHealth($player->getMaxHealth()); 69 | $player->setGamemode(Player::ADVENTURE); 70 | if($this->getMaxPlayers() == count($this->getPlayers())) { 71 | $this->start(); 72 | return true; 73 | } 74 | if($this->getNeededPlayers() == count($this->getPlayers())) $this->wait(); 75 | $this->broadcastMessage($this->getMiniGameApi()->getPrefix() . $this->getMiniGameApi()->getLanguage()->translateString('left.players', [$this->getNeededPlayers(), count($this->getPlayers()),$this->getMaxPlayers()])); 76 | return true; 77 | } 78 | return false; 79 | } 80 | public function assignPlayers() { 81 | foreach($this->getPlayers() as $player) { 82 | $team = new Team($this, $player->getName(), 1, 1); 83 | $team->addPlayer($player); 84 | $this->submitTeam($team); 85 | } 86 | } 87 | final public function broadcastMessage(string $message){ 88 | foreach($this->getPlayers() as $player) { 89 | $player->sendMessage($message); 90 | } 91 | return; 92 | } 93 | final public function end(int $endCode = self::END_NORMAL) { 94 | switch($endCode) { 95 | case self::END_NORMAL: 96 | case self::END_TIMEOUT: 97 | case self::END_NO_PLAYERS: 98 | case self::END_KILLED_GAME: 99 | case self::END_STARTING_ERROR: 100 | $this->onEnd($endCode); 101 | if (!is_null($this->getWinner())) { 102 | $this->getMiniGameApi()->getServer()->broadcastMessage($this->getMiniGameApi()->getPrefix() . $this->getMiniGameApi()->getLanguage()->translateString('end.won',[$this->getWinner()->getName(), $this->getName()])); 103 | } else { 104 | $this->getMiniGameApi()->getServer()->broadcastMessage($this->getMiniGameApi()->getPrefix() . $this->getMiniGameApi()->getLanguage()->translateString('end.normal',[$this->getName()])); 105 | } 106 | foreach ($this->getPlayers() as $player) { 107 | $this->quitPlayer($player,true); 108 | } 109 | unset($this->remainingWaitTime); 110 | unset($this->remainingRunTime); 111 | $this->reset(); 112 | break; 113 | } 114 | } 115 | final public function getAllowedCommands() : array { 116 | return $this->allowedCommands; 117 | } 118 | final public function getDescription() : string { 119 | return $this->description; 120 | } 121 | final public function getMiniGameApi() : MiniGameApi { 122 | return $this->getPlugin()->getServer()->getPluginManager()->getPlugin('MiniGameAPI'); 123 | } 124 | final public function getGameManager() : GameManager{ 125 | return $this->getMiniGameApi()->getGameManager(); 126 | } 127 | final public function getIconImage() : string { 128 | if(isset($this->iconImage)) return $this->iconImage; 129 | return $this->getMiniGameApi()->getLogoImagePath(); 130 | } 131 | final public function getIconItem() : Item { 132 | if(isset($this->iconItem)) return $this->iconItem; 133 | return new WheatSeeds(); 134 | } 135 | final public function getJoinedTeam(Player $player) : ?Team { 136 | foreach ($this->getTeams() as $team) { 137 | if($team->isInTeam($player)) return $team; 138 | } 139 | return null; 140 | } 141 | final public function getMaxPlayers() : int{ 142 | return $this->maxPlayers; 143 | } 144 | final public function getName() : string{ 145 | return $this->name; 146 | } 147 | final public function getNeededPlayers() : int{ 148 | return $this->neededPlayers; 149 | } 150 | final public function getPrefix() : string{ 151 | return $this->prefix; 152 | } 153 | final public function getPlayers() : array{ 154 | if(!$this->isRunning()) return $this->waitingPlayers; 155 | $result = []; 156 | foreach($this->getTeams() as $team) { 157 | $result = array_merge($result,$team->getPlayers()); 158 | } 159 | return $result; 160 | } 161 | final public function getPlugin() : Plugin{ 162 | return $this->plugin; 163 | } 164 | final public function getRemainingRunTime() : ?Time { 165 | return isset($this->remainingRunTime) ? $this->remainingRunTime : null; 166 | } 167 | final public function getRemainingWaitTime() : ?Time { 168 | return isset($this->remainingWaitTime) ? $this->remainingWaitTime : null; 169 | } 170 | final public function getWaitingRoom() : ?Position { 171 | return $this->waitingRoom; 172 | } 173 | final public function getWinner() : ?Team { 174 | return $this->winner; 175 | } 176 | final public function getRunningTime() : Time { 177 | return $this->runningTime; 178 | } 179 | final public function getTeam(string $teamName) : ?Team{ 180 | foreach($this->getTeams() as $team) { 181 | if($teamName == $team->getName()) return $team; 182 | } 183 | return null; 184 | } 185 | final public function getTeams() : array{ 186 | return $this->teams; 187 | } 188 | final public function getWaitingTime() : Time { 189 | return $this->waitingTime; 190 | } 191 | final public function isAllowedCommand(string $command) : bool{ 192 | switch (explode('.', $command)[0]) { 193 | case 'minigameapi': 194 | case $this->getMiniGameApi()->getLanguage()->translateString('command.miniGameApi'): 195 | case $this->getMiniGameApi()->getLanguage()->translateString('command.quit'): 196 | return true; 197 | } 198 | foreach ($this->getAllowedCommands() as $allowedCommand) { 199 | if(explode('.', $allowedCommand) == array_splice(explode('.', $command), count(explode('.', $allowedCommand)))) return true; 200 | } 201 | return false; 202 | } 203 | final public function isInGame(Player $player) : bool { 204 | if(!$this->isRunning()) foreach ($this->getPlayers() as $pl) { 205 | if($pl->getName() == $player->getName()) return true; 206 | } 207 | if(is_null($this->getJoinedTeam($player))) return false; 208 | return true; 209 | } 210 | final public function isStartable() : bool{ 211 | foreach($this->getTeams() as $team) { 212 | if(count($team->getPlayers()) < $team->getMinPlayers()) return false; 213 | } 214 | return true; 215 | } 216 | final public function isRunning() : bool { 217 | return is_null($this->getRemainingRunTime()) ? false : true; 218 | } 219 | final public function isWaiting() : bool { 220 | return is_null($this->getRemainingWaitTime()) ? false : true; 221 | } 222 | public function onEnd(int $endCode) {} 223 | public function onJoin() : bool{ return true; } 224 | public function onStart() : bool{ return true; } 225 | public function onWait() : bool{ return true; } 226 | public function onWaiting(int $updateCycle) {} 227 | public function onRunning(int $updateCycle) {} 228 | public function onUpdate(int $updateCycle) {} 229 | final public function quitPlayer(Player $player, bool $end = false) : bool { 230 | if (!$end) { 231 | $ev = new MiniGamePlayerQuitEvent($this, $player); 232 | $this->getMiniGameApi()->getServer()->getPluginManager()->callEvent($ev); 233 | if ($ev->isCancelled()) return false; 234 | } 235 | if ($player->isAlive()) { 236 | if(!$this->removePlayer($player)) return false; 237 | $this->getMiniGameApi()->getPlayerData($player->getName())->restore($player); 238 | return true; 239 | } 240 | return true; 241 | } 242 | final public function removePlayer(Player $player) : bool{ 243 | if($this->isRunning()) { 244 | foreach ($this->getTeams() as $team) { 245 | if($team->removePlayer($player)) { 246 | return true; 247 | } 248 | } 249 | } else { 250 | foreach ($this->getPlayers() as $key => $pl) { 251 | //$pl instanceof Player; 252 | if ($player->getName() == $pl->getName()) { 253 | $ev = new MiniGamePlayerRemoveEvent($this,$player); 254 | $this->getMiniGameApi()->getServer()->getPluginManager()->callEvent($ev); 255 | unset($this->waitingPlayers[$key]); 256 | $this->waitingPlayers = array_values($this->waitingPlayers); 257 | if ($this->getNeededPlayers() > count($this->getPlayers())) unset($this->remainingWaitTime); 258 | return true; 259 | } 260 | } 261 | } 262 | return false; 263 | } 264 | final public function removeTeam(string $teamName) { 265 | foreach($this->getTeams() as $key => $team){ 266 | if($team->getName() == $teamName){ 267 | unset($this->teams[$key]); 268 | } 269 | } 270 | $this->teams = array_values($this->teams); 271 | if(count($this->getTeams()) == 0 and $this->isRunning()) $this->end(self::END_NO_PLAYERS); 272 | return; 273 | } 274 | final public function reset() { 275 | $this->resetWaitingPlayers(); 276 | $this->resetTeams(); 277 | } 278 | final public function resetTeams() { 279 | $this->teams = []; 280 | } 281 | final public function resetWaitingPlayers(){ 282 | $this->waitingPlayers = []; 283 | } 284 | final public function setDescription(string $description) { 285 | $this->description = $description; 286 | } 287 | final public function setIconImage(string $path) { 288 | if (mime_content_type($path) !== 'image/png') throw new \InvalidArgumentException($this->getGameManager()->getMiniGameApi()->getLanguage()->translateString('exception.invalidIconImagePath', [$this->getName()])); 289 | $this->iconImage = $path; 290 | } 291 | final public function setIconItem(Item $item) { 292 | if ($item->getId() == ItemIds::AIR) throw new \InvalidArgumentException($this->getGameManager()->getMiniGameApi()->getLanguage()->translateString('exception.invalidIconItem')); 293 | $this->iconItem = $item; 294 | } 295 | final public function setPrefix(string $prefix) { 296 | $this->prefix = $prefix; 297 | } 298 | final public function setWinner(Team $winner) { 299 | $this->winner = $winner; 300 | } 301 | final public function start() : bool{ 302 | unset($this->remainingWaitTime); 303 | $this->resetTeams(); 304 | $this->assignPlayers(); 305 | if(!$this->isStartable()) { 306 | $this->end(self::END_STARTING_ERROR); 307 | return false; 308 | } 309 | $ev = new MiniGameStartEvent($this); 310 | $this->remainingRunTime = clone $this->getRunningTime(); 311 | $this->getPlugin()->getServer()->getPluginManager()->callEvent($ev); 312 | if(!$this->onStart() or $ev->isCancelled()) { 313 | unset($this->remainingRunTime); 314 | return false; 315 | } 316 | $this->resetWaitingPlayers(); 317 | foreach($this->getTeams() as $team) { 318 | $team->spawn(); 319 | } 320 | $this->remainingRunTime = clone $this->getRunningTime(); 321 | $this->broadcastMessage($this->getMiniGameApi()->getPrefix() . $this->getMiniGameApi()->getLanguage()->translateString('start.started')); 322 | return true; 323 | } 324 | final public function submitTeam(Team $team) { 325 | $this->removeTeam($team->getName()); 326 | $this->teams[] = $team; 327 | return; 328 | } 329 | final public function update(int $updateCycle) { 330 | $this->onUpdate($updateCycle); 331 | if($this->isWaiting()) { 332 | $this->getRemainingWaitTime()->reduceTime($updateCycle); 333 | if ($this->getMiniGameApi()->getConfig()->get('show-left-time') and $this->getRemainingWaitTime()->asSec() <= $this->getMiniGameApi()->getConfig()->get('show-left-time'))$this->broadcastMessage($this->getMiniGameApi()->getPrefix() . $this->getMiniGameApi()->getLanguage()->translateString('left.time',[intval($this->getRemainingWaitTime()->asSec())])); 334 | if($this->getRemainingWaitTime()->asTick() <= 0) { 335 | $this->start(); 336 | return; 337 | } 338 | $this->onWaiting($updateCycle); 339 | } elseif($this->isRunning()) { 340 | $this->getRemainingRunTime()->reduceTime($updateCycle); 341 | if ($this->getMiniGameApi()->getConfig()->get('show-left-time') and $this->getRemainingRunTime()->asSec() <= $this->getMiniGameApi()->getConfig()->get('show-left-time'))$this->broadcastMessage($this->getMiniGameApi()->getPrefix() . $this->getMiniGameApi()->getLanguage()->translateString('left.time',[intval($this->getRemainingRunTime()->asSec())])); 342 | if($this->getRemainingRunTime()->asTick() <= 0) { 343 | $this->end(self::END_TIMEOUT); 344 | return; 345 | } 346 | $this->onRunning($updateCycle); 347 | } 348 | } 349 | final public function wait() { 350 | $this->remainingWaitTime = clone $this->getWaitingTime(); 351 | $this->broadcastMessage($this->getMiniGameApi()->getPrefix() . $this->getMiniGameApi()->getLanguage()->translateString('left.time', [(int)$this->getRemainingWaitTime()->asSec()])); 352 | $this->onWait(); 353 | } 354 | } 355 | --------------------------------------------------------------------------------