forked from SteamWar/SteamWar
Migrate FightSystem modes and countdowns to GameCore
- Move shared arena-mode abstractions into GameCore - Adapt fight countdowns and APIs to the shared model - Add SteamWar issue audit workflow and SQL language settings
This commit is contained in:
@@ -23,18 +23,14 @@ 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;
|
||||
private de.steamwar.gamecore.countdown.Countdown countdown;
|
||||
|
||||
protected Countdown(EnumSet<GameStates> enabledStates) {
|
||||
super(enabledStates);
|
||||
@@ -60,30 +56,48 @@ public abstract class Countdown extends GameStateToggleListener {
|
||||
void timerReset() {
|
||||
}
|
||||
|
||||
private void timer() {
|
||||
if (timerShouldCancel()) {
|
||||
time = defaultTime();
|
||||
timerReset();
|
||||
} else {
|
||||
if (time == defaultTime()) {
|
||||
timerStart();
|
||||
}
|
||||
if (time == 0) {
|
||||
timerEnd();
|
||||
return;
|
||||
}
|
||||
run();
|
||||
time--;
|
||||
public void setTime(int time) {
|
||||
this.time = time;
|
||||
if (countdown != null) {
|
||||
countdown.setRemainingTime(time + 1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enable() {
|
||||
task = Bukkit.getScheduler().runTaskTimer(TowerRun.getInstance(), this::timer, 0, 20);
|
||||
countdown = new de.steamwar.gamecore.countdown.Countdown(
|
||||
TowerRun.getInstance(), defaultTime() + 1, 0, 20, false
|
||||
) {
|
||||
@Override
|
||||
protected void onTick(int remaining) {
|
||||
time = remaining;
|
||||
if (timerShouldCancel()) {
|
||||
reset();
|
||||
time = defaultTime();
|
||||
timerReset();
|
||||
return;
|
||||
}
|
||||
if (time == defaultTime()) {
|
||||
timerStart();
|
||||
}
|
||||
if (time > 0) {
|
||||
run();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onFinished() {
|
||||
timerEnd();
|
||||
}
|
||||
};
|
||||
countdown.enable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disable() {
|
||||
task.cancel();
|
||||
if (countdown != null) {
|
||||
countdown.disable();
|
||||
countdown = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user