From d267c15845f47b959f6d418067c3794daeb45df4 Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 22 Jan 2018 14:05:28 +0000 Subject: [PATCH] Fix GameSummary showing an incorrect amout of shards --- .../nautilus/game/arcade/ArcadeManager.java | 5 ++ .../gamesummary/GameSummaryModule.java | 20 ++----- .../components/ShardSummaryComponent.java | 2 +- .../arcade/managers/GameRewardManager.java | 58 +++++++++++++------ 4 files changed, 51 insertions(+), 34 deletions(-) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java index fceba7e04..ced536c9d 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java @@ -791,6 +791,11 @@ public class ArcadeManager extends MiniPlugin implements IRelation return _gameCreationManager; } + public GameRewardManager getGameRewardManager() + { + return _gameRewardManager; + } + public GameHostManager GetGameHostManager() { return _gameHostManager; diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/gamesummary/GameSummaryModule.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/gamesummary/GameSummaryModule.java index bda6c0c23..591cd441d 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/gamesummary/GameSummaryModule.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/gamesummary/GameSummaryModule.java @@ -2,23 +2,20 @@ package nautilus.game.arcade.game.modules.gamesummary; import java.util.ArrayList; import java.util.List; -import java.util.Map; import java.util.function.Function; -import mineplex.core.common.jsonchat.HoverEvent; -import mineplex.core.common.jsonchat.JsonMessage; import org.bukkit.Sound; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; -import com.google.common.util.concurrent.AtomicDouble; - import mineplex.core.achievement.Achievement; import mineplex.core.achievement.AchievementData; import mineplex.core.achievement.AchievementLog; import mineplex.core.achievement.AchievementManager; import mineplex.core.common.Pair; import mineplex.core.common.currency.GlobalCurrency; +import mineplex.core.common.jsonchat.HoverEvent; +import mineplex.core.common.jsonchat.JsonMessage; import mineplex.core.common.util.C; import mineplex.core.common.util.UtilServer; @@ -26,7 +23,6 @@ import nautilus.game.arcade.ArcadeFormat; import nautilus.game.arcade.ArcadeManager; import nautilus.game.arcade.events.GameStateChangeEvent; import nautilus.game.arcade.game.Game.GameState; -import nautilus.game.arcade.game.GemData; import nautilus.game.arcade.game.modules.Module; import nautilus.game.arcade.game.modules.gamesummary.components.AchievementSummaryComponent; import nautilus.game.arcade.game.modules.gamesummary.components.ExperienceSummaryComponent; @@ -89,15 +85,7 @@ public class GameSummaryModule extends Module }; addComponent(new GemSummaryComponent(player -> getGame().GetGems(player), GlobalCurrency.GEM.getColor(), GlobalCurrency.GEM.getPrefix())); - addComponent(new ShardSummaryComponent(getGame().getArcadeManager(), player -> - { - AtomicDouble total = new AtomicDouble(); - Map gems = getGame().GetGems(player); - - gems.values().forEach(gemData -> total.getAndAdd(gemData.Gems)); - - return Pair.create(player, (int) total.get()); - })); + addComponent(new ShardSummaryComponent(getGame().getArcadeManager(), player -> Pair.create(player, getGame().getArcadeManager().getGameRewardManager().getBaseShardsEarned(player)))); addComponent(new ExperienceSummaryComponent(experienceFunction)); addComponent(new LevelUpSummaryComponent(experienceFunction)); addComponent(new AchievementSummaryComponent(getGame().getArcadeManager())); @@ -114,7 +102,7 @@ public class GameSummaryModule extends Module ArcadeManager manager = getGame().getArcadeManager(); - if (!manager.IsRewardGems() || !manager.IsRewardStats() || !manager.IsRewardAchievements()) + if (!manager.IsRewardGems() || !manager.IsRewardStats() || !manager.IsRewardAchievements() || manager.GetGame().getGameLiveTime() == 0) { return; } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/gamesummary/components/ShardSummaryComponent.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/gamesummary/components/ShardSummaryComponent.java index 93a3dad77..93148cb70 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/gamesummary/components/ShardSummaryComponent.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/gamesummary/components/ShardSummaryComponent.java @@ -82,7 +82,7 @@ public class ShardSummaryComponent extends GameSummaryComponent 0) { diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameRewardManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameRewardManager.java index 9d0c3d385..271efef73 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameRewardManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameRewardManager.java @@ -1,5 +1,6 @@ package nautilus.game.arcade.managers; +import java.util.HashMap; import java.util.Map; import org.bukkit.entity.Player; @@ -34,6 +35,7 @@ import nautilus.game.arcade.game.GemData; */ public class GameRewardManager implements Listener { + public enum Perm implements Permission { SHARD_MULT_1, @@ -48,15 +50,18 @@ public class GameRewardManager implements Listener boolean DoubleGem = false; boolean TimeReward = true; + private final Map _baseShardsEarned; + public GameRewardManager(ArcadeManager manager) { Manager = manager; - Manager.getPluginManager().registerEvents(this, Manager.getPlugin()); - + _baseShardsEarned = new HashMap<>(); + UtilServer.RegisterEvents(this); + generatePermissions(); } - + private void generatePermissions() { PermissionGroup.ULTRA.setPermission(Perm.SHARD_MULT_1, true, true); @@ -129,7 +134,7 @@ public class GameRewardManager implements Listener } @EventHandler(priority = EventPriority.LOW) - public void GameStateChange(GameStateChangeEvent event) + public void gameDead(GameStateChangeEvent event) { if (event.GetState() != GameState.Dead) { @@ -139,6 +144,17 @@ public class GameRewardManager implements Listener UtilServer.getPlayersCollection().forEach(player -> GiveGems(event.GetGame(), player)); } + @EventHandler(priority = EventPriority.MONITOR) + public void gameDeadCleanup(GameStateChangeEvent event) + { + if (event.GetState() != GameState.Dead) + { + return; + } + + _baseShardsEarned.clear(); + } + private void GiveGems(Game game, Player player) { if (!Manager.IsRewardGems()) @@ -147,7 +163,7 @@ public class GameRewardManager implements Listener } double gameMult = game.GemMultiplier; - Map gems = game.GetGems(player); + Map gems = game.GetGems(player); if (gems == null) { @@ -158,22 +174,25 @@ public class GameRewardManager implements Listener int gemsToReward; // Calculate the base gems earned in this game + int gemsEarned = 0; + + for (GemData data : gems.values()) { - int gemsEarned = 0; - - for (GemData data : gems.values()) - gemsEarned += (int) data.Gems; - - if (gemsEarned <= 0) - gemsEarned = 1; - - baseGemsEarned = (int) (gemsEarned * gameMult); - gemsToReward = baseGemsEarned; + gemsEarned += (int) data.Gems; } + if (gemsEarned <= 0) + { + gemsEarned = 1; + } + + baseGemsEarned = (int) (gemsEarned * gameMult); + gemsToReward = baseGemsEarned; + // Award players shards equal to base gems, plus booster bonuses. final int baseShardsEarned = baseGemsEarned; int shardsToReward = baseShardsEarned; + _baseShardsEarned.put(player, baseShardsEarned); // Gem Boooster Booster booster = Manager.getBoosterManager().getActiveBooster(); @@ -220,7 +239,7 @@ public class GameRewardManager implements Listener } int accountId = Manager.GetClients().getAccountId(player); - + double shardMult = 0; for (Perm shardMultPerm : Perm.values()) @@ -235,7 +254,7 @@ public class GameRewardManager implements Listener { shardsToReward += shardsToReward * shardMult; } - + if (!game.CrownsEnabled) { Manager.GetDonation().rewardCurrency(GlobalCurrency.GEM, player, "Earned " + game.GetName(), gemsToReward); @@ -265,4 +284,9 @@ public class GameRewardManager implements Listener Manager.GetStatsManager().incrementStat(player, game.GetName() + ".CrownsEarned", gemsToReward); } } + + public Integer getBaseShardsEarned(Player player) + { + return _baseShardsEarned.get(player); + } }