Fix it this time

This commit is contained in:
Telesphoreo 2022-04-20 21:26:39 -05:00
parent ef957467ce
commit ec7e370a01
4 changed files with 15 additions and 37 deletions

View file

@ -82,10 +82,6 @@ public class EntityWipeCMD extends PlexCommand
list = list.replaceAll("(, )(?!.*\1)", (list.indexOf(", ") == list.lastIndexOf(", ") ? "" : ",") + " and "); list = list.replaceAll("(, )(?!.*\1)", (list.indexOf(", ") == list.lastIndexOf(", ") ? "" : ",") + " and ");
PlexUtils.broadcast(messageComponent("removedEntitiesOfTypes", sender.getName(), entityCount, list)); PlexUtils.broadcast(messageComponent("removedEntitiesOfTypes", sender.getName(), entityCount, list));
} }
/*entityCounts.forEach((entityName, numRemoved) -> {
sender.sendMessage(messageComponent("removedEntitiesOfType", sender.getName(), numRemoved, entityName));
});*/
return null; return null;
} }

View file

@ -4,7 +4,6 @@ import dev.plex.listener.PlexListener;
import dev.plex.services.impl.TimingService; import dev.plex.services.impl.TimingService;
import java.util.UUID; import java.util.UUID;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockBreakEvent;
@ -12,24 +11,26 @@ import org.bukkit.event.block.BlockPlaceEvent;
public class AntiNukerListener extends PlexListener public class AntiNukerListener extends PlexListener
{ {
@EventHandler(priority = EventPriority.LOW) @EventHandler(priority = EventPriority.HIGH)
public void onBlockPlace(BlockPlaceEvent event) public void onBlockPlace(BlockPlaceEvent event)
{ {
TimingService.nukerCooldown.merge(event.getPlayer().getUniqueId(), 1L, Long::sum); TimingService.nukerCooldown.merge(event.getPlayer().getUniqueId(), 1L, Long::sum);
if (getCount(event.getPlayer().getUniqueId()) > 200L) if (getCount(event.getPlayer().getUniqueId()) > 200L)
{ {
TimingService.strikes.merge(event.getPlayer().getUniqueId(), 1L, Long::sum); TimingService.strikes.merge(event.getPlayer().getUniqueId(), 1L, Long::sum);
event.getPlayer().kick(Component.text("Please turn off your nuker!"));
event.setCancelled(true); event.setCancelled(true);
} }
} }
@EventHandler(priority = EventPriority.LOW) @EventHandler(priority = EventPriority.HIGH)
public void onBlockBreak(BlockBreakEvent event) public void onBlockBreak(BlockBreakEvent event)
{ {
TimingService.nukerCooldown.merge(event.getPlayer().getUniqueId(), 1L, Long::sum); TimingService.nukerCooldown.merge(event.getPlayer().getUniqueId(), 1L, Long::sum);
if (getCount(event.getPlayer().getUniqueId()) > 200L) if (getCount(event.getPlayer().getUniqueId()) > 200L)
{ {
TimingService.strikes.merge(event.getPlayer().getUniqueId(), 1L, Long::sum); TimingService.strikes.merge(event.getPlayer().getUniqueId(), 1L, Long::sum);
event.getPlayer().kick(Component.text("Please turn off your nuker!"));
event.setCancelled(true); event.setCancelled(true);
} }
} }

View file

@ -37,7 +37,7 @@ public class BanListener extends PlexListener
if (plugin.getPunishmentManager().isBanned(event.getUniqueId())) if (plugin.getPunishmentManager().isBanned(event.getUniqueId()))
{ {
PlexPlayer player = DataUtils.getPlayer(event.getUniqueId()); PlexPlayer player = DataUtils.getPlayer(event.getUniqueId());
player.getPunishments().stream().filter(punishment -> punishment.getType() == PunishmentType.BAN && punishment.isActive()).findFirst().ifPresent(punishment -> player.getPunishments().stream().filter(punishment -> (punishment.getType() == PunishmentType.BAN || punishment.getType() == PunishmentType.TEMPBAN) && punishment.isActive()).findFirst().ifPresent(punishment ->
event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_BANNED, event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_BANNED,
Punishment.generateBanMessage(punishment))); Punishment.generateBanMessage(punishment)));
} }

View file

@ -5,12 +5,11 @@ import dev.plex.player.PlexPlayer;
import dev.plex.punishment.Punishment; import dev.plex.punishment.Punishment;
import dev.plex.punishment.PunishmentType; import dev.plex.punishment.PunishmentType;
import dev.plex.services.AbstractService; import dev.plex.services.AbstractService;
import dev.plex.util.PlexLog;
import dev.plex.util.TimeUtils; import dev.plex.util.TimeUtils;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -18,10 +17,6 @@ public class TimingService extends AbstractService
{ {
public static final Map<UUID, Long> spamCooldown = new HashMap<>(); public static final Map<UUID, Long> spamCooldown = new HashMap<>();
public static final Map<UUID, Long> nukerCooldown = 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 static final Map<UUID, Long> strikes = new HashMap<>();
public TimingService() public TimingService()
@ -36,46 +31,32 @@ public class TimingService extends AbstractService
nukerCooldown.clear(); nukerCooldown.clear();
for (Map.Entry<UUID, Long> map : strikes.entrySet()) for (Map.Entry<UUID, Long> map : strikes.entrySet())
{ {
if (map.getValue() == 2) PlexLog.debug(map.getKey() + ": " + map.getValue());
// Tempban for 5 minutes and reset strikes. This will probably stop people from actually trying to use a Nuker to grief.
if (map.getValue() >= 2L)
{ {
Player player = Bukkit.getPlayer(map.getKey()); issueBan(map);
if (player != null) strikes.remove(map.getKey());
{
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");
map.setValue(0L);
} }
} }
} }
private void issueBan(Map.Entry<UUID, Long> map, String time) private void issueBan(Map.Entry<UUID, Long> map)
{ {
Punishment punishment = new Punishment(map.getKey(), null); Punishment punishment = new Punishment(map.getKey(), null);
Player player = Bukkit.getPlayer(map.getKey()); Player player = Bukkit.getPlayer(map.getKey());
PlexPlayer plexPlayer = DataUtils.getPlayer(map.getKey()); PlexPlayer plexPlayer = DataUtils.getPlayer(map.getKey());
punishment.setType(PunishmentType.TEMPBAN); punishment.setType(PunishmentType.TEMPBAN);
punishment.setReason("You are temporarily banned for five minutes for either using a Nuker or spamming chat/commands."); punishment.setReason("You are temporarily banned for five minutes for using a Nuker.");
if (player != null) if (player != null)
{ {
punishment.setPunishedUsername(player.getName()); punishment.setPunishedUsername(player.getName());
punishment.setIp(player.getAddress().getAddress().getHostAddress()); punishment.setIp(player.getAddress().getAddress().getHostAddress());
} }
punishment.setEndDate(TimeUtils.createDate(time)); punishment.setEndDate(TimeUtils.createDate("5m"));
punishment.setCustomTime(false); punishment.setCustomTime(false);
punishment.setActive(!plugin.getRankManager().isAdmin(plexPlayer)); punishment.setActive(!plexPlayer.isAdminActive());
plugin.getPunishmentManager().punish(plexPlayer, punishment); plugin.getPunishmentManager().punish(plexPlayer, punishment);
if (player != null)
{
player.kick(Punishment.generateBanMessage(punishment));
}
} }
@Override @Override