use of com.gmail.stefvanschiedev.buildinggame.timers.VoteTimer 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();
}
use of com.gmail.stefvanschiedev.buildinggame.timers.VoteTimer 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);
}
use of com.gmail.stefvanschiedev.buildinggame.timers.VoteTimer in project buildinggame by stefvanschie.
the class VoteTimerManager method setup.
/**
* Loads/Reloads all vote 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 + ".vote-timer"))
arenas.set(name + ".vote-timer", config.getInt("timers.vote"));
arena.setVoteTimer(new VoteTimer(arenas.getInt(name + ".vote-timer"), arena));
});
}
Aggregations