SteamWar/BungeeCore
Archiviert
13
2

🐛 Fixing Punishment Errors
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
Chaoscaot 2022-04-10 19:20:16 +02:00
Ursprung d67c9bac66
Commit 190828692c
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) { public static Timestamp parseTime(CommandSender sender, String arg) {
if (arg.equalsIgnoreCase("perma")) { if (arg.equalsIgnoreCase("perma")) {
return Timestamp.from(Instant.ofEpochSecond(946674800)); return Punishment.PERMA_TIME;
} else { } else {
SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy_HH:mm"); SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy_HH:mm");
try { try {

Datei anzeigen

@ -48,7 +48,7 @@ public class ChatListener extends BasicListener {
public void onChatEvent(ChatEvent e){ public void onChatEvent(ChatEvent e){
if(e.getMessage().contains("jndi:ldap")) { if(e.getMessage().contains("jndi:ldap")) {
e.setCancelled(true); 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; return;
} }

Datei anzeigen

@ -182,11 +182,9 @@ public class Fabric extends BasicListener {
} }
public void banPlayer(SteamwarUser user, ProxiedPlayer player) { public void banPlayer(SteamwarUser user, ProxiedPlayer player) {
user.punish(Punishment.PunishmentType.Ban, user.punishPerma(Punishment.PunishmentType.Ban,
Timestamp.from(Instant.now()),
Message.parse("MODIFICATION_BAN_MESSAGE", player, user.getUserName(), user.getId()), Message.parse("MODIFICATION_BAN_MESSAGE", player, user.getUserName(), user.getId()),
0, 0);
true);
BungeeCore.log(Level.SEVERE,Message.parse("MODIFICATION_BAN_LOG", player, user.getUserName())); 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.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.time.Instant;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.*; 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 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 (?, ?, ?, ?, ?, ?)"); 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) { public static Punishment getPunishmentOfPlayer(int user, PunishmentType type) {
return getPunishment.select(rs -> { return getPunishment.select(rs -> {
if (rs.next()) 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) { 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); insert.update(user, executor, type.name(), reason, endTime, perma);
return getPunishmentOfPlayer(user, type); return getPunishmentOfPlayer(user, type);
} }

Datei anzeigen

@ -297,6 +297,10 @@ public class SteamwarUser {
return true; 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) { public void punish(Punishment.PunishmentType punishment, Timestamp time, String banReason, int from, boolean perma) {
punishments.remove(punishment); punishments.remove(punishment);
punishments.put(punishment, Punishment.createPunishment(id, from, punishment, banReason, time, perma)); punishments.put(punishment, Punishment.createPunishment(id, from, punishment, banReason, time, perma));