mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-30 10:05:59 +00:00
fix ban spam when someone joins and spams at 308 mph (#176)
* fix ban spam when someone joins and spams at 308 mph there's probably a more efficient and less retarded way of doing this but its 2 am and i cannot think * changed the message while testing but i dont see anything wrong with the old one * wanted to add this rq * not needed * clean up crew Co-authored-by: super
This commit is contained in:
parent
89b91598fb
commit
6d0400cdf3
@ -9,14 +9,21 @@ import org.bukkit.event.EventHandler;
|
|||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||||
|
import org.bukkit.event.player.PlayerKickEvent;
|
||||||
|
import org.bukkit.event.player.PlayerLoginEvent;
|
||||||
|
import org.bukkit.event.player.PlayerLoginEvent.Result;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
import org.bukkit.scheduler.BukkitTask;
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class AntiSpam extends FreedomService
|
public class AntiSpam extends FreedomService
|
||||||
{
|
{
|
||||||
|
|
||||||
public static final int MSG_PER_CYCLE = 8;
|
public static final int MSG_PER_CYCLE = 8;
|
||||||
public static final int TICKS_PER_CYCLE = 2 * 10;
|
public static final int TICKS_PER_CYCLE = 2 * 10;
|
||||||
|
List<Player> markedForDeath = new ArrayList<>();
|
||||||
//
|
//
|
||||||
public BukkitTask cycleTask = null;
|
public BukkitTask cycleTask = null;
|
||||||
|
|
||||||
@ -75,14 +82,24 @@ public class AntiSpam extends FreedomService
|
|||||||
// Check for spam
|
// Check for spam
|
||||||
if (playerdata.incrementAndGetMsgCount() > MSG_PER_CYCLE)
|
if (playerdata.incrementAndGetMsgCount() > MSG_PER_CYCLE)
|
||||||
{
|
{
|
||||||
FSync.bcastMsg(player.getName() + " was automatically kicked for spamming chat.", ChatColor.RED);
|
if (!markedForDeath.contains(player))
|
||||||
FSync.autoEject(player, "Kicked for spamming chat.");
|
{
|
||||||
|
markedForDeath.add(player);
|
||||||
|
FSync.bcastMsg(player.getName() + " was automatically kicked for spamming chat.", ChatColor.RED);
|
||||||
|
FSync.autoEject(player, "Kicked for spamming chat.");
|
||||||
|
|
||||||
playerdata.resetMsgCount();
|
playerdata.resetMsgCount();
|
||||||
|
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
else if (playerdata.incrementAndGetMsgCount() > MSG_PER_CYCLE / 2)
|
||||||
|
{
|
||||||
|
FUtil.playerMsg(player, "Please refrain from spamming chat.", ChatColor.GRAY);
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOW)
|
@EventHandler(priority = EventPriority.LOW)
|
||||||
@ -114,4 +131,14 @@ public class AntiSpam extends FreedomService
|
|||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.NORMAL)
|
||||||
|
public void onPlayerKick(PlayerKickEvent event)
|
||||||
|
{
|
||||||
|
if (markedForDeath.contains(event.getPlayer()))
|
||||||
|
{
|
||||||
|
markedForDeath.remove(event.getPlayer());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user