Plex/server/src/main/java/dev/plex/punishment/Punishment.java

67 lines
1.9 KiB
Java
Raw Normal View History

2021-01-03 07:21:15 +00:00
package dev.plex.punishment;
2020-11-06 18:51:47 +00:00
2023-03-08 11:45:47 +00:00
import com.google.gson.Gson;
2022-02-07 05:06:55 +00:00
import com.google.gson.GsonBuilder;
2022-04-07 07:37:31 +00:00
import dev.morphia.annotations.Entity;
2022-02-26 06:24:11 +00:00
import dev.plex.Plex;
import dev.plex.util.MojangUtils;
import dev.plex.util.PlexUtils;
2022-04-19 20:31:34 +00:00
import dev.plex.util.TimeUtils;
2023-03-08 11:45:47 +00:00
import dev.plex.util.adapter.ZonedDateTimeAdapter;
import lombok.Getter;
import lombok.Setter;
2022-02-26 06:24:11 +00:00
import net.kyori.adventure.text.Component;
2023-03-08 20:26:10 +00:00
import java.time.ZonedDateTime;
import java.util.UUID;
2020-11-06 18:51:47 +00:00
@Getter
@Setter
2022-04-07 07:37:31 +00:00
@Entity
2020-11-06 18:51:47 +00:00
public class Punishment
{
2023-03-08 11:45:47 +00:00
private static final Gson gson = new GsonBuilder().registerTypeAdapter(ZonedDateTime.class, new ZonedDateTimeAdapter()).create();
2022-02-26 06:26:42 +00:00
private static final String banUrl = Plex.get().config.getString("banning.ban_url");
2020-11-06 18:51:47 +00:00
private final UUID punished;
private final UUID punisher;
2022-04-02 23:03:58 +00:00
private String ip;
2020-11-06 18:51:47 +00:00
private String punishedUsername;
private PunishmentType type;
private String reason;
private boolean customTime;
2022-02-26 06:24:11 +00:00
private boolean active; // Field is only for bans
private ZonedDateTime endDate;
2022-03-17 22:16:17 +00:00
public Punishment()
{
this.punished = null;
this.punisher = null;
}
2020-11-06 18:51:47 +00:00
public Punishment(UUID punished, UUID punisher)
{
this.punished = punished;
this.punisher = punisher;
}
2022-02-26 06:24:11 +00:00
public static Component generateBanMessage(Punishment punishment)
{
2022-04-19 20:31:34 +00:00
return PlexUtils.messageComponent("banMessage", banUrl, punishment.getReason(), TimeUtils.useTimezone(punishment.getEndDate()), punishment.getPunisher() == null ? "CONSOLE" : MojangUtils.getInfo(punishment.getPunisher().toString()).getUsername());
2022-02-26 06:24:11 +00:00
}
public static Component generateIndefBanMessage(String type)
{
return PlexUtils.messageComponent("indefBanMessage", type, banUrl);
}
2022-02-26 06:26:42 +00:00
public static Punishment fromJson(String json)
2020-11-06 18:51:47 +00:00
{
2023-03-08 11:45:47 +00:00
return gson.fromJson(json, Punishment.class);
2020-11-06 18:51:47 +00:00
}
2022-02-26 06:26:42 +00:00
public String toJSON()
2020-11-06 18:51:47 +00:00
{
2023-03-08 11:45:47 +00:00
return gson.toJson(this);
2020-11-06 18:51:47 +00:00
}
}