use of com.gmail.stefvanschiedev.buildinggame.timers.utils.Timer 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);
}
Aggregations