From aee9b2986c239545f4ad1cc5d12ce10e9d61bad4 Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 20 Sep 2018 23:46:43 +0100 Subject: [PATCH] Fix some memory leaks within Nano Games --- .../nano/game/components/currency/GameCurrencyManager.java | 5 +---- .../game/games/quick/challenges/ChallengePunchAPig.java | 2 +- .../games/quick/challenges/ChallengeReverseRunner.java | 7 ++++++- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Plugins/Mineplex.Game.Nano/src/mineplex/game/nano/game/components/currency/GameCurrencyManager.java b/Plugins/Mineplex.Game.Nano/src/mineplex/game/nano/game/components/currency/GameCurrencyManager.java index 47db090e6..6cdf1698e 100644 --- a/Plugins/Mineplex.Game.Nano/src/mineplex/game/nano/game/components/currency/GameCurrencyManager.java +++ b/Plugins/Mineplex.Game.Nano/src/mineplex/game/nano/game/components/currency/GameCurrencyManager.java @@ -138,7 +138,7 @@ public class GameCurrencyManager extends GameManager implements CurrencyComponen private void informRewards(Player player, boolean reward) { - GameSessionData data = _sessionData.get(player); + GameSessionData data = reward ? _sessionData.remove(player) : _sessionData.get(player); if (data == null || data.Games == 0) { @@ -202,9 +202,6 @@ public class GameCurrencyManager extends GameManager implements CurrencyComponen statsManager.incrementStat(player, "Global.GamesPlayed", gamesPlayed); require(TrackManager.class).getTrack(GemCollectorTrack.class).earnedGems(player, gems); } - - // Remove from session - _sessionData.remove(player); } // Inform diff --git a/Plugins/Mineplex.Game.Nano/src/mineplex/game/nano/game/games/quick/challenges/ChallengePunchAPig.java b/Plugins/Mineplex.Game.Nano/src/mineplex/game/nano/game/games/quick/challenges/ChallengePunchAPig.java index ffe8591f5..6a1804c67 100644 --- a/Plugins/Mineplex.Game.Nano/src/mineplex/game/nano/game/games/quick/challenges/ChallengePunchAPig.java +++ b/Plugins/Mineplex.Game.Nano/src/mineplex/game/nano/game/games/quick/challenges/ChallengePunchAPig.java @@ -78,7 +78,7 @@ public class ChallengePunchAPig extends Challenge LivingEntity damagee = event.GetDamageeEntity(); Player damager = event.GetDamagerPlayer(false); - if (damagee instanceof Pig) + if (damagee instanceof Pig && damager != null) { int punched = _punched.getOrDefault(damager, 0) + 1; diff --git a/Plugins/Mineplex.Game.Nano/src/mineplex/game/nano/game/games/quick/challenges/ChallengeReverseRunner.java b/Plugins/Mineplex.Game.Nano/src/mineplex/game/nano/game/games/quick/challenges/ChallengeReverseRunner.java index c7788ec7b..283e4d2c1 100644 --- a/Plugins/Mineplex.Game.Nano/src/mineplex/game/nano/game/games/quick/challenges/ChallengeReverseRunner.java +++ b/Plugins/Mineplex.Game.Nano/src/mineplex/game/nano/game/games/quick/challenges/ChallengeReverseRunner.java @@ -49,8 +49,13 @@ public class ChallengeReverseRunner extends Challenge return; } - for (Player player : _players) + for (Player player : _game.getAlivePlayers()) { + if (!isParticipating(player)) + { + continue; + } + Location location = player.getLocation().add(0, 10, 0).getBlock().getLocation().add(0.5, 0, 0.5); if (!inArena(location))