Search in sources :

Example 1 with GameRestartingTask

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();
        }
    }
}
Also used : MoneyPerMinuteTask(com.andrei1058.bedwars.money.internal.MoneyPerMinuteTask) Player(org.bukkit.entity.Player) BukkitScheduler(org.bukkit.scheduler.BukkitScheduler) GameStartingTask(com.andrei1058.bedwars.arena.tasks.GameStartingTask) InternalLevel(com.andrei1058.bedwars.levels.internal.InternalLevel) WithEconomy(com.andrei1058.bedwars.support.vault.WithEconomy) GamePlayingTask(com.andrei1058.bedwars.arena.tasks.GamePlayingTask) GameStateChangeEvent(com.andrei1058.bedwars.api.events.gameplay.GameStateChangeEvent) PerMinuteTask(com.andrei1058.bedwars.levels.internal.PerMinuteTask) MoneyPerMinuteTask(com.andrei1058.bedwars.money.internal.MoneyPerMinuteTask) GameRestartingTask(com.andrei1058.bedwars.arena.tasks.GameRestartingTask)

Aggregations

GameStateChangeEvent (com.andrei1058.bedwars.api.events.gameplay.GameStateChangeEvent)1 GamePlayingTask (com.andrei1058.bedwars.arena.tasks.GamePlayingTask)1 GameRestartingTask (com.andrei1058.bedwars.arena.tasks.GameRestartingTask)1 GameStartingTask (com.andrei1058.bedwars.arena.tasks.GameStartingTask)1 InternalLevel (com.andrei1058.bedwars.levels.internal.InternalLevel)1 PerMinuteTask (com.andrei1058.bedwars.levels.internal.PerMinuteTask)1 MoneyPerMinuteTask (com.andrei1058.bedwars.money.internal.MoneyPerMinuteTask)1 WithEconomy (com.andrei1058.bedwars.support.vault.WithEconomy)1 Player (org.bukkit.entity.Player)1 BukkitScheduler (org.bukkit.scheduler.BukkitScheduler)1