Search in sources :

Example 1 with MoneyPerMinuteTask

use of com.andrei1058.bedwars.money.internal.MoneyPerMinuteTask 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)

Example 2 with MoneyPerMinuteTask

use of com.andrei1058.bedwars.money.internal.MoneyPerMinuteTask in project BedWars1058 by andrei1058.

the class Arena method destroyData.

public void destroyData() {
    destroyReJoins();
    if (worldName != null)
        arenaByIdentifier.remove(worldName);
    arenas.remove(this);
    for (ReJoinTask rjt : ReJoinTask.getReJoinTasks()) {
        if (rjt.getArena() == this) {
            rjt.destroy();
        }
    }
    for (Despawnable despawnable : new ArrayList<>(BedWars.nms.getDespawnablesList().values())) {
        if (despawnable.getTeam().getArena() == this) {
            despawnable.destroy();
        }
    }
    arenaByName.remove(arenaName);
    arenaByPlayer.entrySet().removeIf(entry -> entry.getValue() == this);
    players = null;
    spectators = null;
    signs = null;
    yml = null;
    cm = null;
    world = null;
    for (IGenerator og : oreGenerators) {
        og.destroyData();
    }
    isOnABase.entrySet().removeIf(entry -> entry.getValue().getArena().equals(this));
    for (ITeam bwt : teams) {
        bwt.destroyData();
    }
    playerLocation.entrySet().removeIf(e -> Objects.requireNonNull(e.getValue().getWorld()).getName().equalsIgnoreCase(worldName));
    teams = null;
    placed = null;
    nextEvents = null;
    regionsList = null;
    respawnSessions = null;
    showTime = null;
    playerKills = null;
    playerBedsDestroyed = null;
    playerFinalKills = null;
    playerDeaths = null;
    playerFinalKillDeaths = null;
    startingTask = null;
    playingTask = null;
    restartingTask = null;
    oreGenerators = null;
    perMinuteTask = null;
    moneyperMinuteTask = null;
    leaving.clear();
    fireballCooldowns.clear();
}
Also used : ReJoinTask(com.andrei1058.bedwars.arena.tasks.ReJoinTask) Despawnable(com.andrei1058.bedwars.api.entity.Despawnable) IGenerator(com.andrei1058.bedwars.api.arena.generator.IGenerator) ITeam(com.andrei1058.bedwars.api.arena.team.ITeam)

Aggregations

IGenerator (com.andrei1058.bedwars.api.arena.generator.IGenerator)1 ITeam (com.andrei1058.bedwars.api.arena.team.ITeam)1 Despawnable (com.andrei1058.bedwars.api.entity.Despawnable)1 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 ReJoinTask (com.andrei1058.bedwars.arena.tasks.ReJoinTask)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