Skip to content

Commit

Permalink
feat: add new placeholders, closes #150
Browse files Browse the repository at this point in the history
`%bedwars_game_<game>_running%` - returns true/false
`%bedwars_game_<game>_waiting%` - returns true/false
`%bedwars_current_game_running%` - returns true/false
`%bedwars_current_game_waiting%` - returns true/false
`%bedwars_all_games_anyrunning%` - returns true/false
`%bedwars_all_games_anywaiting%` - returns true/false
  • Loading branch information
Misat11 committed Jun 21, 2024
1 parent ccdea59 commit ad454f5
Showing 1 changed file with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.screamingsandals.bedwars.Main;
import org.screamingsandals.bedwars.api.game.GameStatus;
import org.screamingsandals.bedwars.api.statistics.PlayerStatistic;
import org.screamingsandals.bedwars.game.CurrentTeam;
import org.screamingsandals.bedwars.game.Game;
Expand Down Expand Up @@ -168,6 +169,10 @@ public String onPlaceholderRequest(Player player, String identifier) {
return game.getWorld().getName();
case "state":
return game.getStatus().name().toLowerCase();
case "running":
return game.getStatus() == GameStatus.RUNNING || game.getStatus() == GameStatus.GAME_END_CELEBRATING ? "true" : "false";
case "waiting":
return game.getStatus() == GameStatus.WAITING ? "true" : "false";
case "aviable_teams": // Wow, you found an easter egg
case "available_teams":
return Integer.toString(game.countAvailableTeams());
Expand All @@ -186,6 +191,10 @@ public String onPlaceholderRequest(Player player, String identifier) {
return Integer.toString(Main.getGameNames().stream().map(Main::getGame).mapToInt(Game::countConnectedPlayers).sum());
case "maxplayers":
return Integer.toString(Main.getGameNames().stream().map(Main::getGame).mapToInt(Game::getMaxPlayers).sum());
case "anyrunning":
return Main.getGameNames().stream().map(Main::getGame).anyMatch(game -> game.getStatus() == GameStatus.RUNNING || game.getStatus() == GameStatus.GAME_END_CELEBRATING) ? "true" : "false";
case "anywaiting":
return Main.getGameNames().stream().map(Main::getGame).anyMatch(game -> game.getStatus() == GameStatus.WAITING) ? "true" : "false";
}
}

Expand Down Expand Up @@ -376,6 +385,19 @@ public String onPlaceholderRequest(Player player, String identifier) {
} else {
return "none";
}
case "game_running":
if (Main.isPlayerInGame(player)) {
Game game = Main.getPlayerGameProfile(player).getGame();
return game.getStatus() == GameStatus.RUNNING || game.getStatus() == GameStatus.GAME_END_CELEBRATING ? "true" : "false";
} else {
return "false";
}
case "game_waiting":
if (Main.isPlayerInGame(player)) {
return Main.getPlayerGameProfile(player).getGame().getStatus() == GameStatus.WAITING ? "true" : "false";
} else {
return "false";
}
case "aviable_teams": // Wow, you found an easter egg
case "available_teams":
if (Main.isPlayerInGame(player)) {
Expand Down

0 comments on commit ad454f5

Please sign in to comment.