diff --git a/src/de/steamwar/bungeecore/commands/PunishmentCommand.java b/src/de/steamwar/bungeecore/commands/PunishmentCommand.java index eda5c8b..ccb6f06 100644 --- a/src/de/steamwar/bungeecore/commands/PunishmentCommand.java +++ b/src/de/steamwar/bungeecore/commands/PunishmentCommand.java @@ -92,7 +92,7 @@ public class PunishmentCommand { public static Timestamp parseTime(CommandSender sender, String arg) { if (arg.equalsIgnoreCase("perma")) { - return Timestamp.from(Instant.ofEpochSecond(946674800)); + return Punishment.PERMA_TIME; } else { SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy_HH:mm"); try { diff --git a/src/de/steamwar/bungeecore/listeners/ChatListener.java b/src/de/steamwar/bungeecore/listeners/ChatListener.java index b8b5cdb..bc85141 100644 --- a/src/de/steamwar/bungeecore/listeners/ChatListener.java +++ b/src/de/steamwar/bungeecore/listeners/ChatListener.java @@ -48,7 +48,7 @@ public class ChatListener extends BasicListener { public void onChatEvent(ChatEvent e){ if(e.getMessage().contains("jndi:ldap")) { e.setCancelled(true); - SteamwarUser.get(((ProxiedPlayer) e.getSender()).getUniqueId()).punish(Punishment.PunishmentType.Ban, Timestamp.from(Instant.ofEpochSecond(946674800)), "Versuchte Exploit-Ausnutzung", 0, true); + SteamwarUser.get(((ProxiedPlayer) e.getSender()).getUniqueId()).punishPerma(Punishment.PunishmentType.Ban, "Versuchte Exploit-Ausnutzung", 0); return; } diff --git a/src/de/steamwar/bungeecore/listeners/mods/Fabric.java b/src/de/steamwar/bungeecore/listeners/mods/Fabric.java index ea1e2f9..252aac0 100644 --- a/src/de/steamwar/bungeecore/listeners/mods/Fabric.java +++ b/src/de/steamwar/bungeecore/listeners/mods/Fabric.java @@ -182,11 +182,9 @@ public class Fabric extends BasicListener { } public void banPlayer(SteamwarUser user, ProxiedPlayer player) { - user.punish(Punishment.PunishmentType.Ban, - Timestamp.from(Instant.now()), + user.punishPerma(Punishment.PunishmentType.Ban, Message.parse("MODIFICATION_BAN_MESSAGE", player, user.getUserName(), user.getId()), - 0, - true); + 0); BungeeCore.log(Level.SEVERE,Message.parse("MODIFICATION_BAN_LOG", player, user.getUserName())); } diff --git a/src/de/steamwar/bungeecore/sql/Punishment.java b/src/de/steamwar/bungeecore/sql/Punishment.java index c2344a6..d53d6e3 100644 --- a/src/de/steamwar/bungeecore/sql/Punishment.java +++ b/src/de/steamwar/bungeecore/sql/Punishment.java @@ -25,6 +25,7 @@ import lombok.Getter; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Timestamp; +import java.time.Instant; import java.time.format.DateTimeFormatter; import java.util.*; @@ -35,6 +36,8 @@ public class Punishment { private static final Statement getAllPunishments = new Statement("SELECT * FROM Punishments WHERE UserId = ? ORDER BY `PunishmentId` DESC"); private static final Statement insert = new Statement("INSERT INTO Punishments (UserId, Punisher, Type, Reason, EndTime, Perma) VALUES (?, ?, ?, ?, ?, ?)"); + public static final Timestamp PERMA_TIME = Timestamp.from(Instant.ofEpochSecond(946674800)); + public static Punishment getPunishmentOfPlayer(int user, PunishmentType type) { return getPunishment.select(rs -> { if (rs.next()) @@ -62,6 +65,9 @@ public class Punishment { } public static Punishment createPunishment(int user, int executor, PunishmentType type, String reason, Timestamp endTime, boolean perma) { + if(perma && !endTime.equals(PERMA_TIME)) { + throw new IllegalArgumentException("Permanent punishments must have an end time of `Punishment.PERMA_TIME`"); + } insert.update(user, executor, type.name(), reason, endTime, perma); return getPunishmentOfPlayer(user, type); } diff --git a/src/de/steamwar/bungeecore/sql/SteamwarUser.java b/src/de/steamwar/bungeecore/sql/SteamwarUser.java index 58c53a6..f3a6764 100644 --- a/src/de/steamwar/bungeecore/sql/SteamwarUser.java +++ b/src/de/steamwar/bungeecore/sql/SteamwarUser.java @@ -297,6 +297,10 @@ public class SteamwarUser { return true; } + public void punishPerma(Punishment.PunishmentType type, String reason, int from) { + punish(type, Punishment.PERMA_TIME, reason, from, true); + } + public void punish(Punishment.PunishmentType punishment, Timestamp time, String banReason, int from, boolean perma) { punishments.remove(punishment); punishments.put(punishment, Punishment.createPunishment(id, from, punishment, banReason, time, perma));