Try to prevent duplicate bans even more

This commit is contained in:
samczsun 2016-12-22 22:42:07 -05:00
parent 1bcbddee87
commit a0716ae774
1 changed files with 20 additions and 3 deletions

View File

@ -1,9 +1,11 @@
package mineplex.core.antihack;
import javax.xml.bind.DatatypeConverter;
import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
@ -27,6 +29,7 @@ import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerToggleFlightEvent;
import org.bukkit.plugin.ServicePriority;
@ -138,7 +141,9 @@ public class AntiHack extends MiniPlugin
private final Set<String> _detailedMessages = new HashSet<>();
private Set<Player> _pendingBan = new HashSet<>();
private Set<Player> _pendingBan = Collections.synchronizedSet(new HashSet<>());
private Set<UUID> _banned = Collections.synchronizedSet(new HashSet<>());
// These are the GWEN checks to ignore when handling PlayerViolationEvent
private HashSet<Class<? extends Check>> _ignoredChecks = new HashSet<>();
@ -186,11 +191,18 @@ public class AntiHack extends MiniPlugin
new BanwaveAnimationSpin().run(player, after);
}
@EventHandler
public void onQuit(PlayerQuitEvent event)
{
UUID uuid = event.getPlayer().getUniqueId();
runSync(() -> _banned.remove(uuid));
}
public void doBan(Player player, Class<? extends Check> cause)
{
runSync(() ->
{
if (_pendingBan.add(player))
if (_pendingBan.add(player) && !_banned.contains(player.getUniqueId()))
{
CoreClient coreClient = _clientManager.Get(player);
@ -215,7 +227,11 @@ public class AntiHack extends MiniPlugin
if (coreClient.GetRank().has(Rank.TWITCH))
{
doPunish.accept(result -> _pendingBan.remove(player));
doPunish.accept(result ->
{
_pendingBan.remove(player);
_banned.add(player.getUniqueId());
});
}
else
{
@ -225,6 +241,7 @@ public class AntiHack extends MiniPlugin
if (result == PunishmentResponse.Punished)
{
announceBan(player);
_banned.add(player.getUniqueId());
}
_pendingBan.remove(player);
})