Search in sources :

Example 1 with ArenaStartEvent

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

the class PlaysStat method onArenaStart.

/**
 * Handles statistics for games played
 *
 * @param e an event that represents an arena starting
 * @see ArenaStartEvent
 * @since 2.2.0
 */
@EventHandler
public static void onArenaStart(ArenaStartEvent e) {
    StatManager instance = StatManager.getInstance();
    e.getArena().getUsedPlots().stream().flatMap(plot -> plot.getGamePlayers().stream()).forEach(gamePlayer -> {
        var player = gamePlayer.getPlayer();
        var stat = instance.getStat(player, StatType.PLAYS);
        instance.registerStat(player, StatType.PLAYS, stat == null ? 1 : stat.getValue() + 1);
    });
}
Also used : EventHandler(org.bukkit.event.EventHandler) ArenaStartEvent(com.gmail.stefvanschiedev.buildinggame.api.events.ArenaStartEvent) StatManager(com.gmail.stefvanschiedev.buildinggame.managers.stats.StatManager) StatType(com.gmail.stefvanschiedev.buildinggame.utils.stats.StatType) Listener(org.bukkit.event.Listener) StatManager(com.gmail.stefvanschiedev.buildinggame.managers.stats.StatManager) EventHandler(org.bukkit.event.EventHandler)

Example 2 with ArenaStartEvent

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

the class Arena method postStart.

/**
 * Starts a new match. An ArenaStartEvent will be fired once this method is called.
 *
 * @since 2.1.0
 */
private void postStart() {
    YamlConfiguration config = SettingsManager.getInstance().getConfig();
    YamlConfiguration messages = SettingsManager.getInstance().getMessages();
    // call event
    ArenaStartEvent event = new ArenaStartEvent(this);
    Bukkit.getPluginManager().callEvent(event);
    if (event.isCancelled())
        return;
    subject = getSubjectMenu().getHighestVote();
    // update bossbar
    getBossBar().setTitle(MessageManager.translate(messages.getString("global.bossbar-header").replace("%subject%", getSubject())));
    getUsedPlots().forEach(plot -> plot.getGamePlayers().forEach(gamePlayer -> {
        plot.getLocation().teleport(gamePlayer.getPlayer());
        MessageManager.getInstance().send(gamePlayer.getPlayer(), messages.getStringList("gameStarts.message"));
        messages.getStringList("gameStarts.subject").forEach(message -> MessageManager.getInstance().send(gamePlayer.getPlayer(), message.replace("%subject%", getSubject())));
        gamePlayer.addTitleAndSubtitle(messages.getString("gameStarts.title").replace("%subject%", getSubject()), messages.getString("gameStarts.subtitle").replace("%subject%", getSubject()));
        gamePlayer.sendActionbar(messages.getString("gameStarts.actionbar").replace("%subject%", subject));
        final var player = gamePlayer.getPlayer();
        player.getInventory().clear();
        player.setGameMode(GameMode.CREATIVE);
        player.setPlayerTime(plot.getTime(), false);
        // hotbar
        for (int i = 0; i < 9; i++) {
            Material material = SettingsManager.getInstance().getMaterial("hotbar.default.slot-" + (i + 1), Material.AIR);
            player.getInventory().setItem(i, new ItemStack(material));
        }
        // bossbar
        getBossBar().setVisible(true);
        tryGiveOptionsMenu(player);
    }));
    setState(GameState.BUILDING);
    // save blocks
    getPlots().forEach(Plot::save);
    matches++;
    SignManager.getInstance().updateJoinSigns(this);
    buildTimer.runTaskTimer(Main.getInstance(), 20L, 20L);
}
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) ArenaStartEvent(com.gmail.stefvanschiedev.buildinggame.api.events.ArenaStartEvent) Plot(com.gmail.stefvanschiedev.buildinggame.utils.plot.Plot) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) ItemStack(org.bukkit.inventory.ItemStack)

Aggregations

ArenaStartEvent (com.gmail.stefvanschiedev.buildinggame.api.events.ArenaStartEvent)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 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 StatManager (com.gmail.stefvanschiedev.buildinggame.managers.stats.StatManager)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