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.
This commit is contained in:
Ben 2016-04-07 07:00:46 +01:00
parent 3a8ab581dd
commit eed3df720a
1 changed files with 26 additions and 10 deletions

View File

@ -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<IncognitoClient>
@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)
{
player.hidePlayer(event.getPlayer());
customEvent = UtilServer.CallEvent(new IncognitoHidePlayerEvent(player));
}
if (Get(player).Status)
for (Player other : UtilServer.getPlayers())
{
IncognitoHidePlayerEvent customEvent2 = UtilServer.CallEvent(new IncognitoHidePlayerEvent(player));
if (customEvent != null && !customEvent.isCancelled() && !_clientManager.hasRank(other, _clientManager.Get(player).GetRank()))
{
other.hidePlayer(player);
}
if (!customEvent2.isCancelled() && !_clientManager.hasRank(event.getPlayer(), _clientManager.Get(player).GetRank()))
if (Get(other).Status)
{
event.getPlayer().hidePlayer(player);
IncognitoHidePlayerEvent customEvent2 = UtilServer.CallEvent(new IncognitoHidePlayerEvent(other));
if (!customEvent2.isCancelled() && !_clientManager.hasRank(player, _clientManager.Get(other).GetRank()))
{
player.hidePlayer(other);
}
}
}
});
}
@EventHandler(priority = EventPriority.HIGHEST)