use of com.andrei1058.bedwars.arena.tasks.GameRestartingTask in project BedWars1058 by andrei1058.
the class Arena method changeStatus.
/**
* Change game status starting tasks.
*/
public void changeStatus(GameState status) {
this.status = status;
Bukkit.getPluginManager().callEvent(new GameStateChangeEvent(this, status, status));
refreshSigns();
if (status == GameState.playing) {
for (Player p : players) {
Arena.afkCheck.remove(p.getUniqueId());
BedWars.getAPI().getAFKUtil().setPlayerAFK(p, false);
}
for (Player p : spectators) {
Arena.afkCheck.remove(p.getUniqueId());
BedWars.getAPI().getAFKUtil().setPlayerAFK(p, false);
}
}
// Stop active tasks to prevent issues
BukkitScheduler bs = Bukkit.getScheduler();
if (startingTask != null) {
if (bs.isCurrentlyRunning(startingTask.getTask()) || bs.isQueued(startingTask.getTask()))
startingTask.cancel();
}
startingTask = null;
if (playingTask != null) {
if (bs.isCurrentlyRunning(playingTask.getTask()) || bs.isQueued(playingTask.getTask()))
playingTask.cancel();
}
playingTask = null;
if (restartingTask != null) {
if (bs.isCurrentlyRunning(restartingTask.getTask()) || bs.isQueued(restartingTask.getTask()))
restartingTask.cancel();
}
restartingTask = null;
players.forEach(c -> BedWarsScoreboard.giveScoreboard(c, this, false));
spectators.forEach(c -> BedWarsScoreboard.giveScoreboard(c, this, false));
if (status == GameState.starting) {
startingTask = new GameStartingTask(this);
} else if (status == GameState.playing) {
if (BedWars.getLevelSupport() instanceof InternalLevel) {
perMinuteTask = new PerMinuteTask(this);
}
if (BedWars.getEconomy() instanceof WithEconomy) {
moneyperMinuteTask = new MoneyPerMinuteTask(this);
}
playingTask = new GamePlayingTask(this);
} else if (status == GameState.restarting) {
restartingTask = new GameRestartingTask(this);
if (perMinuteTask != null) {
perMinuteTask.cancel();
}
if (moneyperMinuteTask != null) {
moneyperMinuteTask.cancel();
}
}
}
Aggregations