From f4ca1d151cd0c6ac4094f278b9e26b714c6f21ef Mon Sep 17 00:00:00 2001 From: Amaury Carrade Date: Tue, 12 Jan 2016 01:28:17 +0100 Subject: [PATCH] Added a title when the game ends. (#110, #27) * 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. --- .../UHCReloaded/game/UHGameManager.java | 42 +++++++++++++------ src/main/resources/config.yml | 2 + src/main/resources/i18n/en_US.yml | 8 ++++ src/main/resources/i18n/fr_FR.yml | 8 ++++ 4 files changed, 48 insertions(+), 12 deletions(-) diff --git a/src/main/java/eu/carrade/amaury/UHCReloaded/game/UHGameManager.java b/src/main/java/eu/carrade/amaury/UHCReloaded/game/UHGameManager.java index e8c3108..224c9af 100644 --- a/src/main/java/eu/carrade/amaury/UHCReloaded/game/UHGameManager.java +++ b/src/main/java/eu/carrade/amaury/UHCReloaded/game/UHGameManager.java @@ -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; @@ -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 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(); @@ -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); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 0d5b5a9..83eac2b 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -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. diff --git a/src/main/resources/i18n/en_US.yml b/src/main/resources/i18n/en_US.yml index ec6d02b..749aa04 100644 --- a/src/main/resources/i18n/en_US.yml +++ b/src/main/resources/i18n/en_US.yml @@ -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." diff --git a/src/main/resources/i18n/fr_FR.yml b/src/main/resources/i18n/fr_FR.yml index 6879b8e..ce27802 100644 --- a/src/main/resources/i18n/fr_FR.yml +++ b/src/main/resources/i18n/fr_FR.yml @@ -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."