Archiviert
1
0

Merge pull request 'Fixing Punishment Errors' (#341) from again! into master

Reviewed-on: SteamWar/BungeeCore#341
Reviewed-by: Lixfel <lixfel@steamwar.de>
Dieser Commit ist enthalten in:
Lixfel 2022-04-10 19:25:11 +02:00
Commit f7892d21d1
5 geänderte Dateien mit 14 neuen und 6 gelöschten Zeilen

Datei anzeigen

@ -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 {

Datei anzeigen

@ -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;
}

Datei anzeigen

@ -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()));
}

Datei anzeigen

@ -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);
}

Datei anzeigen

@ -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));