Skip to content

Commit

Permalink
feat: new placeholders
Browse files Browse the repository at this point in the history
%bedwars_game_<game name>_timeformat%
%bedwars_game_<game name>_elapsedtime%
%bedwars_game_<game name>_elapsedtimeformat%
%bedwars_current_game_timeformat%
%bedwars_current_game_elapsedtime%
%bedwars_current_game_elapsedtimeformat%
%bedwars_current_game_team_<team name>_colored%
%bedwars_current_game_team_<team name>_color%
%bedwars_current_game_team_<team name>_ingame%
%bedwars_current_game_team_<team name>_players%
%bedwars_current_game_team_<team name>_maxplayers%
%bedwars_current_game_team_<team name>_bed%
%bedwars_current_game_team_<team name>_bedsymbol%
%bedwars_current_game_team_<team name>_teamchests%
  • Loading branch information
Misat11 committed Apr 6, 2024
1 parent e754068 commit 5aa2dbb
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2631,7 +2631,7 @@ public String getFormattedTimeLeft() {
return getFormattedTimeLeft(this.countdown);
}

public String getFormattedTimeLeft(int countdown) {
public static String getFormattedTimeLeft(int countdown) {
int min;
int sec;
String minStr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,32 @@ public String onPlaceholderRequest(Player player, String identifier) {
return Integer.toString(game.getMinPlayers());
case "time":
return Integer.toString(game.getCountdown());
case "timeformat":
return Game.getFormattedTimeLeft(game.getCountdown());
case "elapsedtime":
switch (game.getStatus()) {
case WAITING:
return Integer.toString(game.getLobbyCountdown() - game.getCountdown());
case RUNNING:
return Integer.toString(game.getGameTime() - game.getCountdown());
case GAME_END_CELEBRATING:
return Integer.toString(game.getPostGameWaiting() - game.getCountdown());
case REBUILDING:
case DISABLED:
return "0";
}
case "elapsedtimeformat":
switch (game.getStatus()) {
case WAITING:
return Game.getFormattedTimeLeft(game.getLobbyCountdown() - game.getCountdown());
case RUNNING:
return Game.getFormattedTimeLeft(game.getGameTime() - game.getCountdown());
case GAME_END_CELEBRATING:
return Game.getFormattedTimeLeft(game.getPostGameWaiting() - game.getCountdown());
case REBUILDING:
case DISABLED:
return Game.getFormattedTimeLeft(0);
}
case "world":
return game.getWorld().getName();
case "state":
Expand Down Expand Up @@ -210,6 +236,66 @@ public String onPlaceholderRequest(Player player, String identifier) {
}

if (identifier.startsWith("current_")) {
if (identifier.toLowerCase(Locale.ROOT).startsWith("current_game_team_")) {
String operation = identifier.substring(18);
int index = operation.lastIndexOf("_");
if (index != -1) {
String teamName = operation.substring(0, index);
String teamOperation = operation.substring(index + 1).toLowerCase(Locale.ROOT);

Game game = Main.isPlayerInGame(player) ? Main.getPlayerGameProfile(player).getGame() : null;
if (game != null) {
Team team = (Team) game.getTeamFromName(teamName);

if (team != null) {
switch (teamOperation) {
case "colored":
return team.color.chatColor + team.getName();
case "color":
return team.color.chatColor.toString();
case "ingame":
return game.getCurrentTeamByTeam(team) != null ? "yes" : "no";
case "players": {
CurrentTeam ct = game.getCurrentTeamByTeam(team);
if (ct != null) {
return Integer.toString(ct.countConnectedPlayers());
} else {
return "0";
}
}
case "maxplayers":
return Integer.toString(team.getMaxPlayers());
case "bed": {
CurrentTeam ct = game.getCurrentTeamByTeam(team);
if (ct != null) {
return ct.isBed ? "yes" : "no";
} else {
return "no";
}
}
case "bedsymbol": {
CurrentTeam ct = game.getCurrentTeamByTeam(team);
if (ct != null) {
boolean empty = ct.isBed && "RESPAWN_ANCHOR".equals(team.bed.getBlock().getType().name()) && Player116ListenerUtils.isAnchorEmpty(team.bed.getBlock());
return !ct.isBed ? Game.bedLostString() : (empty ? Game.anchorEmptyString() : Game.bedExistString());
} else {
return Game.bedLostString();
}
}
case "teamchests": {
CurrentTeam ct = game.getCurrentTeamByTeam(team);
if (ct != null) {
return Integer.toString(ct.countTeamChests());
} else {
return "0";
}
}
}
}
}
}
}

// current game
switch (identifier.toLowerCase(Locale.ROOT).substring(8)) {
case "game":
Expand Down Expand Up @@ -238,6 +324,46 @@ public String onPlaceholderRequest(Player player, String identifier) {
} else {
return "0";
}
case "game_timeformat":
if (Main.isPlayerInGame(player)) {
return Game.getFormattedTimeLeft(Main.getPlayerGameProfile(player).getGame().getCountdown());
} else {
return "0";
}
case "game_elapsedtime":
if (Main.isPlayerInGame(player)) {
Game game = Main.getPlayerGameProfile(player).getGame();
switch (game.getStatus()) {
case WAITING:
return Integer.toString(game.getLobbyCountdown() - game.getCountdown());
case RUNNING:
return Integer.toString(game.getGameTime() - game.getCountdown());
case GAME_END_CELEBRATING:
return Integer.toString(game.getPostGameWaiting() - game.getCountdown());
case REBUILDING:
case DISABLED:
return "0";
}
} else {
return "0";
}
case "game_elapsedtimeformat":
if (Main.isPlayerInGame(player)) {
Game game = Main.getPlayerGameProfile(player).getGame();
switch (game.getStatus()) {
case WAITING:
return Game.getFormattedTimeLeft(game.getLobbyCountdown() - game.getCountdown());
case RUNNING:
return Game.getFormattedTimeLeft(game.getGameTime() - game.getCountdown());
case GAME_END_CELEBRATING:
return Game.getFormattedTimeLeft(game.getPostGameWaiting() - game.getCountdown());
case REBUILDING:
case DISABLED:
return Game.getFormattedTimeLeft(0);
}
} else {
return Game.getFormattedTimeLeft(0);
}
case "game_world":
if (Main.isPlayerInGame(player)) {
return Main.getPlayerGameProfile(player).getGame().getWorld().getName();
Expand Down

0 comments on commit 5aa2dbb

Please sign in to comment.