forked from SteamWar/SteamWar
Add TowerRun module
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.towerrun.countdowns;
|
||||
|
||||
import de.steamwar.towerrun.TowerRun;
|
||||
import de.steamwar.towerrun.state.GameStateToggleListener;
|
||||
import de.steamwar.towerrun.state.GameStates;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
public abstract class Countdown extends GameStateToggleListener {
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
protected int time = defaultTime();
|
||||
protected BukkitTask task;
|
||||
|
||||
protected Countdown(EnumSet<GameStates> enabledStates) {
|
||||
super(enabledStates);
|
||||
}
|
||||
|
||||
int defaultTime() {
|
||||
return 0;
|
||||
}
|
||||
void timerEnd() {}
|
||||
boolean timerShouldCancel() {
|
||||
return true;
|
||||
}
|
||||
void run() {}
|
||||
void timerStart() {}
|
||||
void timerReset() {}
|
||||
|
||||
private void timer() {
|
||||
if (timerShouldCancel()) {
|
||||
time = defaultTime();
|
||||
timerReset();
|
||||
} else {
|
||||
if (time == defaultTime()) {
|
||||
timerStart();
|
||||
}
|
||||
if (time == 0) {
|
||||
timerEnd();
|
||||
return;
|
||||
}
|
||||
run();
|
||||
time--;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enable() {
|
||||
task = Bukkit.getScheduler().runTaskTimer(TowerRun.getInstance(), this::timer, 0, 20);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disable() {
|
||||
task.cancel();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.towerrun.countdowns;
|
||||
|
||||
import de.steamwar.towerrun.TowerRun;
|
||||
import de.steamwar.towerrun.game.TowerRunGame;
|
||||
import de.steamwar.towerrun.state.GameStates;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Sound;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.Objects;
|
||||
|
||||
public class EndCountdown extends Countdown {
|
||||
|
||||
private final LobbyCountdown lobbyCountdown;
|
||||
|
||||
private static final boolean RESETS = Objects.requireNonNull(Bukkit.getWorlds().get(0).getWorldFolder().list((dir, name) -> name.equals("backup"))).length > 0;
|
||||
|
||||
public EndCountdown(LobbyCountdown lobbyCountdown) {
|
||||
super(EnumSet.of(GameStates.ENDING));
|
||||
this.lobbyCountdown = lobbyCountdown;
|
||||
}
|
||||
|
||||
@Override
|
||||
int defaultTime() {
|
||||
return 10;
|
||||
}
|
||||
|
||||
@Override
|
||||
void timerEnd() {
|
||||
Bukkit.getOnlinePlayers().forEach(player -> player.playSound(player.getLocation(), Sound.BLOCK_NOTE_BLOCK_PLING, 1, 1));
|
||||
if (RESETS) {
|
||||
TowerRunGame.reset();
|
||||
lobbyCountdown.setTime(lobbyCountdown.defaultTime());
|
||||
} else {
|
||||
Bukkit.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean timerShouldCancel() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
void run() {
|
||||
TowerRun.getMessage().broadcastActionbar(RESETS ? "SERVER_RESET" : "SERVER_STOPPING", time);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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", String.format("%02d", timeMinutes), String.format("%02d", timeSeconds));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disable() {
|
||||
super.disable();
|
||||
setTime(defaultTime());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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 lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Sound;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
@Getter
|
||||
public class LobbyCountdown extends Countdown {
|
||||
|
||||
@Setter
|
||||
private boolean override = false;
|
||||
|
||||
public LobbyCountdown() {
|
||||
super(EnumSet.of(GameStates.LOBBY));
|
||||
}
|
||||
|
||||
@Override
|
||||
int defaultTime() {
|
||||
return Config.LOBBY_TIMER;
|
||||
}
|
||||
|
||||
@Override
|
||||
void timerEnd() {
|
||||
TowerRunGame.prepareTowerOrStart();
|
||||
override = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean timerShouldCancel() {
|
||||
return !override && Bukkit.getOnlinePlayers().size() < Config.MIN_PLAYERS;
|
||||
}
|
||||
|
||||
@Override
|
||||
void run() {
|
||||
TowerRun.getMessage().broadcastActionbar("GAME_STARTING", time);
|
||||
if (time < 10) {
|
||||
Bukkit.getOnlinePlayers().forEach(player -> player.playSound(player.getLocation(), Sound.BLOCK_NOTE_BLOCK_PLING, 1, 1));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
void timerReset() {
|
||||
TowerRun.getMessage().broadcastActionbar("GAME_WAITING");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user