From eed3df720a77a99d884a5f30ee8dad78b2db140a Mon Sep 17 00:00:00 2001 From: Ben Date: Thu, 7 Apr 2016 07:00:46 +0100 Subject: [PATCH] Disable incognito mode for staff members that have been demoted whilst using it. Also fixes a bug that caused IncognitoHidePlayerEvent fire even if the player logging in does not have incognito mode enabled. --- .../core/incognito/IncognitoManager.java | 36 +++++++++++++------ 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/incognito/IncognitoManager.java b/Plugins/Mineplex.Core/src/mineplex/core/incognito/IncognitoManager.java index 91d873faa..afb328093 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/incognito/IncognitoManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/incognito/IncognitoManager.java @@ -17,6 +17,7 @@ import com.google.common.base.Function; import mineplex.core.MiniDbClientPlugin; import mineplex.core.account.CoreClientManager; +import mineplex.core.common.Rank; import mineplex.core.common.util.C; import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilServer; @@ -90,30 +91,45 @@ public class IncognitoManager extends MiniDbClientPlugin @EventHandler(priority = EventPriority.HIGHEST) public void Join(PlayerJoinEvent event) { + Player player = event.getPlayer(); + + if (Get(event.getPlayer()).Status && !_clientManager.hasRank(event.getPlayer(), Rank.HELPER)) + { + Get(event.getPlayer()).Status = false; + runAsync(() -> _repository.setStatus(_clientManager.getAccountId(player), false)); + return; + } + if (Get(event.getPlayer()).Status) { event.setJoinMessage(null); - informIncognito(event.getPlayer()); + informIncognito(player); } - IncognitoHidePlayerEvent customEvent = UtilServer.CallEvent(new IncognitoHidePlayerEvent(event.getPlayer())); + IncognitoHidePlayerEvent customEvent = null; - UtilServer.getPlayersCollection().forEach(player -> { - if (!customEvent.isCancelled() && Get(event.getPlayer()).Status && !_clientManager.hasRank(player, _clientManager.Get(event.getPlayer()).GetRank())) + if (Get(event.getPlayer()).Status) + { + customEvent = UtilServer.CallEvent(new IncognitoHidePlayerEvent(player)); + } + + for (Player other : UtilServer.getPlayers()) + { + if (customEvent != null && !customEvent.isCancelled() && !_clientManager.hasRank(other, _clientManager.Get(player).GetRank())) { - player.hidePlayer(event.getPlayer()); + other.hidePlayer(player); } - if (Get(player).Status) + if (Get(other).Status) { - IncognitoHidePlayerEvent customEvent2 = UtilServer.CallEvent(new IncognitoHidePlayerEvent(player)); + IncognitoHidePlayerEvent customEvent2 = UtilServer.CallEvent(new IncognitoHidePlayerEvent(other)); - if (!customEvent2.isCancelled() && !_clientManager.hasRank(event.getPlayer(), _clientManager.Get(player).GetRank())) + if (!customEvent2.isCancelled() && !_clientManager.hasRank(player, _clientManager.Get(other).GetRank())) { - event.getPlayer().hidePlayer(player); + player.hidePlayer(other); } } - }); + } } @EventHandler(priority = EventPriority.HIGHEST)