2021-01-03 07:21:15 +00:00
|
|
|
package dev.plex.punishment;
|
2020-11-06 18:51:47 +00:00
|
|
|
|
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;
|
2022-04-19 21:49:45 +00:00
|
|
|
import java.time.ZonedDateTime;
|
2020-11-06 18:51:47 +00:00
|
|
|
import java.util.UUID;
|
2022-04-19 21:49:45 +00:00
|
|
|
|
|
|
|
import dev.plex.util.adapter.ZonedDateTimeDeserializer;
|
|
|
|
import dev.plex.util.adapter.ZonedDateTimeSerializer;
|
2022-02-07 05:53:57 +00:00
|
|
|
import lombok.Getter;
|
|
|
|
import lombok.Setter;
|
2022-02-26 06:24:11 +00:00
|
|
|
import net.kyori.adventure.text.Component;
|
2022-02-07 03:43:37 +00:00
|
|
|
|
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
|
|
|
|
{
|
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
|
2022-04-19 21:49:45 +00:00
|
|
|
private ZonedDateTime endDate;
|
2022-03-17 22:16:17 +00:00
|
|
|
|
2022-04-04 08:36:50 +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
|
|
|
}
|
|
|
|
|
2022-02-28 06:28:00 +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
|
|
|
{
|
2022-04-19 21:49:45 +00:00
|
|
|
return new GsonBuilder().registerTypeAdapter(ZonedDateTime.class, new ZonedDateTimeDeserializer()).create().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
|
|
|
{
|
2022-04-19 21:49:45 +00:00
|
|
|
return new GsonBuilder().registerTypeAdapter(ZonedDateTime.class, new ZonedDateTimeSerializer()).create().toJson(this);
|
2020-11-06 18:51:47 +00:00
|
|
|
}
|
|
|
|
}
|