Search in sources :

Example 1 with WinTimer

use of com.gmail.stefvanschiedev.buildinggame.timers.WinTimer in project buildinggame by stefvanschie.

the class Arena method nextMatch.

/**
 * Moves on to the next match or stops the game if all matches have been played. This won't cancel any timers, and
 * if called incorrectly this will mess with the arena resulting in incorrect behaviour.
 *
 * @since 4.0.6
 */
public void nextMatch() {
    YamlConfiguration arenas = SettingsManager.getInstance().getArenas();
    setState(GameState.WAITING);
    this.lobbyTimer = new LobbyTimer(arenas.getInt(name + ".lobby-timer"), this);
    this.buildTimer = new BuildTimer(arenas.getInt(name + ".timer"), this);
    this.voteTimer = new VoteTimer(arenas.getInt(name + ".vote-timer"), this);
    this.winTimer = new WinTimer(arenas.getInt(name + ".win-timer"), this);
    voteScoreboards.replaceAll((plot, voteScoreboard) -> new VoteScoreboard(this));
    subject = null;
    setFirstPlot(null);
    setSecondPlot(null);
    setThirdPlot(null);
    getVotedPlots().clear();
    getUsedPlots().forEach(plot -> {
        plot.getTimesVoted().clear();
        plot.getVotes().clear();
        plot.getAllGamePlayers().forEach(gamePlayer -> {
            var player = gamePlayer.getPlayer();
            player.setPlayerTime(player.getWorld().getFullTime(), true);
            player.resetPlayerWeather();
        });
    });
    getPlots().forEach(plot -> {
        plot.restore();
        var entities = plot.getEntities();
        entities.keySet().forEach(Entity::remove);
        entities.clear();
    });
    subjectMenu = new SubjectMenu();
    SignManager.getInstance().updateJoinSigns(this);
    if (matches == maxMatches)
        stop();
    else
        postStart();
}
Also used : Entity(org.bukkit.entity.Entity) WinTimer(com.gmail.stefvanschiedev.buildinggame.timers.WinTimer) LobbyTimer(com.gmail.stefvanschiedev.buildinggame.timers.LobbyTimer) VoteTimer(com.gmail.stefvanschiedev.buildinggame.timers.VoteTimer) SubjectMenu(com.gmail.stefvanschiedev.buildinggame.utils.guis.SubjectMenu) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) BuildTimer(com.gmail.stefvanschiedev.buildinggame.timers.BuildTimer)

Example 2 with WinTimer

use of com.gmail.stefvanschiedev.buildinggame.timers.WinTimer in project buildinggame by stefvanschie.

the class Arena method leave.

/**
 * Leaves the specified player. This will send messages to the player, restore their inventory, exp, armor etc.,
 * reset their time and weather to the one by the server, will make all invisible players visible again, cancel
 * timers if needed, updates the join signs for this arena and will leave the plot for the player. An
 * ArenaLeaveEvert may fire once this method is called.
 *
 * @param player the player to leave
 * @since 2.1.0
 */
public void leave(Player player) {
    YamlConfiguration arenas = SettingsManager.getInstance().getArenas();
    YamlConfiguration config = SettingsManager.getInstance().getConfig();
    YamlConfiguration messages = SettingsManager.getInstance().getMessages();
    if (ArenaManager.getInstance().getArena(player) == null) {
        MessageManager.getInstance().send(player, ChatColor.RED + "You're not in a game");
        return;
    }
    // call event
    ArenaLeaveEvent event = new ArenaLeaveEvent(this, player);
    Bukkit.getPluginManager().callEvent(event);
    if (event.isCancelled())
        return;
    var plot = getPlot(player);
    // this shouldn't happen unless you screwed up with the api
    if (plot == null) {
        MessageManager.getInstance().send(player, "You're not in a game");
        ArenaManager.getInstance().getArena(player).leave(player);
        return;
    }
    GamePlayer p = plot.getGamePlayer(player);
    p.restore();
    if (MainSpawnManager.getInstance().getMainSpawn() != null)
        p.connect(MainSpawnManager.getInstance().getServer(), MainSpawnManager.getInstance().getMainSpawn());
    if (config.getBoolean("scoreboards.main.enable"))
        MainScoreboardManager.getInstance().register(player);
    player.resetPlayerTime();
    player.resetPlayerWeather();
    // show all players again
    Bukkit.getOnlinePlayers().forEach(pl -> player.showPlayer(Main.getInstance(), pl));
    // reset player display name of removed player
    getPlots().forEach(pl -> {
        getLobbyScoreboard(pl).getRedTeam().removeEntry(player.getName());
        getBuildScoreboard(pl).getRedTeam().removeEntry(player.getName());
        getVoteScoreboard(pl).getRedTeam().removeEntry(player.getName());
        getWinScoreboard(pl).getRedTeam().removeEntry(player.getName());
    });
    getUsedPlots().forEach(usedPlot -> {
        for (GamePlayer gamePlayer : usedPlot.getGamePlayers()) {
            Player pl = gamePlayer.getPlayer();
            if (pl.equals(player)) {
                usedPlot.leave(gamePlayer);
                if (state == GameState.WAITING)
                    MessageManager.getInstance().send(player, messages.getStringList("leave.message.lobby"));
                else
                    MessageManager.getInstance().send(player, messages.getStringList("leave.message.in-game"));
                break;
            }
        }
    });
    getUsedPlots().forEach(usedPlot -> usedPlot.getGamePlayers().forEach(gamePlayer -> {
        Player pl = gamePlayer.getPlayer();
        if (state == GameState.WAITING)
            messages.getStringList("leave.other-players.lobby").forEach(message -> MessageManager.getInstance().send(pl, message.replace("%player%", player.getName())));
        else
            messages.getStringList("leave.other-players.in-game").forEach(message -> MessageManager.getInstance().send(pl, message.replace("%player%", player.getName())));
        if (config.getBoolean("scoreboards.lobby.enable"))
            getLobbyScoreboard(usedPlot).show(pl);
    }));
    // cancel wait timer when user amount drops below minimum
    if (getPlayers() < minPlayers && lobbyTimer.isActive()) {
        lobbyTimer.cancel();
        setLobbyTimer(new LobbyTimer(arenas.getInt(name + ".lobby-timer"), this));
    }
    if (getPlayers() <= 1) {
        if (getLobbyTimer().isActive()) {
            lobbyTimer.cancel();
            setLobbyTimer(new LobbyTimer(arenas.getInt(name + ".lobby-timer"), this));
            setState(GameState.WAITING);
        }
        if (buildTimer.isActive()) {
            buildTimer.cancel();
            setBuildTimer(new BuildTimer(arenas.getInt(name + ".timer"), this));
            forceStop();
        }
        if (getVoteTimer().isActive()) {
            voteTimer.cancel();
            setVoteTimer(new VoteTimer(arenas.getInt(name + ".vote-timer"), this));
            forceStop();
        }
        if (getWinTimer().isActive()) {
            winTimer.cancel();
            setWinTimer(new WinTimer(arenas.getInt(name + ".win-timer"), this));
            forceStop();
        }
    }
    if (getBossBar().getPlayers().contains(player))
        getBossBar().removePlayer(player);
    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) WinTimer(com.gmail.stefvanschiedev.buildinggame.timers.WinTimer) LobbyTimer(com.gmail.stefvanschiedev.buildinggame.timers.LobbyTimer) GamePlayer(com.gmail.stefvanschiedev.buildinggame.utils.gameplayer.GamePlayer) VoteTimer(com.gmail.stefvanschiedev.buildinggame.timers.VoteTimer) ArenaLeaveEvent(com.gmail.stefvanschiedev.buildinggame.api.events.ArenaLeaveEvent) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) BuildTimer(com.gmail.stefvanschiedev.buildinggame.timers.BuildTimer)

Example 3 with WinTimer

use of com.gmail.stefvanschiedev.buildinggame.timers.WinTimer in project buildinggame by stefvanschie.

the class WinTimerManager method setup.

/**
 * Loads/Reloads all win timers for all arenas
 *
 * @since 2.3.0
 */
@SuppressWarnings("MethodMayBeStatic")
public void setup() {
    YamlConfiguration arenas = SettingsManager.getInstance().getArenas();
    YamlConfiguration config = SettingsManager.getInstance().getConfig();
    ArenaManager.getInstance().getArenas().forEach(arena -> {
        String name = arena.getName();
        if (!arenas.contains(name + ".win-timer"))
            arenas.set(name + ".win-timer", config.getInt("timers.win"));
        arena.setWinTimer(new WinTimer(arenas.getInt(name + ".win-timer"), arena));
    });
}
Also used : WinTimer(com.gmail.stefvanschiedev.buildinggame.timers.WinTimer) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration)

Aggregations

WinTimer (com.gmail.stefvanschiedev.buildinggame.timers.WinTimer)3 YamlConfiguration (org.bukkit.configuration.file.YamlConfiguration)3 BuildTimer (com.gmail.stefvanschiedev.buildinggame.timers.BuildTimer)2 LobbyTimer (com.gmail.stefvanschiedev.buildinggame.timers.LobbyTimer)2 VoteTimer (com.gmail.stefvanschiedev.buildinggame.timers.VoteTimer)2 SubjectMenu (com.gmail.stefvanschiedev.buildinggame.utils.guis.SubjectMenu)2 Entity (org.bukkit.entity.Entity)2 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 Timer (com.gmail.stefvanschiedev.buildinggame.timers.utils.Timer)1 com.gmail.stefvanschiedev.buildinggame.utils (com.gmail.stefvanschiedev.buildinggame.utils)1