From 81a869c26465c9fcf1fb381a6c0e867ad1681e71 Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 18 May 2017 00:28:08 +0100 Subject: [PATCH] Implement progression titles --- .../mineplex/gemhunters/chat/ChatModule.java | 10 +- .../progression/ProgressionModule.java | 28 +++++- .../progression/ProgressionTitle.java | 26 ++++++ .../scoreboard/GemHuntersScoreboard.java | 9 ++ .../scoreboard/ScoreboardModule.java | 92 ++++++++++++------- 5 files changed, 130 insertions(+), 35 deletions(-) create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/progression/ProgressionTitle.java diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/chat/ChatModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/chat/ChatModule.java index 02e210ff5..f53b1eb44 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/chat/ChatModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/chat/ChatModule.java @@ -1,5 +1,7 @@ package mineplex.gemhunters.chat; +import mineplex.gemhunters.economy.EconomyModule; +import mineplex.gemhunters.progression.ProgressionModule; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -26,15 +28,19 @@ public class ChatModule extends MiniPlugin private final CoreClientManager _clientManager; private final Chat _chat; + private final EconomyModule _economy; private final PartyManager _party; - + private final ProgressionModule _progression; + private ChatModule() { super("Chat"); _clientManager = require(CoreClientManager.class); _chat = require(Chat.class); + _economy = require(EconomyModule.class); _party = require(PartyManager.class); + _progression = require(ProgressionModule.class); } @EventHandler(priority = EventPriority.LOWEST) @@ -90,7 +96,7 @@ public class ChatModule extends MiniPlugin } else { - message += C.cWhite; + message = _progression.getTitle(_economy.getGems(player)).getTitle() + " " + message + C.cWhite; } message += _chat.getFilteredMessage(player, event.getMessage()); diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/progression/ProgressionModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/progression/ProgressionModule.java index f89dec275..04d76ac24 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/progression/ProgressionModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/progression/ProgressionModule.java @@ -1,17 +1,41 @@ package mineplex.gemhunters.progression; -import com.google.common.collect.ImmutableMap; import mineplex.core.MiniPlugin; import mineplex.core.ReflectivelyCreateMiniPlugin; +import mineplex.core.common.util.C; + +import java.util.Arrays; +import java.util.List; @ReflectivelyCreateMiniPlugin public class ProgressionModule extends MiniPlugin { - private final Map TITLES = ImmutableMap().builder().build(); + private static final List TITLE_LIST = Arrays.asList( + new ProgressionTitle(C.cGray + "Bankrupt", 0), + new ProgressionTitle(C.cAqua + "Beggar", 100), + new ProgressionTitle(C.cGreen + "Poor", 250), + new ProgressionTitle(C.cGreen + "Middle Class", 500), + new ProgressionTitle(C.cGold + "Wealthy", 750), + new ProgressionTitle(C.cGold + "Loaded", 1000), + new ProgressionTitle(C.cRed + "Millionaire", 5000) + ); public ProgressionModule() { super("Progression"); } + + public ProgressionTitle getTitle(int gems) + { + for (ProgressionTitle title : TITLE_LIST) + { + if (title.getRequiredGems() >= gems) + { + return title; + } + } + + return TITLE_LIST.get(TITLE_LIST.size() - 1); + } } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/progression/ProgressionTitle.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/progression/ProgressionTitle.java new file mode 100644 index 000000000..493959845 --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/progression/ProgressionTitle.java @@ -0,0 +1,26 @@ +package mineplex.gemhunters.progression; + +import mineplex.core.common.util.C; + +public class ProgressionTitle +{ + + private String _title; + private int _requiredGems; + + public ProgressionTitle(String title, int requiredGems) + { + _title = title + C.Reset; + _requiredGems = requiredGems; + } + + public String getTitle() + { + return _title; + } + + public int getRequiredGems() + { + return _requiredGems; + } +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/scoreboard/GemHuntersScoreboard.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/scoreboard/GemHuntersScoreboard.java index 27e0eb487..ba3067ae3 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/scoreboard/GemHuntersScoreboard.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/scoreboard/GemHuntersScoreboard.java @@ -1,5 +1,7 @@ package mineplex.gemhunters.scoreboard; +import mineplex.gemhunters.progression.ProgressionModule; +import mineplex.gemhunters.progression.ProgressionTitle; import org.bukkit.entity.Player; import mineplex.core.Managers; @@ -17,6 +19,7 @@ public class GemHuntersScoreboard extends WritableMineplexScoreboard private final EconomyModule _economy; private final PlayerStatusModule _playerStatus; + private final ProgressionModule _progression; private final SupplyDropModule _supplyDrop; public GemHuntersScoreboard(Player player) @@ -25,6 +28,7 @@ public class GemHuntersScoreboard extends WritableMineplexScoreboard _economy = Managers.get(EconomyModule.class); _playerStatus = Managers.get(PlayerStatusModule.class); + _progression = Managers.get(ProgressionModule.class); _supplyDrop = Managers.get(SupplyDropModule.class); } @@ -60,4 +64,9 @@ public class GemHuntersScoreboard extends WritableMineplexScoreboard { return _economy.getGems(player); } + + public String getPrefix(Player perspective, Player subject) + { + return _progression.getTitle(_economy.getGems(subject)).getTitle() + " " + C.cYellow; + } } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/scoreboard/ScoreboardModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/scoreboard/ScoreboardModule.java index 4b10288c0..e3677ca02 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/scoreboard/ScoreboardModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/scoreboard/ScoreboardModule.java @@ -70,17 +70,17 @@ public class ScoreboardModule extends MiniPlugin for (Player player : Bukkit.getOnlinePlayers()) { int gems = _economy.getGems(player); - + for (GemHuntersScoreboard scoreboard : _scoreboards.values()) { Objective objective = scoreboard.getHandle().getObjective(DisplaySlot.BELOW_NAME); Score score = objective.getScore(player.getName()); - + if (score.getScore() == gems) { continue; } - + score.setScore(gems); } } @@ -106,45 +106,75 @@ public class ScoreboardModule extends MiniPlugin _scoreboards.remove(player.getUniqueId()); } - public void createPlayerScoreboard(Player player) - { - if (!_scoreboards.containsKey(player.getUniqueId())) + @EventHandler + public void updateScoreboard(UpdateEvent event) + { + if (event.getType() != UpdateType.MIN_01) { - GemHuntersScoreboard scoreboard = new GemHuntersScoreboard(player); - Scoreboard handle = scoreboard.getHandle(); + return; + } + for (Player player : Bukkit.getOnlinePlayers()) + { + createPlayerScoreboard(player); + } + } + + public void createPlayerScoreboard(Player player) + { + GemHuntersScoreboard scoreboard; + + if (_scoreboards.containsKey(player.getUniqueId())) + { + scoreboard = _scoreboards.get(player.getUniqueId()); + } + else + { + scoreboard = new GemHuntersScoreboard(player); _scoreboards.put(player.getUniqueId(), scoreboard); // Gem Counter Undername - Objective gemCounter = handle.registerNewObjective("Gems", "Gems"); + Objective gemCounter = scoreboard.getHandle().registerNewObjective("Gems", "Gems"); gemCounter.setDisplaySlot(DisplaySlot.BELOW_NAME); + } - for (GemHuntersScoreboard other : _scoreboards.values()) + Scoreboard handle = scoreboard.getHandle(); + + for (GemHuntersScoreboard other : _scoreboards.values()) + { + // Set the other player's name tag for the player joining + Player otherPlayer = other.getOwner(); + Team team = handle.getTeam(otherPlayer.getName()); + + if (team == null) { - // Set the other player's name tag for the player joining - Player otherPlayer = other.getOwner(); - Team team = handle.registerNewTeam(otherPlayer.getName()); - - team.setPrefix(C.cYellow); - //team.setSuffix(scoreboard.getSuffix(player, otherPlayer)); - team.addEntry(otherPlayer.getName()); - - if (player.equals(otherPlayer)) - { - continue; - } - - // Set the player that is joining - Scoreboard otherHandle = other.getHandle(); - Team otherTeam = otherHandle.registerNewTeam(player.getName()); - - otherTeam.setPrefix(C.cYellow); - //otherTeam.setSuffix(other.getSuffix(other.getOwner(), player)); - otherTeam.addEntry(player.getName()); + team = handle.registerNewTeam(otherPlayer.getName()); } - player.setScoreboard(scoreboard.getHandle()); + team.setPrefix(scoreboard.getPrefix(player, otherPlayer)); + //team.setSuffix(scoreboard.getSuffix(player, otherPlayer)); + team.addEntry(otherPlayer.getName()); + + if (player.equals(otherPlayer)) + { + continue; + } + + // Set the player that is joining + Scoreboard otherHandle = other.getHandle(); + Team otherTeam = otherHandle.getTeam(player.getName()); + + if (otherTeam == null) + { + otherTeam = otherHandle.registerNewTeam(player.getName()); + } + + otherTeam.setPrefix(other.getPrefix(other.getOwner(), player)); + //otherTeam.setSuffix(other.getSuffix(other.getOwner(), player)); + otherTeam.addEntry(player.getName()); } + + player.setScoreboard(handle); } public void updateTitles()