Skip to content

Commit

Permalink
Added a title when the game ends. (#110, #27)
Browse files Browse the repository at this point in the history
* NEW: the winners are broadcasted through a /title when the game ends (or the finish sequence is summoned using /uh finish). Can be disabled in the config.
  • Loading branch information
AmauryCarrade committed Jan 12, 2016
1 parent 4c6afdb commit f4ca1d1
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 12 deletions.
42 changes: 30 additions & 12 deletions src/main/java/eu/carrade/amaury/UHCReloaded/game/UHGameManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import fr.zcraft.zlib.tools.Callback;
import fr.zcraft.zlib.tools.runners.RunTask;
import fr.zcraft.zlib.tools.text.ActionBar;
import fr.zcraft.zlib.tools.text.Titles;
import org.bukkit.Achievement;
import org.bukkit.Bukkit;
import org.bukkit.Difficulty;
Expand Down Expand Up @@ -1050,30 +1051,28 @@ public void finishGame()
}

// There's only one team.
p.getLogger().info(p.getGameManager().getAliveTeams().toString());
UHTeam winnerTeam = p.getGameManager().getAliveTeams().iterator().next();
Set<OfflinePlayer> listWinners = winnerTeam.getPlayers();

if (p.getConfig().getBoolean("finish.message"))
{
if (p.getGameManager().isGameWithTeams())
if (isGameWithTeams())
{
String winners = "";
int j = 0;

for (OfflinePlayer winner : listWinners)
{
if (j == 0)
if (j != 0)
{
// Nothing
}
else if (j == listWinners.size() - 1)
{
winners += " " + i.t("finish.and") + " ";
}
else
{
winners += ", ";
if (j == listWinners.size() - 1)
{
winners += " " + i.t("finish.and") + " ";
}
else
{
winners += ", ";
}
}

winners += winner.getName();
Expand All @@ -1088,6 +1087,25 @@ else if (j == listWinners.size() - 1)
}
}

if (p.getConfig().getBoolean("finish.title"))
{
final String title;
final String subtitle;

if (isGameWithTeams())
{
title = i.t("finish.titles.withTeams.title", winnerTeam.getDisplayName());
subtitle = i.t("finish.titles.withTeams.subtitle", winnerTeam.getDisplayName());
}
else
{
title = i.t("finish.titles.withoutTeams.title", winnerTeam.getDisplayName());
subtitle = i.t("finish.titles.withoutTeams.subtitle", winnerTeam.getDisplayName());
}

Titles.broadcastTitle(5, 142, 21, title, subtitle);
}

if (p.getConfig().getBoolean("finish.fireworks.enabled"))
{
new FireworksOnWinnersTask(p, listWinners).runTaskTimer(p, 0l, 10l);
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,8 @@ finish:
timeAfterLastDeath: 3 # The command will be executed this amount of seconds after the last death.

message: true # If true, the name of the winner(s) will be broadcasted.
title: true # If true, a title will display the winner(s) of the game.

fireworks:
enabled: true # If true, some fireworks will be launched at the location of the winners.
duration: 10 # In seconds.
Expand Down
8 changes: 8 additions & 0 deletions src/main/resources/i18n/en_US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,14 @@ keys:
withTeams: "{darkgreen}{obfuscated}--{green} Congratulations to {0} (team {1}{green}) for their victory! {darkgreen}{obfuscated}--"
withoutTeams: "{darkgreen}{obfuscated}--{green} Congratulations to {0} for his victory! {darkgreen}{obfuscated}--"

titles:
withTeams:
title: "{darkgreen}{0}"
subtitle: "{green}This team wins the game!"
withoutTeams:
title: "{darkgreen}{0}"
subtitle: "{green}wins the game!"

pvp:
enabled: "{red}{bold}Warning!{white} PvP is now enabled."

Expand Down
8 changes: 8 additions & 0 deletions src/main/resources/i18n/fr_FR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,14 @@ keys:
withTeams: "{darkgreen}{obfuscated}--{green} Félicitations à {0} (équipe {1}{green}) pour leur victoire ! {darkgreen}{obfuscated}--"
withoutTeams: "{darkgreen}{obfuscated}--{green} Félicitation à {0} pour sa victoire ! {darkgreen}{obfuscated}--"

titles:
withTeams:
title: "{darkgreen}{0}"
subtitle: "{green}Cette équipe remporte la victoire !"
withoutTeams:
title: "{darkgreen}{0}"
subtitle: "{green}remporte la partie !"

pvp:
enabled: "{red}{bold}Attention !{white} Le PvP est désormais actif."

Expand Down

0 comments on commit f4ca1d1

Please sign in to comment.