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);
});
}
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);
}
Aggregations