Search in sources :

Example 1 with ArenaStopEvent

use of com.gmail.stefvanschiedev.buildinggame.api.events.ArenaStopEvent in project buildinggame by stefvanschie.

the class Arena method stop.

/**
 * Stops the arena and resets it so it's open for new players. If you want to stop the arena while it's still
 * running use {@link #forceStop()}.
 *
 * @since 2.1.0
 */
public void stop() {
    YamlConfiguration config = SettingsManager.getInstance().getConfig();
    YamlConfiguration messages = SettingsManager.getInstance().getMessages();
    // call event
    ArenaStopEvent event = new ArenaStopEvent(this);
    Bukkit.getPluginManager().callEvent(event);
    if (event.isCancelled())
        return;
    getUsedPlots().stream().flatMap(plot -> plot.getAllGamePlayers().stream()).forEach(gamePlayer -> gamePlayer.connect(MainSpawnManager.getInstance().getServer(), MainSpawnManager.getInstance().getMainSpawn()));
    // update bossbar
    getBossBar().setTitle(MessageManager.translate(messages.getString("global.bossbar-header").replace("%subject%", "?")));
    getBossBar().setVisible(false);
    getBossBar().getPlayers().forEach(player -> getBossBar().removePlayer(player));
    getUsedPlots().stream().flatMap(plot -> plot.getAllGamePlayers().stream()).forEach(gamePlayer -> {
        Player player = gamePlayer.getPlayer();
        gamePlayer.restore();
        player.setScoreboard(Bukkit.getScoreboardManager().getNewScoreboard());
        // show all players again
        if (config.getBoolean("tab-list.adjust"))
            Bukkit.getOnlinePlayers().forEach(pl -> player.showPlayer(Main.getInstance(), pl));
        // reset scoreboard
        getUsedPlots().stream().flatMap(p -> p.getGamePlayers().stream()).forEach(gp -> gp.getPlayer().setScoreboard(Bukkit.getScoreboardManager().getNewScoreboard()));
    });
    getPlots().forEach(plot -> plot.getAllGamePlayers().clear());
    this.matches = 0;
    SignManager.getInstance().updateJoinSigns(this);
}
Also used : java.util(java.util) ZonedDateTime(java.time.ZonedDateTime) LocalDateTime(java.time.LocalDateTime) Player(org.bukkit.entity.Player) LobbyTimer(com.gmail.stefvanschiedev.buildinggame.timers.LobbyTimer) org.bukkit(org.bukkit) BuildTimer(com.gmail.stefvanschiedev.buildinggame.timers.BuildTimer) ArenaLeaveEvent(com.gmail.stefvanschiedev.buildinggame.api.events.ArenaLeaveEvent) BarColor(org.bukkit.boss.BarColor) com.gmail.stefvanschiedev.buildinggame.utils(com.gmail.stefvanschiedev.buildinggame.utils) Main(com.gmail.stefvanschiedev.buildinggame.Main) Timer(com.gmail.stefvanschiedev.buildinggame.timers.utils.Timer) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) BarStyle(org.bukkit.boss.BarStyle) VoteTimer(com.gmail.stefvanschiedev.buildinggame.timers.VoteTimer) GamePlayerType(com.gmail.stefvanschiedev.buildinggame.utils.gameplayer.GamePlayerType) Attribute(org.bukkit.attribute.Attribute) ArenaStartEvent(com.gmail.stefvanschiedev.buildinggame.api.events.ArenaStartEvent) ArenaStopEvent(com.gmail.stefvanschiedev.buildinggame.api.events.ArenaStopEvent) Entity(org.bukkit.entity.Entity) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) PotentialLocation(com.gmail.stefvanschiedev.buildinggame.utils.potential.PotentialLocation) GamePlayer(com.gmail.stefvanschiedev.buildinggame.utils.gameplayer.GamePlayer) MessageManager(com.gmail.stefvanschiedev.buildinggame.managers.messages.MessageManager) com.gmail.stefvanschiedev.buildinggame.utils.scoreboards(com.gmail.stefvanschiedev.buildinggame.utils.scoreboards) SettingsManager(com.gmail.stefvanschiedev.buildinggame.managers.files.SettingsManager) SubjectMenu(com.gmail.stefvanschiedev.buildinggame.utils.guis.SubjectMenu) Plot(com.gmail.stefvanschiedev.buildinggame.utils.plot.Plot) Collectors(java.util.stream.Collectors) File(java.io.File) ItemStack(org.bukkit.inventory.ItemStack) TeamSelection(com.gmail.stefvanschiedev.buildinggame.utils.guis.TeamSelection) MainScoreboardManager(com.gmail.stefvanschiedev.buildinggame.managers.scoreboards.MainScoreboardManager) Nullable(org.jetbrains.annotations.Nullable) Contract(org.jetbrains.annotations.Contract) BossBar(org.bukkit.boss.BossBar) Region(com.gmail.stefvanschiedev.buildinggame.utils.region.Region) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) DateTimeFormatter(java.time.format.DateTimeFormatter) SignManager(com.gmail.stefvanschiedev.buildinggame.managers.arenas.SignManager) When(com.gmail.stefvanschiedev.buildinggame.utils.guis.SubjectMenu.When) PotentialBlockPosition(com.gmail.stefvanschiedev.buildinggame.utils.potential.PotentialBlockPosition) NotNull(org.jetbrains.annotations.NotNull) ArenaManager(com.gmail.stefvanschiedev.buildinggame.managers.arenas.ArenaManager) MainSpawnManager(com.gmail.stefvanschiedev.buildinggame.managers.mainspawn.MainSpawnManager) ArenaJoinEvent(com.gmail.stefvanschiedev.buildinggame.api.events.ArenaJoinEvent) WinTimer(com.gmail.stefvanschiedev.buildinggame.timers.WinTimer) Player(org.bukkit.entity.Player) GamePlayer(com.gmail.stefvanschiedev.buildinggame.utils.gameplayer.GamePlayer) ArenaStopEvent(com.gmail.stefvanschiedev.buildinggame.api.events.ArenaStopEvent) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration)

Aggregations

Main (com.gmail.stefvanschiedev.buildinggame.Main)1 ArenaJoinEvent (com.gmail.stefvanschiedev.buildinggame.api.events.ArenaJoinEvent)1 ArenaLeaveEvent (com.gmail.stefvanschiedev.buildinggame.api.events.ArenaLeaveEvent)1 ArenaStartEvent (com.gmail.stefvanschiedev.buildinggame.api.events.ArenaStartEvent)1 ArenaStopEvent (com.gmail.stefvanschiedev.buildinggame.api.events.ArenaStopEvent)1 ArenaManager (com.gmail.stefvanschiedev.buildinggame.managers.arenas.ArenaManager)1 SignManager (com.gmail.stefvanschiedev.buildinggame.managers.arenas.SignManager)1 SettingsManager (com.gmail.stefvanschiedev.buildinggame.managers.files.SettingsManager)1 MainSpawnManager (com.gmail.stefvanschiedev.buildinggame.managers.mainspawn.MainSpawnManager)1 MessageManager (com.gmail.stefvanschiedev.buildinggame.managers.messages.MessageManager)1 MainScoreboardManager (com.gmail.stefvanschiedev.buildinggame.managers.scoreboards.MainScoreboardManager)1 BuildTimer (com.gmail.stefvanschiedev.buildinggame.timers.BuildTimer)1 LobbyTimer (com.gmail.stefvanschiedev.buildinggame.timers.LobbyTimer)1 VoteTimer (com.gmail.stefvanschiedev.buildinggame.timers.VoteTimer)1 WinTimer (com.gmail.stefvanschiedev.buildinggame.timers.WinTimer)1 Timer (com.gmail.stefvanschiedev.buildinggame.timers.utils.Timer)1 com.gmail.stefvanschiedev.buildinggame.utils (com.gmail.stefvanschiedev.buildinggame.utils)1 GamePlayer (com.gmail.stefvanschiedev.buildinggame.utils.gameplayer.GamePlayer)1 GamePlayerType (com.gmail.stefvanschiedev.buildinggame.utils.gameplayer.GamePlayerType)1 SubjectMenu (com.gmail.stefvanschiedev.buildinggame.utils.guis.SubjectMenu)1