Add changes for HTTPD to do web-based punishments

This commit is contained in:
2026-05-18 00:30:26 -04:00
parent 432e614286
commit a508aa5aae
3 changed files with 32 additions and 10 deletions
@@ -26,6 +26,10 @@ public class Punishment
@NotNull @NotNull
private final UUID punished; private final UUID punished;
private final UUID punisher; private final UUID punisher;
// Optional display attribution for punishers without a Minecraft UUID
// (e.g. web staff signed in via XenForo). When non-null, render this in
// place of the UUID-based name lookup.
private String punisherName;
private String ip; private String ip;
private String punishedUsername; private String punishedUsername;
private PunishmentType type; private PunishmentType type;
@@ -42,12 +46,27 @@ public class Punishment
public static Component generateBanMessage(Punishment punishment) public static Component generateBanMessage(Punishment punishment)
{ {
return PlexUtils.messageComponent("banMessage", banUrl, punishment.getReason(), TimeUtils.useTimezone(punishment.getEndDate()), punishment.getPunisher() == null ? "CONSOLE" : Plex.get().getSqlPlayerData().getNameByUUID(punishment.getPunisher())); return PlexUtils.messageComponent("banMessage", banUrl, punishment.getReason(), TimeUtils.useTimezone(punishment.getEndDate()), punisherDisplayName(punishment));
} }
public static Component generateKickMessage(Punishment punishment) public static Component generateKickMessage(Punishment punishment)
{ {
return PlexUtils.messageComponent("kickMessage", punishment.getReason(), punishment.getPunisher() == null ? "CONSOLE" : Plex.get().getSqlPlayerData().getNameByUUID(punishment.getPunisher())); return PlexUtils.messageComponent("kickMessage", punishment.getReason(), punisherDisplayName(punishment));
}
/**
* Resolves the human-readable punisher attribution for display.
* Prefers the explicit {@link #punisherName} (used for off-server
* sources such as XenForo staff acting via the web HTTPD), falling
* back to a UUID lookup, and finally "CONSOLE" when the punisher is
* truly unknown.
*/
public static String punisherDisplayName(Punishment punishment)
{
String explicit = punishment.getPunisherName();
if (explicit != null && !explicit.isEmpty()) return explicit;
if (punishment.getPunisher() == null) return "CONSOLE";
return Plex.get().getSqlPlayerData().getNameByUUID(punishment.getPunisher());
} }
public static Component generateIndefBanMessageWithReason(String type, String reason) public static Component generateIndefBanMessageWithReason(String type, String reason)
@@ -82,6 +82,7 @@ public class SQLConnection implements PlexBase
con.prepareStatement("CREATE TABLE IF NOT EXISTS `punishments` (" + con.prepareStatement("CREATE TABLE IF NOT EXISTS `punishments` (" +
"`punished` VARCHAR(46) NOT NULL, " + "`punished` VARCHAR(46) NOT NULL, " +
"`punisher` VARCHAR(46), " + "`punisher` VARCHAR(46), " +
"`punisherName` VARCHAR(64), " +
"`punishedUsername` VARCHAR(16), " + "`punishedUsername` VARCHAR(16), " +
"`ip` VARCHAR(2000), " + "`ip` VARCHAR(2000), " +
"`type` VARCHAR(30), " + "`type` VARCHAR(30), " +
@@ -24,7 +24,7 @@ public class SQLPunishment
private static final String SELECT_BY_IP = "SELECT * FROM `punishments` WHERE ip=?"; private static final String SELECT_BY_IP = "SELECT * FROM `punishments` WHERE ip=?";
private static final String SELECT_BY = "SELECT * FROM `punishments` WHERE punisher=?"; private static final String SELECT_BY = "SELECT * FROM `punishments` WHERE punisher=?";
private static final String INSERT = "INSERT INTO `punishments` (`punished`, `punisher`, `punishedUsername`, `ip`, `type`, `reason`, `customTime`, `active`, `endDate`) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?)"; private static final String INSERT = "INSERT INTO `punishments` (`punished`, `punisher`, `punisherName`, `punishedUsername`, `ip`, `type`, `reason`, `customTime`, `active`, `endDate`) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
private static final String UPDATE_PUNISHMENT = "UPDATE `punishments` SET active=? WHERE punished=? AND type=?"; private static final String UPDATE_PUNISHMENT = "UPDATE `punishments` SET active=? WHERE punished=? AND type=?";
public CompletableFuture<List<Punishment>> getPunishments() public CompletableFuture<List<Punishment>> getPunishments()
@@ -43,6 +43,7 @@ public class SQLPunishment
punishment.setType(PunishmentType.valueOf(set.getString("type"))); punishment.setType(PunishmentType.valueOf(set.getString("type")));
punishment.setCustomTime(set.getBoolean("customTime")); punishment.setCustomTime(set.getBoolean("customTime"));
punishment.setPunishedUsername(set.getString("punishedUsername")); punishment.setPunishedUsername(set.getString("punishedUsername"));
punishment.setPunisherName(set.getString("punisherName"));
punishment.setEndDate(ZonedDateTime.ofInstant(Instant.ofEpochMilli(set.getLong("endDate")), ZoneId.of(TimeUtils.TIMEZONE))); punishment.setEndDate(ZonedDateTime.ofInstant(Instant.ofEpochMilli(set.getLong("endDate")), ZoneId.of(TimeUtils.TIMEZONE)));
punishment.setReason(set.getString("reason")); punishment.setReason(set.getString("reason"));
punishment.setIp(set.getString("ip")); punishment.setIp(set.getString("ip"));
@@ -125,13 +126,14 @@ public class SQLPunishment
PreparedStatement statement = con.prepareStatement(INSERT); PreparedStatement statement = con.prepareStatement(INSERT);
statement.setString(1, punishment.getPunished().toString()); statement.setString(1, punishment.getPunished().toString());
statement.setString(2, punishment.getPunisher() == null ? null : punishment.getPunisher().toString()); statement.setString(2, punishment.getPunisher() == null ? null : punishment.getPunisher().toString());
statement.setString(3, punishment.getPunishedUsername()); statement.setString(3, punishment.getPunisherName());
statement.setString(4, punishment.getIp()); statement.setString(4, punishment.getPunishedUsername());
statement.setString(5, punishment.getType().name()); statement.setString(5, punishment.getIp());
statement.setString(6, punishment.getReason()); statement.setString(6, punishment.getType().name());
statement.setBoolean(7, punishment.isCustomTime()); statement.setString(7, punishment.getReason());
statement.setBoolean(8, punishment.isActive()); statement.setBoolean(8, punishment.isCustomTime());
statement.setLong(9, punishment.getEndDate().toInstant().toEpochMilli()); statement.setBoolean(9, punishment.isActive());
statement.setLong(10, punishment.getEndDate().toInstant().toEpochMilli());
PlexLog.debug("Executing punishment"); PlexLog.debug("Executing punishment");
statement.execute(); statement.execute();
} }