use of com.gmail.stefvanschiedev.buildinggame.utils.gameplayer.GamePlayer 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.utils.gameplayer.GamePlayer in project buildinggame by stefvanschie.
the class Arena method stop.
/**
* Stops the arena and resets it so it's open for new players. If you want to stop the arena while it's still
* running use {@link #forceStop()}.
*
* @since 2.1.0
*/
public void stop() {
YamlConfiguration config = SettingsManager.getInstance().getConfig();
YamlConfiguration messages = SettingsManager.getInstance().getMessages();
// call event
ArenaStopEvent event = new ArenaStopEvent(this);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled())
return;
getUsedPlots().stream().flatMap(plot -> plot.getAllGamePlayers().stream()).forEach(gamePlayer -> gamePlayer.connect(MainSpawnManager.getInstance().getServer(), MainSpawnManager.getInstance().getMainSpawn()));
// update bossbar
getBossBar().setTitle(MessageManager.translate(messages.getString("global.bossbar-header").replace("%subject%", "?")));
getBossBar().setVisible(false);
getBossBar().getPlayers().forEach(player -> getBossBar().removePlayer(player));
getUsedPlots().stream().flatMap(plot -> plot.getAllGamePlayers().stream()).forEach(gamePlayer -> {
Player player = gamePlayer.getPlayer();
gamePlayer.restore();
player.setScoreboard(Bukkit.getScoreboardManager().getNewScoreboard());
// show all players again
if (config.getBoolean("tab-list.adjust"))
Bukkit.getOnlinePlayers().forEach(pl -> player.showPlayer(Main.getInstance(), pl));
// reset scoreboard
getUsedPlots().stream().flatMap(p -> p.getGamePlayers().stream()).forEach(gp -> gp.getPlayer().setScoreboard(Bukkit.getScoreboardManager().getNewScoreboard()));
});
getPlots().forEach(plot -> plot.getAllGamePlayers().clear());
this.matches = 0;
SignManager.getInstance().updateJoinSigns(this);
}
use of com.gmail.stefvanschiedev.buildinggame.utils.gameplayer.GamePlayer in project buildinggame by stefvanschie.
the class Plot method getPlayerFormat.
/**
* Returns a formatted string containing all players' name
*
* @return a formatted string of players
* @since 2.1.0
*/
@NotNull
@Contract(pure = true)
public String getPlayerFormat() {
YamlConfiguration messages = SettingsManager.getInstance().getMessages();
StringBuilder players = new StringBuilder();
for (var i = 0; i < getGamePlayers().size(); i++) {
GamePlayer player = getGamePlayers().get(i);
if (i == getGamePlayers().size() - 1)
players.append(player.getPlayer().getName());
else if (i == getGamePlayers().size() - 2)
players.append(player.getPlayer().getName()).append(messages.getString("global.combine-names"));
else
players.append(player.getPlayer().getName()).append(", ");
}
return players.toString();
}
use of com.gmail.stefvanschiedev.buildinggame.utils.gameplayer.GamePlayer in project buildinggame by stefvanschie.
the class Plot method restore.
/**
* Restores the previous state of this plot which includes its block states and data, its time, rain state and
* particles
*
* @since 2.1.0
*/
public void restore() {
if (!SettingsManager.getInstance().getConfig().getBoolean("restore-plots"))
return;
blocks.forEach((blockState, biome) -> {
Block block = blockState.getLocation().getBlock();
block.setType(blockState.getType());
block.setBiome(biome);
});
// refresh chunks because of the biomes
arena.getPlots().forEach(plot -> plot.getBoundary().getChunks().forEach(chunk -> gamePlayers.forEach(gamePlayer -> gamePlayer.refreshChunk(chunk))));
setRaining(false);
setTime(0);
getParticles().clear();
}
use of com.gmail.stefvanschiedev.buildinggame.utils.gameplayer.GamePlayer in project buildinggame by stefvanschie.
the class CommandManager method onSpectate.
/**
* Called whenever a player wants to spectate
*
* @param player the player
* @param toSpectate the player to spectate
* @since 5.8.0
*/
@Subcommand("spectate")
@Description("Spectate a player")
@CommandPermission("bg.spectate")
public void onSpectate(Player player, Player toSpectate) {
var arena = ArenaManager.getInstance().getArena(toSpectate);
if (arena == null) {
MessageManager.getInstance().send(player, ChatColor.RED + "Arena not found");
return;
}
if (arena.getState() != GameState.BUILDING) {
MessageManager.getInstance().send(player, ChatColor.RED + "You can't spectate right now");
return;
}
GamePlayer toSpectateGamePlayer = arena.getUsedPlots().stream().flatMap(plot -> plot.getAllGamePlayers().stream()).filter(gamePlayer -> gamePlayer.getPlayer().equals(toSpectate)).findAny().orElse(null);
if (toSpectateGamePlayer == null) {
MessageManager.getInstance().send(player, ChatColor.RED + "Couldn't find the player to spectate");
return;
}
if (toSpectateGamePlayer.getGamePlayerType() == GamePlayerType.SPECTATOR) {
MessageManager.getInstance().send(player, ChatColor.RED + "You can't spectate a spectator");
return;
}
// check if the player is playing the game
if (ArenaManager.getInstance().getArena(player) != null && ArenaManager.getInstance().getArena(player).getPlot(player).getGamePlayer(player).getGamePlayerType() == GamePlayerType.PLAYER) {
MessageManager.getInstance().send(player, ChatColor.RED + "You can't spectate while you're in game");
return;
}
// check if we are already spectating
Plot spectating = null;
for (Arena a : ArenaManager.getInstance().getArenas()) {
for (Plot plot : a.getUsedPlots()) {
for (GamePlayer gamePlayer : plot.getSpectators()) {
if (gamePlayer.getPlayer().equals(player)) {
spectating = plot;
break;
}
}
}
}
if (spectating != null)
spectating.removeSpectator(spectating.getGamePlayer(player));
arena.getPlot(toSpectateGamePlayer.getPlayer()).addSpectator(player, toSpectateGamePlayer);
MessageManager.getInstance().send(player, ChatColor.GREEN + "Now spectating " + toSpectateGamePlayer.getPlayer().getName() + '!');
}
Aggregations