mirror of
https://github.com/plexusorg/Plex.git
synced 2025-01-11 09:27:36 +00:00
Not sure we need a nuker, paper is blocking it before Plex
This commit is contained in:
parent
b1fcf5e348
commit
1a94c3e39f
41
src/main/java/dev/plex/listener/impl/AntiNukerListener.java
Normal file
41
src/main/java/dev/plex/listener/impl/AntiNukerListener.java
Normal file
@ -0,0 +1,41 @@
|
||||
package dev.plex.listener.impl;
|
||||
|
||||
import dev.plex.listener.PlexListener;
|
||||
import dev.plex.services.impl.TimingService;
|
||||
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.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
|
||||
public class AntiNukerListener extends PlexListener
|
||||
{
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onBlockPlace(BlockPlaceEvent event)
|
||||
{
|
||||
TimingService.nukerCooldown.merge(event.getPlayer().getUniqueId(), 1L, Long::sum);
|
||||
if (getCount(event.getPlayer().getUniqueId()) > 200L)
|
||||
{
|
||||
TimingService.strikes.merge(event.getPlayer().getUniqueId(), 1L, Long::sum);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onBlockBreak(BlockBreakEvent event)
|
||||
{
|
||||
TimingService.nukerCooldown.merge(event.getPlayer().getUniqueId(), 1L, Long::sum);
|
||||
if (getCount(event.getPlayer().getUniqueId()) > 200L)
|
||||
{
|
||||
TimingService.strikes.merge(event.getPlayer().getUniqueId(), 1L, Long::sum);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
public long getCount(UUID uuid)
|
||||
{
|
||||
return TimingService.nukerCooldown.getOrDefault(uuid, 1L);
|
||||
}
|
||||
}
|
@ -15,7 +15,7 @@ public class AntiSpamListener extends PlexListener
|
||||
@EventHandler
|
||||
public void onChat(AsyncChatEvent event)
|
||||
{
|
||||
TimingService.cooldowns.merge(event.getPlayer().getUniqueId(), 1L, Long::sum);
|
||||
TimingService.spamCooldown.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));
|
||||
@ -26,7 +26,7 @@ public class AntiSpamListener extends PlexListener
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event)
|
||||
{
|
||||
TimingService.cooldowns.merge(event.getPlayer().getUniqueId(), 1L, Long::sum);
|
||||
TimingService.spamCooldown.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));
|
||||
@ -36,6 +36,6 @@ public class AntiSpamListener extends PlexListener
|
||||
|
||||
public long getCount(UUID uuid)
|
||||
{
|
||||
return TimingService.cooldowns.getOrDefault(uuid, 1L);
|
||||
return TimingService.spamCooldown.getOrDefault(uuid, 1L);
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,28 @@
|
||||
package dev.plex.services.impl;
|
||||
|
||||
import dev.plex.cache.DataUtils;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.punishment.Punishment;
|
||||
import dev.plex.punishment.PunishmentType;
|
||||
import dev.plex.services.AbstractService;
|
||||
import dev.plex.util.TimeUtils;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class TimingService extends AbstractService
|
||||
{
|
||||
public static final Map<UUID, Long> cooldowns = new HashMap<>();
|
||||
public static final Map<UUID, Long> spamCooldown = new HashMap<>();
|
||||
public static final Map<UUID, Long> nukerCooldown = new HashMap<>();
|
||||
// 1 - Default
|
||||
// 2 - Kick
|
||||
// 3 - Tempban 5 minutes
|
||||
// 4 - Ban
|
||||
public static final Map<UUID, Long> strikes = new HashMap<>();
|
||||
|
||||
public TimingService()
|
||||
{
|
||||
@ -17,7 +32,49 @@ public class TimingService extends AbstractService
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
cooldowns.clear();
|
||||
spamCooldown.clear();
|
||||
nukerCooldown.clear();
|
||||
for (Map.Entry<UUID, Long> map : strikes.entrySet())
|
||||
{
|
||||
if (map.getValue() == 2)
|
||||
{
|
||||
Player player = Bukkit.getPlayer(map.getKey());
|
||||
if (player != null)
|
||||
{
|
||||
player.kick(Component.text("Please disable your nuker!").color(NamedTextColor.RED));
|
||||
}
|
||||
}
|
||||
if (map.getValue() == 3)
|
||||
{
|
||||
issueBan(map, "5m");
|
||||
}
|
||||
else if (map.getValue() == 4)
|
||||
{
|
||||
issueBan(map, "24h");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void issueBan(Map.Entry<UUID, Long> map, String time)
|
||||
{
|
||||
Punishment punishment = new Punishment(map.getKey(), null);
|
||||
Player player = Bukkit.getPlayer(map.getKey());
|
||||
PlexPlayer plexPlayer = DataUtils.getPlayer(map.getKey());
|
||||
punishment.setType(PunishmentType.TEMPBAN);
|
||||
punishment.setReason("You are temporarily banned for five minutes for either using a Nuker or spamming chat/commands.");
|
||||
if (player != null)
|
||||
{
|
||||
punishment.setPunishedUsername(player.getName());
|
||||
punishment.setIp(player.getAddress().getAddress().getHostAddress());
|
||||
}
|
||||
punishment.setEndDate(TimeUtils.createDate(time));
|
||||
punishment.setCustomTime(false);
|
||||
punishment.setActive(!plugin.getRankManager().isAdmin(plexPlayer));
|
||||
plugin.getPunishmentManager().punish(plexPlayer, punishment);
|
||||
if (player != null)
|
||||
{
|
||||
player.kick(Punishment.generateBanMessage(punishment));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user