mirror of
https://github.com/plexusorg/Plex.git
synced 2024-12-22 17:17:37 +00:00
adds anti spam
likely needs tweaking
This commit is contained in:
parent
7c27c03d98
commit
b1fcf5e348
41
src/main/java/dev/plex/listener/impl/AntiSpamListener.java
Normal file
41
src/main/java/dev/plex/listener/impl/AntiSpamListener.java
Normal file
@ -0,0 +1,41 @@
|
||||
package dev.plex.listener.impl;
|
||||
|
||||
import dev.plex.listener.PlexListener;
|
||||
import dev.plex.services.impl.TimingService;
|
||||
import io.papermc.paper.event.player.AsyncChatEvent;
|
||||
import java.util.UUID;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
|
||||
public class AntiSpamListener extends PlexListener
|
||||
{
|
||||
@EventHandler
|
||||
public void onChat(AsyncChatEvent event)
|
||||
{
|
||||
TimingService.cooldowns.merge(event.getPlayer().getUniqueId(), 1L, Long::sum);
|
||||
if (getCount(event.getPlayer().getUniqueId()) > 8L)
|
||||
{
|
||||
event.getPlayer().sendMessage(Component.text("Please refrain from spamming messages.").color(NamedTextColor.GRAY));
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event)
|
||||
{
|
||||
TimingService.cooldowns.merge(event.getPlayer().getUniqueId(), 1L, Long::sum);
|
||||
if (getCount(event.getPlayer().getUniqueId()) > 8L)
|
||||
{
|
||||
event.getPlayer().sendMessage(Component.text("Please refrain from spamming commands.").color(NamedTextColor.GRAY));
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
public long getCount(UUID uuid)
|
||||
{
|
||||
return TimingService.cooldowns.getOrDefault(uuid, 1L);
|
||||
}
|
||||
}
|
@ -6,6 +6,7 @@ import dev.plex.services.impl.AutoWipeService;
|
||||
import dev.plex.services.impl.BanService;
|
||||
import dev.plex.services.impl.CommandBlockerService;
|
||||
import dev.plex.services.impl.GameRuleService;
|
||||
import dev.plex.services.impl.TimingService;
|
||||
import dev.plex.services.impl.UpdateCheckerService;
|
||||
import java.util.List;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -21,6 +22,7 @@ public class ServiceManager
|
||||
registerService(new BanService());
|
||||
registerService(new CommandBlockerService());
|
||||
registerService(new GameRuleService());
|
||||
registerService(new TimingService());
|
||||
registerService(new UpdateCheckerService());
|
||||
}
|
||||
|
||||
|
28
src/main/java/dev/plex/services/impl/TimingService.java
Normal file
28
src/main/java/dev/plex/services/impl/TimingService.java
Normal file
@ -0,0 +1,28 @@
|
||||
package dev.plex.services.impl;
|
||||
|
||||
import dev.plex.services.AbstractService;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class TimingService extends AbstractService
|
||||
{
|
||||
public static final Map<UUID, Long> cooldowns = new HashMap<>();
|
||||
|
||||
public TimingService()
|
||||
{
|
||||
super(true, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
cooldowns.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int repeatInSeconds()
|
||||
{
|
||||
return 5;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user