diff --git a/src/TowerRun.properties b/src/TowerRun.properties index 96fd093..a62684d 100644 --- a/src/TowerRun.properties +++ b/src/TowerRun.properties @@ -30,5 +30,6 @@ SERVER_RESET= KEY_NAME=§eKey KEY_FOUND=§a{0} §7found a key§8! GAME_TIE=§aThe game ended in a tie§8! +GAME_TIME=§a{0}:{1} COMMAND_START=§aThe game will start soon§8! \ No newline at end of file diff --git a/src/de/steamwar/towerrun/TowerRun.java b/src/de/steamwar/towerrun/TowerRun.java index f72eade..eb5969f 100644 --- a/src/de/steamwar/towerrun/TowerRun.java +++ b/src/de/steamwar/towerrun/TowerRun.java @@ -23,6 +23,7 @@ import de.steamwar.message.Message; import de.steamwar.towerrun.commands.StartCommand; import de.steamwar.towerrun.config.WorldConfig; import de.steamwar.towerrun.countdowns.EndCountdown; +import de.steamwar.towerrun.countdowns.GameCountdown; import de.steamwar.towerrun.countdowns.LobbyCountdown; import de.steamwar.towerrun.game.TowerRunGame; import de.steamwar.towerrun.generator.TowerGenerator; @@ -72,6 +73,7 @@ public class TowerRun extends JavaPlugin { final LobbyCountdown lobbyCountdown = new LobbyCountdown(); new EndCountdown(lobbyCountdown); new StartCommand(lobbyCountdown); + new GameCountdown(); TowerRunGame.reset(); } diff --git a/src/de/steamwar/towerrun/config/Config.java b/src/de/steamwar/towerrun/config/Config.java index bbd3138..b77f50e 100644 --- a/src/de/steamwar/towerrun/config/Config.java +++ b/src/de/steamwar/towerrun/config/Config.java @@ -36,6 +36,7 @@ public class Config { public static final int MIN_PLAYERS; public static final int LOBBY_TIMER; public static final Set DESTROYABLE_BLOCKS; + public static final int GAME_TIMER; static { File configFile = new File(TowerRun.getInstance().getDataFolder(), "config.yml"); @@ -48,6 +49,7 @@ public class Config { MIN_PLAYERS = config.getInt("minPlayers"); LOBBY_TIMER = config.getInt("lobbyTimer"); + GAME_TIMER = config.getInt("gameTimer", 20 * 60); DESTROYABLE_BLOCKS = EnumSet.copyOf(config.getStringList("destroyable").stream().map(Material::valueOf).collect(Collectors.toSet())); } diff --git a/src/de/steamwar/towerrun/countdowns/GameCountdown.java b/src/de/steamwar/towerrun/countdowns/GameCountdown.java new file mode 100644 index 0000000..f5d23ef --- /dev/null +++ b/src/de/steamwar/towerrun/countdowns/GameCountdown.java @@ -0,0 +1,61 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.towerrun.countdowns; + +import de.steamwar.towerrun.TowerRun; +import de.steamwar.towerrun.config.Config; +import de.steamwar.towerrun.game.TowerRunGame; +import de.steamwar.towerrun.state.GameStates; + +import java.util.EnumSet; + +public class GameCountdown extends Countdown { + + public GameCountdown() { + super(EnumSet.of(GameStates.INGAME)); + } + + @Override + int defaultTime() { + return Config.GAME_TIMER; + } + + @Override + void timerEnd() { + if (TowerRunGame.PLAYERS_ESCAPED.isEmpty()) { + TowerRunGame.tie(); + } else { + TowerRunGame.win(TowerRunGame.PLAYERS_ESCAPED.get(TowerRunGame.PLAYERS_ESCAPED.size() - 1)); + } + } + + @Override + boolean timerShouldCancel() { + return false; + } + + @Override + void run() { + int timeMinutes = Math.floorDiv(time, 60); + int timeSeconds = time % 60; + + TowerRun.getMessage().broadcastActionbar("GAME_TIME", timeMinutes, timeSeconds); + } +}